From e7195a2e3cbc4124f6bde8c281199e7a1e87089d Mon Sep 17 00:00:00 2001 From: jxiang Date: Mon, 16 Sep 2013 23:05:30 +0000 Subject: [PATCH] HBASE-9525 "Move" region right after a region split is dangerous git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1523832 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop/hbase/master/AssignmentManager.java | 9 ++++++++- .../TestRegionMergeTransactionOnCluster.java | 12 +++++++++--- .../regionserver/TestSplitTransactionOnCluster.java | 12 +++++++++--- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java index 5c1905ef9f4..b594cba6526 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java @@ -2295,6 +2295,13 @@ public class AssignmentManager extends ZooKeeperListener { RegionState state = regionStates.getRegionTransitionState(encodedName); try { if (state == null) { + // Region is not in transition. + // We can unassign it only if it's not SPLIT/MERGED. + state = regionStates.getRegionState(encodedName); + if (state.isMerged() || state.isSplit()) { + LOG.info("Attempting to unassign " + state + ", ignored"); + return; + } // Create the znode in CLOSING state try { state = regionStates.getRegionState(region); @@ -2307,7 +2314,7 @@ public class AssignmentManager extends ZooKeeperListener { versionOfClosingNode = ZKAssign.createNodeClosing( watcher, region, state.getServerName()); if (versionOfClosingNode == -1) { - LOG.debug("Attempting to unassign " + + LOG.info("Attempting to unassign " + region.getRegionNameAsString() + " but ZK closing node " + "can't be created."); return; diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionMergeTransactionOnCluster.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionMergeTransactionOnCluster.java index f54889857c4..aac801ea177 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionMergeTransactionOnCluster.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionMergeTransactionOnCluster.java @@ -140,9 +140,15 @@ public class TestRegionMergeTransactionOnCluster { // We should not be able to assign it again am.assign(hri, true, true); - assertFalse("Merged region should not be in transition again", - regionStates.isRegionInTransition(hri) - && regionStates.isRegionInState(hri, State.MERGED)); + assertFalse("Merged region can't be assigned", + regionStates.isRegionInTransition(hri)); + assertTrue(regionStates.isRegionInState(hri, State.MERGED)); + + // We should not be able to unassign it either + am.unassign(hri, true, null); + assertFalse("Merged region can't be unassigned", + regionStates.isRegionInTransition(hri)); + assertTrue(regionStates.isRegionInState(hri, State.MERGED)); table.close(); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitTransactionOnCluster.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitTransactionOnCluster.java index f035b67ddd3..dfd1bf723b5 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitTransactionOnCluster.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitTransactionOnCluster.java @@ -850,9 +850,15 @@ public class TestSplitTransactionOnCluster { // We should not be able to assign it again am.assign(hri, true, true); - assertFalse("Split region should not be in transition again", - regionStates.isRegionInTransition(hri) - && regionStates.isRegionInState(hri, State.SPLIT)); + assertFalse("Split region can't be assigned", + regionStates.isRegionInTransition(hri)); + assertTrue(regionStates.isRegionInState(hri, State.SPLIT)); + + // We should not be able to unassign it either + am.unassign(hri, true, null); + assertFalse("Split region can't be unassigned", + regionStates.isRegionInTransition(hri)); + assertTrue(regionStates.isRegionInState(hri, State.SPLIT)); } finally { admin.setBalancerRunning(true, false); cluster.getMaster().setCatalogJanitorEnabled(true);