hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From te...@apache.org
Subject hbase git commit: HBASE-10528 DefaultBalancer selects plans to move regions onto draining nodes (Churro Morales)
Date Thu, 08 Jan 2015 23:08:17 GMT
Repository: hbase
Updated Branches:
  refs/heads/branch-1.0 bfc0c74cb -> 483e55e2f


HBASE-10528 DefaultBalancer selects plans to move regions onto draining nodes (Churro Morales)


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/483e55e2
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/483e55e2
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/483e55e2

Branch: refs/heads/branch-1.0
Commit: 483e55e2fa0817a2f8d12c9635d2def05f78a3e6
Parents: bfc0c74
Author: tedyu <yuzhihong@gmail.com>
Authored: Thu Jan 8 15:07:57 2015 -0800
Committer: tedyu <yuzhihong@gmail.com>
Committed: Thu Jan 8 15:07:57 2015 -0800

----------------------------------------------------------------------
 .../hadoop/hbase/master/RegionStates.java       |  4 +-
 .../hadoop/hbase/master/TestRegionStates.java   | 87 ++++++++++++++++++++
 2 files changed, 90 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/483e55e2/hbase-server/src/main/java/org/apache/hadoop/hbase/master/RegionStates.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/RegionStates.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/RegionStates.java
index 46d21c7..b19bbb8 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/RegionStates.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/RegionStates.java
@@ -926,13 +926,15 @@ public class RegionStates {
 
     Map<ServerName, ServerLoad>
       onlineSvrs = serverManager.getOnlineServers();
-    // Take care of servers w/o assignments.
+    // Take care of servers w/o assignments, and remove servers in draining mode
+    List<ServerName> drainingServers = this.serverManager.getDrainingServersList();
     for (Map<ServerName, List<HRegionInfo>> map: result.values()) {
       for (ServerName svr: onlineSvrs.keySet()) {
         if (!map.containsKey(svr)) {
           map.put(svr, new ArrayList<HRegionInfo>());
         }
       }
+      map.keySet().removeAll(drainingServers);
     }
     return result;
   }

http://git-wip-us.apache.org/repos/asf/hbase/blob/483e55e2/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRegionStates.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRegionStates.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRegionStates.java
new file mode 100644
index 0000000..20cbd62
--- /dev/null
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRegionStates.java
@@ -0,0 +1,87 @@
+/**
+ * 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.hadoop.hbase.master;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.HRegionInfo;
+import org.apache.hadoop.hbase.Server;
+import org.apache.hadoop.hbase.ServerName;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.TableStateManager;
+import org.apache.hadoop.hbase.testclassification.SmallTests;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import static junit.framework.Assert.assertFalse;
+import static org.mockito.Matchers.isA;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+@Category(SmallTests.class)
+public class TestRegionStates {
+
+
+  @Test
+  public void testWeDontReturnDrainingServersForOurBalancePlans() throws Exception {
+    Server server = mock(Server.class);
+    when(server.getServerName()).thenReturn(ServerName.valueOf("master,1,1"));
+    Configuration configuration = mock(Configuration.class);
+    when(server.getConfiguration()).thenReturn(configuration);
+    TableStateManager tsm = mock(TableStateManager.class);
+    ServerManager sm = mock(ServerManager.class);
+    when(sm.isServerOnline(isA(ServerName.class))).thenReturn(true);
+
+    RegionStateStore rss = mock(RegionStateStore.class);
+    RegionStates regionStates = new RegionStates(server, tsm, sm, rss);
+
+    ServerName one = mockServer("one", 1);
+    ServerName two = mockServer("two", 1);
+    ServerName three = mockServer("three", 1);
+
+    when(sm.getDrainingServersList()).thenReturn(Arrays.asList(three));
+
+    regionStates.regionOnline(createFakeRegion(), one);
+    regionStates.regionOnline(createFakeRegion(), two);
+    regionStates.regionOnline(createFakeRegion(), three);
+
+
+    Map<TableName, Map<ServerName, List<HRegionInfo>>> result =
+        regionStates.getAssignmentsByTable();
+    for (Map<ServerName, List<HRegionInfo>> map : result.values()) {
+      assertFalse(map.keySet().contains(three));
+    }
+  }
+
+  private HRegionInfo createFakeRegion() {
+    HRegionInfo info = mock(HRegionInfo.class);
+    when(info.getEncodedName()).thenReturn(UUID.randomUUID().toString());
+    return info;
+  }
+
+  private ServerName mockServer(String fakeHost, int fakePort) {
+    ServerName serverName = mock(ServerName.class);
+    when(serverName.getHostname()).thenReturn(fakeHost);
+    when(serverName.getPort()).thenReturn(fakePort);
+    return serverName;
+  }
+}


Mime
View raw message