guojialiang92 commented on code in PR #13017:
URL: https://github.com/apache/lucene/pull/13017#discussion_r1457326578
##########
lucene/core/src/java/org/apache/lucene/index/IndexWriter.java:
##########
@@ -5136,7 +5141,13 @@ private int mergeMiddle(MergePolicy.OneMerge merge,
MergePolicy mergePolicy) thr
sci -> {
final ReadersAndUpdates rld = getPooledInstance(sci, true);
rld.setIsMerging();
- return rld.getReaderForMerge(context);
+ synchronized (this) {
+ return rld.getReaderForMerge(
+ context,
+ mr -> {
+ deleter.incRef(mr.reader.getSegmentInfo().files());
Review Comment:
Hello, This PR has noticed that
`IndexFileDeleter#incRef/IndexFileDeleter#decRef` needs to have the
`IndexWriter` lock. I will explain in detail:
1. `IndexFileDeleter#incRef` is called in `IndexWriter#mergeMiddle`. it has
been locked by `synchronized (this)` before the `IndexFileDeleter#incRef` is
called.
2. Another call of `IndexFileDeleter#incRef` in
`IndexWriter#preparePointInTimeMerge`. `IndexWriter#preparePointInTimeMerge` is
called by `IndexWriter#prepareCommitInternal` or `IndexWriter#getReader`.
`synchronized (this)` is performed in both `IndexWriter#prepareCommitInternal`
and `IndexWriter#getReader`, so the `IndexFileDeleter#incRef` in
`IndexWriter#preparePointInTimeMerge` does not need to be locked.
3. `IndexFileDeleter#decRef` is called in `IndexWriter#closeMergeReaders`.
`IndexWriter#closeMergeReaders` is a `synchronized` function.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]