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_r388704872
########## File path: lucene/core/src/java/org/apache/lucene/index/IndexWriter.java ########## @@ -3147,6 +3149,42 @@ public final boolean flushNextBuffer() throws IOException { } } + private MergePolicy.OneMerge updateSegmentInfosOnMergeFinish(MergePolicy.OneMerge merge, final SegmentInfos toCommit, + AtomicReference<CountDownLatch> mergeLatchRef) { + return new MergePolicy.OneMerge(merge.segments) { + public void mergeFinished() throws IOException { + super.mergeFinished(); + CountDownLatch mergeAwaitLatch = mergeLatchRef.get(); + if (mergeAwaitLatch == null) { + // Commit thread timed out waiting for this merge and moved on. No need to manipulate toCommit. + return; + } + if (isAborted() == false) { + deleter.incRef(this.info.files()); + // Resolve "live" SegmentInfos segments to their toCommit cloned equivalents, based on segment name. + Set<String> mergedSegmentNames = new HashSet<>(); + for (SegmentCommitInfo sci : this.segments) { + deleter.decRef(sci.files()); + mergedSegmentNames.add(sci.info.name); + } + List<SegmentCommitInfo> toCommitMergedAwaySegments = new ArrayList<>(); + for (SegmentCommitInfo sci : toCommit) { + if (mergedSegmentNames.contains(sci.info.name)) { + toCommitMergedAwaySegments.add(sci); + } + } + // Construct a OneMerge that applies to toCommit + MergePolicy.OneMerge applicableMerge = new MergePolicy.OneMerge(toCommitMergedAwaySegments); + applicableMerge.info = this.info.clone(); + long segmentCounter = Long.parseLong(this.info.info.name.substring(1), Character.MAX_RADIX); + toCommit.counter = Math.max(toCommit.counter, segmentCounter + 1); + toCommit.applyMergeChanges(applicableMerge, false); Review comment: ~We should modify `toCommit` under `IndexWrite.this` lock (or a private synchronization between this method and `commitInternal`).~ ---------------------------------------------------------------- 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