This is an automated email from the ASF dual-hosted git repository.

vjasani pushed a commit to branch tmp-ec
in repository https://gitbox.apache.org/repos/asf/phoenix.git

commit 0b1303a13b726fa2ba94f3cd0e59c271e7ba472c
Author: Viraj Jasani <[email protected]>
AuthorDate: Thu Mar 26 20:08:12 2026 -0700

    fix index concurrency issues
---
 .../apache/phoenix/hbase/index/IndexRegionObserver.java  | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git 
a/phoenix-core-server/src/main/java/org/apache/phoenix/hbase/index/IndexRegionObserver.java
 
b/phoenix-core-server/src/main/java/org/apache/phoenix/hbase/index/IndexRegionObserver.java
index 48c823d258..17362e159d 100644
--- 
a/phoenix-core-server/src/main/java/org/apache/phoenix/hbase/index/IndexRegionObserver.java
+++ 
b/phoenix-core-server/src/main/java/org/apache/phoenix/hbase/index/IndexRegionObserver.java
@@ -245,15 +245,16 @@ public class IndexRegionObserver implements 
RegionCoprocessor, RegionObserver {
       this.rowKey = rowKey;
     }
 
-    public boolean add(BatchMutateContext context) {
+    public BatchMutateContext addAndGetPrevCtx(BatchMutateContext context) {
       synchronized (this) {
         if (usable) {
+          BatchMutateContext previousContext = lastContext;
           count++;
           lastContext = context;
-          return true;
+          return previousContext;
         }
       }
-      return false;
+      return null;
     }
 
     public void remove() {
@@ -270,9 +271,6 @@ public class IndexRegionObserver implements 
RegionCoprocessor, RegionObserver {
       return count;
     }
 
-    public BatchMutateContext getLastContext() {
-      return lastContext;
-    }
   }
 
   private static boolean ignoreIndexRebuildForTesting = false;
@@ -1175,8 +1173,8 @@ public class IndexRegionObserver implements 
RegionCoprocessor, RegionObserver {
         keys.add(PVarbinary.INSTANCE.getKeyRange(rowKeyPtr.get(), 
SortOrder.ASC));
       } else {
         // There is a pending row for this row key. We need to retrieve the 
row from memory
-        BatchMutateContext lastContext = existingPendingRow.getLastContext();
-        if (existingPendingRow.add(context)) {
+        BatchMutateContext lastContext = 
existingPendingRow.addAndGetPrevCtx(context);
+        if (lastContext != null) {
           BatchMutatePhase phase = lastContext.getCurrentPhase();
           Preconditions.checkArgument(phase != BatchMutatePhase.POST,
             "the phase of the last batch cannot be POST");
@@ -1720,7 +1718,7 @@ public class IndexRegionObserver implements 
RegionCoprocessor, RegionObserver {
         CountDownLatch countDownLatch = lastContext.getCountDownLatch();
         if (countDownLatch == null) {
           // phase changed from PRE to either FAILED or POST
-          if (phase == BatchMutatePhase.FAILED) {
+          if (lastContext.getCurrentPhase() == BatchMutatePhase.FAILED) {
             context.currentPhase = BatchMutatePhase.FAILED;
             break;
           }

Reply via email to