[GitHub] [lucene-solr] dnhatn commented on a change in pull request #1319: LUCENE-9164: process all events before closing gracefully

2020-03-08 Thread GitBox
dnhatn commented on a change in pull request #1319: LUCENE-9164: process all 
events before closing gracefully
URL: https://github.com/apache/lucene-solr/pull/1319#discussion_r389394156
 
 

 ##
 File path: lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
 ##
 @@ -299,7 +300,77 @@ static int getActualMaxDocs() {
   final FieldNumbers globalFieldNumberMap;
 
   final DocumentsWriter docWriter;
-  private final Queue eventQueue = new ConcurrentLinkedQueue<>();
+  private final EventQueue eventQueue = new EventQueue(this);
+
+  static final class EventQueue implements Closeable {
+private volatile boolean closed = false;
+private final Semaphore permits = new Semaphore(Integer.MAX_VALUE);
+private final Queue queue = new ConcurrentLinkedQueue<>();
+private final IndexWriter writer;
+
+EventQueue(IndexWriter writer) {
+  this.writer = writer;
+}
+
+private void tryAcquire() {
+  if (permits.tryAcquire() == false) {
+throw new AlreadyClosedException("queue is closed");
+  }
+  if (closed) {
+throw new AlreadyClosedException("queue is closed");
 
 Review comment:
   Great catch.


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org



[GitHub] [lucene-solr] dnhatn commented on a change in pull request #1319: LUCENE-9164: process all events before closing gracefully

2020-03-06 Thread GitBox
dnhatn commented on a change in pull request #1319: LUCENE-9164: process all 
events before closing gracefully
URL: https://github.com/apache/lucene-solr/pull/1319#discussion_r389028879
 
 

 ##
 File path: lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
 ##
 @@ -299,7 +300,76 @@ static int getActualMaxDocs() {
   final FieldNumbers globalFieldNumberMap;
 
   final DocumentsWriter docWriter;
-  private final Queue eventQueue = new ConcurrentLinkedQueue<>();
+  private final CloseableQueue eventQueue = new CloseableQueue(this);
+
+  static final class CloseableQueue implements Closeable {
+private volatile boolean closed = false;
+private final Semaphore permits = new Semaphore(Integer.MAX_VALUE);
+private final Queue queue = new ConcurrentLinkedQueue<>();
+private final IndexWriter writer;
+
+CloseableQueue(IndexWriter writer) {
+  this.writer = writer;
+}
+
+private void tryAcquire() {
+  if (permits.tryAcquire() == false) {
+throw new AlreadyClosedException("queue is closed");
+  }
+  if (closed) {
+throw new AlreadyClosedException("queue is closed");
+  }
+}
+
+boolean add(Event event) {
+  tryAcquire();
+  try {
+return queue.add(event);
+  } finally {
+permits.release();
+  }
+}
+
+void processEvents() throws IOException {
+  tryAcquire();
+  try {
+processEventsInternal();
+  }finally {
 
 Review comment:
   nit: space after `}`


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org



[GitHub] [lucene-solr] dnhatn commented on a change in pull request #1319: LUCENE-9164: process all events before closing gracefully

2020-03-06 Thread GitBox
dnhatn commented on a change in pull request #1319: LUCENE-9164: process all 
events before closing gracefully
URL: https://github.com/apache/lucene-solr/pull/1319#discussion_r389028289
 
 

 ##
 File path: lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
 ##
 @@ -299,7 +300,76 @@ static int getActualMaxDocs() {
   final FieldNumbers globalFieldNumberMap;
 
   final DocumentsWriter docWriter;
-  private final Queue eventQueue = new ConcurrentLinkedQueue<>();
+  private final CloseableQueue eventQueue = new CloseableQueue(this);
+
+  static final class CloseableQueue implements Closeable {
+private volatile boolean closed = false;
+private final Semaphore permits = new Semaphore(Integer.MAX_VALUE);
+private final Queue queue = new ConcurrentLinkedQueue<>();
+private final IndexWriter writer;
+
+CloseableQueue(IndexWriter writer) {
+  this.writer = writer;
+}
+
+private void tryAcquire() {
+  if (permits.tryAcquire() == false) {
+throw new AlreadyClosedException("queue is closed");
+  }
+  if (closed) {
+throw new AlreadyClosedException("queue is closed");
+  }
+}
+
+boolean add(Event event) {
+  tryAcquire();
+  try {
+return queue.add(event);
+  } finally {
+permits.release();
+  }
+}
+
+void processEvents() throws IOException {
+  tryAcquire();
+  try {
+processEventsInternal();
+  }finally {
+permits.release();
+  }
+}
+private void processEventsInternal() throws IOException {
 
 Review comment:
   nit: add a new line


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org



[GitHub] [lucene-solr] dnhatn commented on a change in pull request #1319: LUCENE-9164: process all events before closing gracefully

2020-03-06 Thread GitBox
dnhatn commented on a change in pull request #1319: LUCENE-9164: process all 
events before closing gracefully
URL: https://github.com/apache/lucene-solr/pull/1319#discussion_r389029514
 
 

 ##
 File path: lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java
 ##
 @@ -3773,7 +3774,58 @@ public void testRefreshAndRollbackConcurrently() throws 
Exception {
   stopped.set(true);
   indexer.join();
   refresher.join();
+  if (w.getTragicException() != null) {
+w.getTragicException().printStackTrace();
 
 Review comment:
   I think we don't need to print the stack trace here.


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org



[GitHub] [lucene-solr] dnhatn commented on a change in pull request #1319: LUCENE-9164: process all events before closing gracefully

2020-03-06 Thread GitBox
dnhatn commented on a change in pull request #1319: LUCENE-9164: process all 
events before closing gracefully
URL: https://github.com/apache/lucene-solr/pull/1319#discussion_r389028879
 
 

 ##
 File path: lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
 ##
 @@ -299,7 +300,76 @@ static int getActualMaxDocs() {
   final FieldNumbers globalFieldNumberMap;
 
   final DocumentsWriter docWriter;
-  private final Queue eventQueue = new ConcurrentLinkedQueue<>();
+  private final CloseableQueue eventQueue = new CloseableQueue(this);
+
+  static final class CloseableQueue implements Closeable {
+private volatile boolean closed = false;
+private final Semaphore permits = new Semaphore(Integer.MAX_VALUE);
+private final Queue queue = new ConcurrentLinkedQueue<>();
+private final IndexWriter writer;
+
+CloseableQueue(IndexWriter writer) {
+  this.writer = writer;
+}
+
+private void tryAcquire() {
+  if (permits.tryAcquire() == false) {
+throw new AlreadyClosedException("queue is closed");
+  }
+  if (closed) {
+throw new AlreadyClosedException("queue is closed");
+  }
+}
+
+boolean add(Event event) {
+  tryAcquire();
+  try {
+return queue.add(event);
+  } finally {
+permits.release();
+  }
+}
+
+void processEvents() throws IOException {
+  tryAcquire();
+  try {
+processEventsInternal();
+  }finally {
 
 Review comment:
   nit: space after `{`


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org