epotyom commented on code in PR #16482:
URL: https://github.com/apache/lucene/pull/16482#discussion_r3852014273


##########
lucene/core/src/java/org/apache/lucene/index/SnapshotDeletionPolicy.java:
##########
@@ -91,38 +92,31 @@ public synchronized void release(IndexCommit commit) throws 
IOException {
   }
 
   /** Release a snapshot by generation. */
-  protected void releaseGen(long gen) throws IOException {
-    if (!initCalled) {
+  protected synchronized void releaseGen(long gen) {
+    if (initCalled == false) {
       throw new IllegalStateException(
           "this instance is not being used by IndexWriter; be sure to use the 
instance returned from writer.getConfig().getIndexDeletionPolicy()");
     }
     Integer refCount = refCounts.get(gen);
     if (refCount == null) {
       throw new IllegalArgumentException("commit gen=" + gen + " is not 
currently snapshotted");
     }
-    int refCountInt = refCount.intValue();
-    assert refCountInt > 0;
-    refCountInt--;
-    if (refCountInt == 0) {
+    assert refCount > 0;
+    if (refCount == 1) {
       refCounts.remove(gen);
       indexCommits.remove(gen);
     } else {
-      refCounts.put(gen, refCountInt);
+      refCounts.put(gen, refCount - 1);
     }
   }
 
   /** Increments the refCount for this {@link IndexCommit}. */
   protected synchronized void incRef(IndexCommit ic) {
     long gen = ic.getGeneration();
-    Integer refCount = refCounts.get(gen);
-    int refCountInt;
-    if (refCount == null) {
-      indexCommits.put(gen, lastCommit);
-      refCountInt = 0;
-    } else {
-      refCountInt = refCount.intValue();
+    int refCount = refCounts.merge(gen, 1, Integer::sum);
+    if (refCount == 1) {
+      indexCommits.put(gen, ic);

Review Comment:
   Thanks for fixing this. Storing `lastCommit` instead of `ic` caused issues 
when
   I tried extending this class before.



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

Reply via email to