dnhatn commented on a change in pull request #1155: LUCENE-8962: Add ability to 
selectively merge on commit
URL: https://github.com/apache/lucene-solr/pull/1155#discussion_r388705156
 
 

 ##########
 File path: lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
 ##########
 @@ -3252,6 +3315,53 @@ private long prepareCommitInternal() throws IOException 
{
       } finally {
         maybeCloseOnTragicEvent();
       }
+
+      if (mergeAwaitLatchRef != null) {
+        CountDownLatch mergeAwaitLatch = mergeAwaitLatchRef.get();
+        // If we found and registered any merges above, within the flushLock, 
then we want to ensure that they
+        // complete execution. Note that since we released the lock, other 
merges may have been scheduled. We will
+        // block until  the merges that we registered complete. As they 
complete, they will update toCommit to
+        // replace merged segments with the result of each merge.
+        config.getIndexWriterEvents().beginMergeOnCommit();
+        mergeScheduler.merge(this, MergeTrigger.COMMIT, true);
+        long mergeWaitStart = System.nanoTime();
+        int abandonedCount = 0;
+        long waitTimeMillis = (long) (config.getMaxCommitMergeWaitSeconds() * 
1000.0);
+        try {
+          if (mergeAwaitLatch.await(waitTimeMillis, TimeUnit.MILLISECONDS) == 
false) {
+            synchronized (this) {
+              // Need to do this in a synchronized block, to make sure none of 
our commit merges are currently
+              // executing mergeFinished (since mergeFinished itself is called 
from within the IndexWriter lock).
+              // After we clear the value from mergeAwaitLatchRef, the merges 
we schedule will still execute as
+              // usual, but when they finish, they won't attempt to update 
toCommit or modify segment reference
+              // counts.
+              mergeAwaitLatchRef.set(null);
 
 Review comment:
   I think we should set `mergeAwaitLatchRef` in the `else` branch.

----------------------------------------------------------------
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

Reply via email to