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

tkhurana pushed a commit to branch 5.2
in repository https://gitbox.apache.org/repos/asf/phoenix.git


The following commit(s) were added to refs/heads/5.2 by this push:
     new b821227037 PHOENIX-7591 Concurrent updates to tables with indexes can 
cause data inconsistency
b821227037 is described below

commit b8212270374345fc338350e5eeefa6a39e9f9a48
Author: tkhurana <[email protected]>
AuthorDate: Thu May 22 10:55:14 2025 -0700

    PHOENIX-7591 Concurrent updates to tables with indexes can cause data 
inconsistency
---
 .../phoenix/hbase/index/util/IndexManagementUtil.java   |  2 +-
 .../apache/phoenix/hbase/index/IndexRegionObserver.java | 17 ++++++++++++-----
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git 
a/phoenix-core-client/src/main/java/org/apache/phoenix/hbase/index/util/IndexManagementUtil.java
 
b/phoenix-core-client/src/main/java/org/apache/phoenix/hbase/index/util/IndexManagementUtil.java
index 3d8c111d8e..3b03e7f51b 100644
--- 
a/phoenix-core-client/src/main/java/org/apache/phoenix/hbase/index/util/IndexManagementUtil.java
+++ 
b/phoenix-core-client/src/main/java/org/apache/phoenix/hbase/index/util/IndexManagementUtil.java
@@ -199,7 +199,7 @@ public class IndexManagementUtil {
         try {
             throw e;
         } catch (IOException | FatalIndexBuildingFailureException e1) {
-            LOGGER.info("Rethrowing " + e);
+            LOGGER.info("Rethrowing ", e);
             throw e1;
         }
         catch (Throwable e1) {
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 d4e965bbe9..884f1ed2c2 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
@@ -224,9 +224,9 @@ public class IndexRegionObserver implements 
RegionCoprocessor, RegionObserver {
         ignoreWritingDeleteColumnsToIndex = ignore;
     }
 
-  public enum BatchMutatePhase {
-      PRE, POST, FAILED
-  }
+    public enum BatchMutatePhase {
+        INIT, PRE, POST, FAILED
+    }
 
   // Hack to get around not being able to save any state between
   // coprocessor calls. TODO: remove after HBASE-18127 when available
@@ -240,7 +240,7 @@ public class IndexRegionObserver implements 
RegionCoprocessor, RegionObserver {
    */
 
   public static class BatchMutateContext {
-      private volatile BatchMutatePhase currentPhase = BatchMutatePhase.PRE;
+      private volatile BatchMutatePhase currentPhase = BatchMutatePhase.INIT;
       // The max of reference counts on the pending rows of this batch at the 
time this batch arrives
       private int maxPendingRowCount = 0;
       private final int clientVersion;
@@ -1281,6 +1281,8 @@ public class IndexRegionObserver implements 
RegionCoprocessor, RegionObserver {
             return;
         }
         lockRows(context);
+        // acquired the locks, move to the next phase PRE
+        context.currentPhase = BatchMutatePhase.PRE;
         long onDupCheckTime = 0;
 
         if (context.hasAtomic || context.hasGlobalIndex || 
context.hasUncoveredIndex || context.hasTransform) {
@@ -1437,6 +1439,12 @@ public class IndexRegionObserver implements 
RegionCoprocessor, RegionObserver {
           return;
       }
       try {
+          // We add to pending rows only after we have locked all the rows in 
the batch
+          // If we are in the INIT phase that means we failed to acquire the 
locks before the
+          // PRE phase
+          if (context.getCurrentPhase() != BatchMutatePhase.INIT) {
+              removePendingRows(context);
+          }
           if (success) {
               context.currentPhase = BatchMutatePhase.POST;
               if(context.hasAtomic && miniBatchOp.size() == 1) {
@@ -1454,7 +1462,6 @@ public class IndexRegionObserver implements 
RegionCoprocessor, RegionObserver {
               context.currentPhase = BatchMutatePhase.FAILED;
           }
           context.countDownAllLatches();
-          removePendingRows(context);
           if (context.indexUpdates != null) {
               context.indexUpdates.clear();
           }

Reply via email to