You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by st...@apache.org on 2021/03/15 23:56:12 UTC
[hbase] branch branch-1 updated: HBASE-24395 Backport HBASE-20589
to branch-1 (#2690)
This is an automated email from the ASF dual-hosted git repository.
stack pushed a commit to branch branch-1
in repository https://gitbox.apache.org/repos/asf/hbase.git
The following commit(s) were added to refs/heads/branch-1 by this push:
new 9534a1b HBASE-24395 Backport HBASE-20589 to branch-1 (#2690)
9534a1b is described below
commit 9534a1b150360b47d5a6a70f5fee85f647d4d492
Author: Bo Cui <cu...@163.com>
AuthorDate: Tue Mar 16 07:55:41 2021 +0800
HBASE-24395 Backport HBASE-20589 to branch-1 (#2690)
Signed-off-by: Pankaj Kumar<pa...@apache.org>
Signed-off-by: stack <st...@apache.org>
---
.../java/org/apache/hadoop/hbase/ServerName.java | 4 ++
.../hbase/master/balancer/BaseLoadBalancer.java | 6 +-
.../hadoop/hbase/regionserver/HRegionServer.java | 8 +--
.../org/apache/hadoop/hbase/TestServerName.java | 19 +++--
.../master/TestMetaAssignmentWithStopMaster.java | 82 ++++++++++++++++++++++
5 files changed, 103 insertions(+), 16 deletions(-)
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/ServerName.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/ServerName.java
index 97e78c9..ded0b09 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/ServerName.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/ServerName.java
@@ -213,6 +213,10 @@ public class ServerName implements Comparable<ServerName>, Serializable {
return hostnameOnly;
}
+ public String getHostnameLowerCase() {
+ return hostnameOnly.toLowerCase(Locale.ROOT);
+ }
+
public int getPort() {
return port;
}
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/BaseLoadBalancer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/BaseLoadBalancer.java
index b25b541..d7f5cc5 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/BaseLoadBalancer.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/BaseLoadBalancer.java
@@ -1594,7 +1594,7 @@ public abstract class BaseLoadBalancer implements LoadBalancer {
ArrayListMultimap<String, ServerName> serversByHostname = ArrayListMultimap.create();
for (ServerName server : servers) {
assignments.put(server, new ArrayList<HRegionInfo>());
- serversByHostname.put(server.getHostname(), server);
+ serversByHostname.put(server.getHostnameLowerCase(), server);
}
// Collection of the hostnames that used to have regions
@@ -1613,13 +1613,13 @@ public abstract class BaseLoadBalancer implements LoadBalancer {
ServerName oldServerName = entry.getValue();
List<ServerName> localServers = new ArrayList<ServerName>();
if (oldServerName != null) {
- localServers = serversByHostname.get(oldServerName.getHostname());
+ localServers = serversByHostname.get(oldServerName.getHostnameLowerCase());
}
if (localServers.isEmpty()) {
// No servers on the new cluster match up with this hostname, assign randomly, later.
randomAssignRegions.add(region);
if (oldServerName != null) {
- oldHostsNoLongerPresent.add(oldServerName.getHostname());
+ oldHostsNoLongerPresent.add(oldServerName.getHostnameLowerCase());
}
} else if (localServers.size() == 1) {
// the usual case - one new server on same host
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
index 531038c..5f5c9c5 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
@@ -1292,9 +1292,7 @@ public class HRegionServer extends HasThread implements
ClusterStatusProtos.ServerLoad sl = buildServerLoad(reportStartTime, reportEndTime);
try {
RegionServerReportRequest.Builder request = RegionServerReportRequest.newBuilder();
- ServerName sn = ServerName.parseVersionedServerName(
- this.serverName.getVersionedBytes());
- request.setServer(ProtobufUtil.toServerName(sn));
+ request.setServer(ProtobufUtil.toServerName(this.serverName));
request.setLoad(sl);
rss.regionServerReport(null, request.build());
} catch (ServiceException se) {
@@ -2341,9 +2339,7 @@ public class HRegionServer extends HasThread implements
if (rssStub != null && this.serverName != null) {
ReportRSFatalErrorRequest.Builder builder =
ReportRSFatalErrorRequest.newBuilder();
- ServerName sn =
- ServerName.parseVersionedServerName(this.serverName.getVersionedBytes());
- builder.setServer(ProtobufUtil.toServerName(sn));
+ builder.setServer(ProtobufUtil.toServerName(this.serverName));
builder.setErrorMessage(msg);
rssStub.reportRSFatalError(null, builder.build());
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestServerName.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestServerName.java
index 2c90f34..3866fb4 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestServerName.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestServerName.java
@@ -68,16 +68,21 @@ public class TestServerName {
}
@Test public void testParseOfBytes() {
- final String snStr = "www.example.org,1234,5678";
+ final String snStr = "www.EXAMPLE.org,1234,5678";
ServerName sn = ServerName.valueOf(snStr);
byte [] versionedBytes = sn.getVersionedBytes();
- assertEquals(sn.toString(), ServerName.parseVersionedServerName(versionedBytes).toString());
- final String hostnamePortStr = sn.getHostAndPort();
+ ServerName parsedSn = ServerName.parseVersionedServerName(versionedBytes);
+ assertEquals(sn.toString(), parsedSn.toString());
+ assertEquals(sn.getHostnameLowerCase(), parsedSn.getHostnameLowerCase());
+ assertEquals(sn.getPort(), parsedSn.getPort());
+ assertEquals(sn.getStartcode(), parsedSn.getStartcode());
+
+ final String hostnamePortStr = sn.getAddress().toString();
byte [] bytes = Bytes.toBytes(hostnamePortStr);
- String expecting =
- hostnamePortStr.replace(":", ServerName.SERVERNAME_SEPARATOR) +
- ServerName.SERVERNAME_SEPARATOR + ServerName.NON_STARTCODE;
- assertEquals(expecting, ServerName.parseVersionedServerName(bytes).toString());
+ parsedSn = ServerName.parseVersionedServerName(bytes);
+ assertEquals(sn.getHostnameLowerCase(), parsedSn.getHostnameLowerCase());
+ assertEquals(sn.getPort(), parsedSn.getPort());
+ assertEquals(ServerName.NON_STARTCODE, parsedSn.getStartcode());
}
@Test
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMetaAssignmentWithStopMaster.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMetaAssignmentWithStopMaster.java
new file mode 100644
index 0000000..4abf2c5
--- /dev/null
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMetaAssignmentWithStopMaster.java
@@ -0,0 +1,82 @@
+/**
+ * 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 static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.apache.hadoop.hbase.HBaseTestingUtility;
+import org.apache.hadoop.hbase.HRegionInfo;
+import org.apache.hadoop.hbase.ServerName;
+import org.apache.hadoop.hbase.client.ClusterConnection;
+import org.apache.hadoop.hbase.client.ConnectionFactory;
+import org.apache.hadoop.hbase.testclassification.LargeTests;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Category({ LargeTests.class })
+public class TestMetaAssignmentWithStopMaster {
+
+ private static final Logger LOG =
+ LoggerFactory.getLogger(TestMetaAssignmentWithStopMaster.class);
+
+ private static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
+
+ private static final long WAIT_TIMEOUT = 120000;
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ UTIL.startMiniCluster(2,3);
+ }
+
+ @Test
+ public void testStopActiveMaster() throws Exception {
+ ClusterConnection conn =
+ (ClusterConnection) ConnectionFactory.createConnection(UTIL.getConfiguration());
+ ServerName oldMetaServer = conn.locateRegion(HRegionInfo.FIRST_META_REGIONINFO
+ .getRegionName()).getServerName();
+ ServerName oldMaster = UTIL.getMiniHBaseCluster().getMaster().getServerName();
+
+ UTIL.getMiniHBaseCluster().getMaster().stop("Stop master for test");
+ long startTime = System.currentTimeMillis();
+ while (UTIL.getMiniHBaseCluster().getMaster() == null || UTIL.getMiniHBaseCluster().getMaster()
+ .getServerName().equals(oldMaster)) {
+ LOG.info("Wait the standby master become active");
+ Thread.sleep(3000);
+ if (System.currentTimeMillis() - startTime > WAIT_TIMEOUT) {
+ fail("Wait too long for standby master become active");
+ }
+ }
+ startTime = System.currentTimeMillis();
+ while (!UTIL.getMiniHBaseCluster().getMaster().isInitialized()) {
+ LOG.info("Wait the new active master to be initialized");
+ Thread.sleep(3000);
+ if (System.currentTimeMillis() - startTime > WAIT_TIMEOUT) {
+ fail("Wait too long for the new active master to be initialized");
+ }
+ }
+
+ ServerName newMetaServer = conn.locateRegion(HRegionInfo.FIRST_META_REGIONINFO
+ .getRegionName()).getServerName();
+ assertTrue("The new meta server " + newMetaServer + " should be same with" +
+ " the old meta server " + oldMetaServer, newMetaServer.equals(oldMetaServer));
+ }
+}