HBASE-20589 Don't need to assign meta to a new RS when standby master become active
This commit is contained in:
parent
ee540c9f9e
commit
320a3332e0
|
@ -233,6 +233,10 @@ public class ServerName implements Comparable<ServerName>, Serializable {
|
||||||
return this.address.getHostname();
|
return this.address.getHostname();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getHostnameLowerCase() {
|
||||||
|
return this.address.getHostname().toLowerCase(Locale.ROOT);
|
||||||
|
}
|
||||||
|
|
||||||
public int getPort() {
|
public int getPort() {
|
||||||
return this.address.getPort();
|
return this.address.getPort();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1405,7 +1405,7 @@ public abstract class BaseLoadBalancer implements LoadBalancer {
|
||||||
ArrayListMultimap<String, ServerName> serversByHostname = ArrayListMultimap.create();
|
ArrayListMultimap<String, ServerName> serversByHostname = ArrayListMultimap.create();
|
||||||
for (ServerName server : servers) {
|
for (ServerName server : servers) {
|
||||||
assignments.put(server, new ArrayList<>());
|
assignments.put(server, new ArrayList<>());
|
||||||
serversByHostname.put(server.getHostname(), server);
|
serversByHostname.put(server.getHostnameLowerCase(), server);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collection of the hostnames that used to have regions
|
// Collection of the hostnames that used to have regions
|
||||||
|
@ -1426,13 +1426,13 @@ public abstract class BaseLoadBalancer implements LoadBalancer {
|
||||||
ServerName oldServerName = entry.getValue();
|
ServerName oldServerName = entry.getValue();
|
||||||
List<ServerName> localServers = new ArrayList<>();
|
List<ServerName> localServers = new ArrayList<>();
|
||||||
if (oldServerName != null) {
|
if (oldServerName != null) {
|
||||||
localServers = serversByHostname.get(oldServerName.getHostname());
|
localServers = serversByHostname.get(oldServerName.getHostnameLowerCase());
|
||||||
}
|
}
|
||||||
if (localServers.isEmpty()) {
|
if (localServers.isEmpty()) {
|
||||||
// No servers on the new cluster match up with this hostname, assign randomly, later.
|
// No servers on the new cluster match up with this hostname, assign randomly, later.
|
||||||
randomAssignRegions.add(region);
|
randomAssignRegions.add(region);
|
||||||
if (oldServerName != null) {
|
if (oldServerName != null) {
|
||||||
oldHostsNoLongerPresent.add(oldServerName.getHostname());
|
oldHostsNoLongerPresent.add(oldServerName.getHostnameLowerCase());
|
||||||
}
|
}
|
||||||
} else if (localServers.size() == 1) {
|
} else if (localServers.size() == 1) {
|
||||||
// the usual case - one new server on same host
|
// the usual case - one new server on same host
|
||||||
|
|
|
@ -1191,8 +1191,7 @@ public class HRegionServer extends HasThread implements
|
||||||
ClusterStatusProtos.ServerLoad sl = buildServerLoad(reportStartTime, reportEndTime);
|
ClusterStatusProtos.ServerLoad sl = buildServerLoad(reportStartTime, reportEndTime);
|
||||||
try {
|
try {
|
||||||
RegionServerReportRequest.Builder request = RegionServerReportRequest.newBuilder();
|
RegionServerReportRequest.Builder request = RegionServerReportRequest.newBuilder();
|
||||||
ServerName sn = ServerName.parseVersionedServerName(this.serverName.getVersionedBytes());
|
request.setServer(ProtobufUtil.toServerName(this.serverName));
|
||||||
request.setServer(ProtobufUtil.toServerName(sn));
|
|
||||||
request.setLoad(sl);
|
request.setLoad(sl);
|
||||||
rss.regionServerReport(null, request.build());
|
rss.regionServerReport(null, request.build());
|
||||||
} catch (ServiceException se) {
|
} catch (ServiceException se) {
|
||||||
|
@ -2378,9 +2377,7 @@ public class HRegionServer extends HasThread implements
|
||||||
if (rssStub != null && this.serverName != null) {
|
if (rssStub != null && this.serverName != null) {
|
||||||
ReportRSFatalErrorRequest.Builder builder =
|
ReportRSFatalErrorRequest.Builder builder =
|
||||||
ReportRSFatalErrorRequest.newBuilder();
|
ReportRSFatalErrorRequest.newBuilder();
|
||||||
ServerName sn =
|
builder.setServer(ProtobufUtil.toServerName(this.serverName));
|
||||||
ServerName.parseVersionedServerName(this.serverName.getVersionedBytes());
|
|
||||||
builder.setServer(ProtobufUtil.toServerName(sn));
|
|
||||||
builder.setErrorMessage(msg);
|
builder.setErrorMessage(msg);
|
||||||
rssStub.reportRSFatalError(null, builder.build());
|
rssStub.reportRSFatalError(null, builder.build());
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,16 +87,21 @@ public class TestServerName {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void testParseOfBytes() {
|
@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);
|
ServerName sn = ServerName.valueOf(snStr);
|
||||||
byte [] versionedBytes = sn.getVersionedBytes();
|
byte [] versionedBytes = sn.getVersionedBytes();
|
||||||
assertEquals(sn.toString(), ServerName.parseVersionedServerName(versionedBytes).toString());
|
ServerName parsedSn = ServerName.parseVersionedServerName(versionedBytes);
|
||||||
final String hostnamePortStr = sn.getHostAndPort();
|
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);
|
byte [] bytes = Bytes.toBytes(hostnamePortStr);
|
||||||
String expecting =
|
parsedSn = ServerName.parseVersionedServerName(bytes);
|
||||||
hostnamePortStr.replace(":", ServerName.SERVERNAME_SEPARATOR) +
|
assertEquals(sn.getHostnameLowerCase(), parsedSn.getHostnameLowerCase());
|
||||||
ServerName.SERVERNAME_SEPARATOR + ServerName.NON_STARTCODE;
|
assertEquals(sn.getPort(), parsedSn.getPort());
|
||||||
assertEquals(expecting, ServerName.parseVersionedServerName(bytes).toString());
|
assertEquals(ServerName.NON_STARTCODE, parsedSn.getStartcode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -0,0 +1,86 @@
|
||||||
|
/**
|
||||||
|
* 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.HBaseClassTestRule;
|
||||||
|
import org.apache.hadoop.hbase.HBaseTestingUtility;
|
||||||
|
import org.apache.hadoop.hbase.ServerName;
|
||||||
|
import org.apache.hadoop.hbase.TableName;
|
||||||
|
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.ClassRule;
|
||||||
|
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);
|
||||||
|
|
||||||
|
@ClassRule
|
||||||
|
public static final HBaseClassTestRule CLASS_RULE =
|
||||||
|
HBaseClassTestRule.forClass(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.locateRegions(TableName.META_TABLE_NAME).get(0).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.locateRegions(TableName.META_TABLE_NAME).get(0).getServerName();
|
||||||
|
assertTrue("The new meta server " + newMetaServer + " should be same with" +
|
||||||
|
" the old meta server " + oldMetaServer, newMetaServer.equals(oldMetaServer));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue