You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ya...@apache.org on 2020/12/02 04:58:03 UTC

[phoenix] branch 4.x updated: PHOENIX-5860 Throw exception which region is closing or splitting when delete data

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

yanxinyi 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 f604877  PHOENIX-5860 Throw exception which region is closing or splitting when delete data
f604877 is described below

commit f604877bc30a1b0e5a4b0c41af94614cf83d0ffc
Author: wangchao 00549253 <wa...@huawei.com>
AuthorDate: Thu Sep 10 10:37:51 2020 +0800

    PHOENIX-5860 Throw exception which region is closing or splitting when delete data
    
    Signed-off-by: Xinyi Yan <ya...@apache.org>
---
 .../UngroupedAggregateRegionObserver.java          | 13 +++++
 .../UngroupedAggregateRegionObserverTest.java      | 58 ++++++++++++++++++++++
 2 files changed, 71 insertions(+)

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 5023dad..6ec9bb3 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
@@ -977,4 +977,17 @@ public class UngroupedAggregateRegionObserver extends BaseScannerRegionObserver
         }
         return s;
     }
+
+     /**
+     * roll back after split failed, will isRegionClosingOrSplitting set false,
+     * and then write region will is available
+     * @param ctx
+     * @throws IOException
+     */
+    @Override
+    public void postRollBackSplit(ObserverContext<RegionCoprocessorEnvironment> ctx) throws IOException {
+        synchronized (lock) {
+            isRegionClosingOrSplitting = false;
+        }
+    }
 }
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/coprocessor/UngroupedAggregateRegionObserverTest.java b/phoenix-core/src/test/java/org/apache/phoenix/coprocessor/UngroupedAggregateRegionObserverTest.java
new file mode 100644
index 0000000..e818fdc
--- /dev/null
+++ b/phoenix-core/src/test/java/org/apache/phoenix/coprocessor/UngroupedAggregateRegionObserverTest.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * 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.coprocessor;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.HConstants;
+import org.apache.hadoop.hbase.coprocessor.ObserverContext;
+import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import java.lang.reflect.Field;
+
+/**
+ * Test UngroupedAggregateRegionObserver
+ */
+public class UngroupedAggregateRegionObserverTest {
+
+    /**
+     * Tests RollBackSplit
+     * postRollBackSplit
+     */
+    @Test
+    public void testSplitFailedRollBack() throws Exception {
+        Class<UngroupedAggregateRegionObserver> ungroupClass = (Class<UngroupedAggregateRegionObserver>) Class.forName(UngroupedAggregateRegionObserver.class.getName());
+        UngroupedAggregateRegionObserver ungroupObserver = new UngroupedAggregateRegionObserver();
+        ObserverContext context = Mockito.mock(ObserverContext.class);
+        RegionCoprocessorEnvironment env = Mockito.mock(RegionCoprocessorEnvironment.class);
+        Configuration conf = new Configuration();
+        conf.set(HConstants.HBASE_CLIENT_OPERATION_TIMEOUT, String.valueOf(HConstants.DEFAULT_HBASE_CLIENT_OPERATION_TIMEOUT));
+        Mockito.when(context.getEnvironment()).thenReturn(env);
+        Mockito.when(env.getConfiguration()).thenReturn(conf);
+        ungroupObserver.preSplit(context, null);
+        ungroupObserver.postRollBackSplit(context);
+        Field fieldTag = ungroupClass.getDeclaredField("isRegionClosingOrSplitting");
+        fieldTag.setAccessible(true);
+        Boolean isRegionClosingOrSplitting = (Boolean) fieldTag.get(ungroupObserver);
+        assertEquals(isRegionClosingOrSplitting, false);
+    }
+}
+