You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ac...@apache.org on 2021/07/15 00:00:57 UTC

[phoenix] branch 4.x updated: PHOENIX-6511 Deletes fail in case of failed region split

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

achouhan pushed a commit to branch 4.x
in repository https://gitbox.apache.org/repos/asf/phoenix.git


The following commit(s) were added to refs/heads/4.x by this push:
     new b40ad14  PHOENIX-6511 Deletes fail in case of failed region split
     new fb40ece  Merge pull request #1266 from abhishek-chouhan/PHOENIX-6511
b40ad14 is described below

commit b40ad141d8fa7e33f1eadc43f387af1c388f8b62
Author: Abhishek Singh Chouhan <ab...@salesforce.com>
AuthorDate: Wed Jul 14 16:56:35 2021 -0700

    PHOENIX-6511 Deletes fail in case of failed region split
---
 ...oupedAggregateRegionObserverSplitFailureIT.java | 109 +++++++++++++++++++++
 .../UngroupedAggregateRegionObserver.java          |  14 +++
 2 files changed, 123 insertions(+)

diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UngroupedAggregateRegionObserverSplitFailureIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UngroupedAggregateRegionObserverSplitFailureIT.java
new file mode 100644
index 0000000..a8a1eb7
--- /dev/null
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UngroupedAggregateRegionObserverSplitFailureIT.java
@@ -0,0 +1,109 @@
+/*
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.end2end;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.List;
+import java.util.UUID;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.HBaseConfiguration;
+import org.apache.hadoop.hbase.HBaseTestingUtility;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.coprocessor.ObserverContext;
+import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
+import org.apache.hadoop.hbase.regionserver.HRegion;
+import org.apache.phoenix.coprocessor.UngroupedAggregateRegionObserver;
+import org.apache.phoenix.jdbc.PhoenixDriver;
+import org.apache.phoenix.util.PhoenixRuntime;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class UngroupedAggregateRegionObserverSplitFailureIT extends BaseUniqueNamesOwnClusterIT {
+    
+    private static HBaseTestingUtility hbaseTestUtil;
+    private static String url;
+
+    @BeforeClass
+    public static synchronized void doSetup() throws Exception {
+        Configuration conf = HBaseConfiguration.create();
+        hbaseTestUtil = new HBaseTestingUtility(conf);
+        setUpConfigForMiniCluster(conf);
+        hbaseTestUtil.startMiniCluster();
+        // establish url and quorum. Need to use PhoenixDriver and not PhoenixTestDriver
+        String zkQuorum = "localhost:" + hbaseTestUtil.getZkCluster().getClientPort();
+        url = PhoenixRuntime.JDBC_PROTOCOL + PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR + zkQuorum;
+        DriverManager.registerDriver(PhoenixDriver.INSTANCE);
+    }
+
+    @AfterClass
+    public static synchronized void tearDownAfterClass() throws Exception {
+        if (hbaseTestUtil != null) {
+            hbaseTestUtil.shutdownMiniCluster();
+        }
+    }
+
+    @Test
+    public void testDeleteAfterSplitFailure() throws SQLException, IOException {
+        String tableName = generateUniqueName();
+        int numRecords = 100;
+        try (Connection conn = DriverManager.getConnection(url)) {
+            conn.createStatement().execute(
+                "CREATE TABLE " + tableName + " (PK1 INTEGER NOT NULL PRIMARY KEY, KV1 VARCHAR)");
+            int i = 0;
+            String upsert = "UPSERT INTO " + tableName + " VALUES (?, ?)";
+            PreparedStatement stmt = conn.prepareStatement(upsert);
+            while (i < numRecords) {
+                stmt.setInt(1, i);
+                stmt.setString(2, UUID.randomUUID().toString());
+                stmt.executeUpdate();
+                i++;
+            }
+            conn.commit();
+
+            List<HRegion> regions =
+                    hbaseTestUtil.getMiniHBaseCluster().getRegions(TableName.valueOf(tableName));
+            for (HRegion region : regions) {
+                UngroupedAggregateRegionObserver obs =
+                        (UngroupedAggregateRegionObserver) region.getCoprocessorHost()
+                                .findCoprocessor(UngroupedAggregateRegionObserver.class.getName());
+                ObserverContext<RegionCoprocessorEnvironment> ctx = new ObserverContext<>(null);
+                ctx.prepare((RegionCoprocessorEnvironment) region.getCoprocessorHost()
+                        .findCoprocessorEnvironment(
+                            UngroupedAggregateRegionObserver.class.getName()));
+                // Simulate a split failure between pre and post, in this case the region still
+                // remains open. Note - preRollBackSplit gets called in case of split failure before
+                // rollback
+                obs.preSplit(ctx, null);
+                obs.preRollBackSplit(ctx);
+            }
+            // We want to do server side deletes here
+            conn.setAutoCommit(true);
+            int rowsDeleted =
+                    conn.createStatement()
+                            .executeUpdate("DELETE FROM " + tableName + " WHERE PK1 > 90");
+            assertEquals(rowsDeleted, 9);
+        }
+    }
+}
\ No newline at end of file
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/UngroupedAggregateRegionObserver.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/UngroupedAggregateRegionObserver.java
index cdec974..f7ccced 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/UngroupedAggregateRegionObserver.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/UngroupedAggregateRegionObserver.java
@@ -863,6 +863,20 @@ public class UngroupedAggregateRegionObserver extends BaseScannerRegionObserver
         waitForScansToFinish(c);
     }
 
+    @Override
+    public void preRollBackSplit(ObserverContext<RegionCoprocessorEnvironment> ctx)
+            throws IOException {
+        // We need to reset the state in case of a failed split
+        Region region = ctx.getEnvironment().getRegion();
+        synchronized (lock) {
+            if (isRegionClosingOrSplitting) {
+                if (!region.isClosed() && !region.isClosing()) {
+                    isRegionClosingOrSplitting = false;
+                }
+            }
+        }
+    }
+
     // Don't allow splitting/closing if operations need read and write to same region are going on in the
     // the coprocessors to avoid dead lock scenario. See PHOENIX-3111.
     private void waitForScansToFinish(ObserverContext<RegionCoprocessorEnvironment> c) throws IOException {