From 14f80913e55d6994398aab8cfc80ceab4d348887 Mon Sep 17 00:00:00 2001 From: ramkrishna Date: Fri, 20 Apr 2012 17:36:02 +0000 Subject: [PATCH] HBASE-5809 Avoid move api to take the destination server same as the source server. (Rajesh) git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1328458 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/hadoop/hbase/master/HMaster.java | 5 +++++ .../apache/hadoop/hbase/client/TestAdmin.java | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/main/java/org/apache/hadoop/hbase/master/HMaster.java b/src/main/java/org/apache/hadoop/hbase/master/HMaster.java index 7a66a02d841..d47b83a0187 100644 --- a/src/main/java/org/apache/hadoop/hbase/master/HMaster.java +++ b/src/main/java/org/apache/hadoop/hbase/master/HMaster.java @@ -1174,6 +1174,11 @@ Server { this.assignmentManager.unassign(hri); } else { dest = new ServerName(Bytes.toString(destServerName)); + if (dest.equals(p.getSecond())) { + LOG.debug("Skipping move of region " + hri.getRegionNameAsString() + + " because region already assigned to the same server " + dest +"."); + return; + } try { if (this.cpHost != null) { if (this.cpHost.preMove(p.getFirst(), p.getSecond(), dest)) { diff --git a/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java b/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java index aa7f51bff38..804dfdeeed5 100644 --- a/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java +++ b/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java @@ -43,6 +43,8 @@ import org.apache.hadoop.hbase.*; import org.apache.hadoop.hbase.executor.EventHandler; import org.apache.hadoop.hbase.executor.EventHandler.EventType; import org.apache.hadoop.hbase.executor.ExecutorService; +import org.apache.hadoop.hbase.master.AssignmentManager; +import org.apache.hadoop.hbase.master.HMaster; import org.apache.hadoop.hbase.master.MasterServices; import org.apache.hadoop.hbase.regionserver.HRegion; import org.apache.hadoop.hbase.regionserver.HRegionServer; @@ -1404,6 +1406,22 @@ public class TestAdmin { assertTrue(("actual count: " + count), count <= 2); } + @Test + public void testMoveToPreviouslyAssignedRS() throws IOException { + byte[] tableName = Bytes.toBytes("testMoveToPreviouslyAssignedRS"); + MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); + HMaster master = cluster.getMaster(); + HBaseAdmin localAdmin = createTable(tableName); + List tableRegions = localAdmin.getTableRegions(tableName); + HRegionInfo hri = tableRegions.get(0); + AssignmentManager am = master.getAssignmentManager(); + ServerName server = am.getRegionServerOfRegion(hri); + localAdmin.move(hri.getEncodedNameAsBytes(), Bytes.toBytes(server.getServerName())); + assertEquals("Current region server and region server before move should be same.", server, + am.getRegionServerOfRegion(hri)); + } + + private void setUpforLogRolling() { // Force a region split after every 768KB TEST_UTIL.getConfiguration().setLong(HConstants.HREGION_MAX_FILESIZE,