HBASE-21541 Move MetaTableLocator.verifyRegionLocation to hbase-rsgroup module
This commit is contained in:
parent
59cfe2e31b
commit
8bf966c8e9
|
@ -757,8 +757,7 @@ final class RSGroupInfoManagerImpl implements RSGroupInfoManager {
|
|||
found.set(true);
|
||||
try {
|
||||
boolean rootMetaFound =
|
||||
masterServices.getMetaTableLocator().verifyMetaRegionLocation(
|
||||
conn, masterServices.getZooKeeper(), 1);
|
||||
Utility.verifyMetaRegionLocation(conn, masterServices.getZooKeeper(), 1);
|
||||
if (rootMetaFound) {
|
||||
MetaTableAccessor.Visitor visitor = new DefaultVisitorBase() {
|
||||
@Override
|
||||
|
|
|
@ -19,19 +19,49 @@
|
|||
*/
|
||||
package org.apache.hadoop.hbase.rsgroup;
|
||||
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.net.ConnectException;
|
||||
import java.net.NoRouteToHostException;
|
||||
import java.net.SocketException;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.hadoop.hbase.NotAllMetaRegionsOnlineException;
|
||||
import org.apache.hadoop.hbase.ServerName;
|
||||
import org.apache.hadoop.hbase.client.ClusterConnection;
|
||||
import org.apache.hadoop.hbase.client.RegionInfo;
|
||||
import org.apache.hadoop.hbase.client.RegionInfoBuilder;
|
||||
import org.apache.hadoop.hbase.client.RegionReplicaUtil;
|
||||
import org.apache.hadoop.hbase.client.RetriesExhaustedException;
|
||||
import org.apache.hadoop.hbase.ipc.FailedServerException;
|
||||
import org.apache.hadoop.hbase.ipc.HBaseRpcController;
|
||||
import org.apache.hadoop.hbase.ipc.ServerNotRunningYetException;
|
||||
import org.apache.hadoop.hbase.master.MasterServices;
|
||||
import org.apache.hadoop.hbase.net.Address;
|
||||
import org.apache.hadoop.hbase.regionserver.RegionServerStoppedException;
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
import org.apache.hadoop.hbase.zookeeper.MetaTableLocator;
|
||||
import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
|
||||
import org.apache.hadoop.ipc.RemoteException;
|
||||
import org.apache.yetus.audience.InterfaceAudience;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
|
||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos;
|
||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.AdminService;
|
||||
|
||||
/**
|
||||
* Utility for this RSGroup package in hbase-rsgroup.
|
||||
*/
|
||||
@InterfaceAudience.Private
|
||||
final class Utility {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(Utility.class);
|
||||
|
||||
private Utility() {
|
||||
}
|
||||
|
||||
|
@ -45,9 +75,171 @@ final class Utility {
|
|||
return onlineServers;
|
||||
}
|
||||
|
||||
for(ServerName server: master.getServerManager().getOnlineServers().keySet()) {
|
||||
for (ServerName server : master.getServerManager().getOnlineServers().keySet()) {
|
||||
onlineServers.add(server.getAddress());
|
||||
}
|
||||
return onlineServers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify <code>hbase:meta</code> is deployed and accessible.
|
||||
* @param hConnection the connection to use
|
||||
* @param zkw reference to the {@link ZKWatcher} which also contains configuration and operation
|
||||
* @param timeout How long to wait on zk for meta address (passed through to the internal call to
|
||||
* {@link #getMetaServerConnection}.
|
||||
* @return True if the <code>hbase:meta</code> location is healthy.
|
||||
* @throws IOException if the number of retries for getting the connection is exceeded
|
||||
* @throws InterruptedException if waiting for the socket operation fails
|
||||
*/
|
||||
public static boolean verifyMetaRegionLocation(ClusterConnection hConnection, ZKWatcher zkw,
|
||||
final long timeout) throws InterruptedException, IOException {
|
||||
return verifyMetaRegionLocation(hConnection, zkw, timeout, RegionInfo.DEFAULT_REPLICA_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify <code>hbase:meta</code> is deployed and accessible.
|
||||
* @param connection the connection to use
|
||||
* @param zkw reference to the {@link ZKWatcher} which also contains configuration and operation
|
||||
* @param timeout How long to wait on zk for meta address (passed through to
|
||||
* @param replicaId the ID of the replica
|
||||
* @return True if the <code>hbase:meta</code> location is healthy.
|
||||
* @throws InterruptedException if waiting for the socket operation fails
|
||||
* @throws IOException if the number of retries for getting the connection is exceeded
|
||||
*/
|
||||
public static boolean verifyMetaRegionLocation(ClusterConnection connection, ZKWatcher zkw,
|
||||
final long timeout, int replicaId) throws InterruptedException, IOException {
|
||||
AdminProtos.AdminService.BlockingInterface service = null;
|
||||
try {
|
||||
service = getMetaServerConnection(connection, zkw, timeout, replicaId);
|
||||
} catch (NotAllMetaRegionsOnlineException e) {
|
||||
// Pass
|
||||
} catch (ServerNotRunningYetException e) {
|
||||
// Pass -- remote server is not up so can't be carrying root
|
||||
} catch (UnknownHostException e) {
|
||||
// Pass -- server name doesn't resolve so it can't be assigned anything.
|
||||
} catch (RegionServerStoppedException e) {
|
||||
// Pass -- server name sends us to a server that is dying or already dead.
|
||||
}
|
||||
return (service != null) && verifyRegionLocation(connection, service,
|
||||
MetaTableLocator.getMetaRegionLocation(zkw, replicaId),
|
||||
RegionReplicaUtil.getRegionInfoForReplica(RegionInfoBuilder.FIRST_META_REGIONINFO, replicaId)
|
||||
.getRegionName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify we can connect to <code>hostingServer</code> and that its carrying
|
||||
* <code>regionName</code>.
|
||||
* @param hostingServer Interface to the server hosting <code>regionName</code>
|
||||
* @param address The servername that goes with the <code>metaServer</code> interface. Used
|
||||
* logging.
|
||||
* @param regionName The regionname we are interested in.
|
||||
* @return True if we were able to verify the region located at other side of the interface.
|
||||
*/
|
||||
// TODO: We should be able to get the ServerName from the AdminProtocol
|
||||
// rather than have to pass it in. Its made awkward by the fact that the
|
||||
// HRI is likely a proxy against remote server so the getServerName needs
|
||||
// to be fixed to go to a local method or to a cache before we can do this.
|
||||
private static boolean verifyRegionLocation(final ClusterConnection connection,
|
||||
AdminService.BlockingInterface hostingServer, final ServerName address,
|
||||
final byte[] regionName) {
|
||||
if (hostingServer == null) {
|
||||
LOG.info("Passed hostingServer is null");
|
||||
return false;
|
||||
}
|
||||
Throwable t;
|
||||
HBaseRpcController controller = connection.getRpcControllerFactory().newController();
|
||||
try {
|
||||
// Try and get regioninfo from the hosting server.
|
||||
return ProtobufUtil.getRegionInfo(controller, hostingServer, regionName) != null;
|
||||
} catch (ConnectException e) {
|
||||
t = e;
|
||||
} catch (RetriesExhaustedException e) {
|
||||
t = e;
|
||||
} catch (RemoteException e) {
|
||||
IOException ioe = e.unwrapRemoteException();
|
||||
t = ioe;
|
||||
} catch (IOException e) {
|
||||
Throwable cause = e.getCause();
|
||||
if (cause != null && cause instanceof EOFException) {
|
||||
t = cause;
|
||||
} else if (cause != null && cause.getMessage() != null &&
|
||||
cause.getMessage().contains("Connection reset")) {
|
||||
t = cause;
|
||||
} else {
|
||||
t = e;
|
||||
}
|
||||
}
|
||||
LOG.info("Failed verification of " + Bytes.toStringBinary(regionName) + " at address=" +
|
||||
address + ", exception=" + t.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a connection to the server hosting meta, as reported by ZooKeeper, waiting up to the
|
||||
* specified timeout for availability.
|
||||
* <p>
|
||||
* WARNING: Does not retry. Use an {@link org.apache.hadoop.hbase.client.HTable} instead.
|
||||
* @param connection the connection to use
|
||||
* @param zkw reference to the {@link ZKWatcher} which also contains configuration and operation
|
||||
* @param timeout How long to wait on meta location
|
||||
* @param replicaId the ID of the replica
|
||||
* @return connection to server hosting meta
|
||||
* @throws InterruptedException if waiting for the socket operation fails
|
||||
* @throws IOException if the number of retries for getting the connection is exceeded
|
||||
*/
|
||||
private static AdminService.BlockingInterface getMetaServerConnection(
|
||||
ClusterConnection connection, ZKWatcher zkw, long timeout, int replicaId)
|
||||
throws InterruptedException, IOException {
|
||||
return getCachedConnection(connection,
|
||||
MetaTableLocator.waitMetaRegionLocation(zkw, replicaId, timeout));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param sn ServerName to get a connection against.
|
||||
* @return The AdminProtocol we got when we connected to <code>sn</code> May have come from cache,
|
||||
* may not be good, may have been setup by this invocation, or may be null.
|
||||
* @throws IOException if the number of retries for getting the connection is exceeded
|
||||
*/
|
||||
private static AdminService.BlockingInterface getCachedConnection(ClusterConnection connection,
|
||||
ServerName sn) throws IOException {
|
||||
if (sn == null) {
|
||||
return null;
|
||||
}
|
||||
AdminService.BlockingInterface service = null;
|
||||
try {
|
||||
service = connection.getAdmin(sn);
|
||||
} catch (RetriesExhaustedException e) {
|
||||
if (e.getCause() != null && e.getCause() instanceof ConnectException) {
|
||||
LOG.debug("Catch this; presume it means the cached connection has gone bad.");
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
} catch (SocketTimeoutException e) {
|
||||
LOG.debug("Timed out connecting to " + sn);
|
||||
} catch (NoRouteToHostException e) {
|
||||
LOG.debug("Connecting to " + sn, e);
|
||||
} catch (SocketException e) {
|
||||
LOG.debug("Exception connecting to " + sn);
|
||||
} catch (UnknownHostException e) {
|
||||
LOG.debug("Unknown host exception connecting to " + sn);
|
||||
} catch (FailedServerException e) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Server " + sn + " is in failed server list.");
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
Throwable cause = ioe.getCause();
|
||||
if (ioe instanceof ConnectException) {
|
||||
LOG.debug("Catch. Connect refused.");
|
||||
} else if (cause != null && cause instanceof EOFException) {
|
||||
LOG.debug("Catch. Other end disconnected us.");
|
||||
} else if (cause != null && cause.getMessage() != null &&
|
||||
cause.getMessage().toLowerCase(Locale.ROOT).contains("connection reset")) {
|
||||
LOG.debug("Catch. Connection reset.");
|
||||
} else {
|
||||
throw ioe;
|
||||
}
|
||||
|
||||
}
|
||||
return service;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,229 @@
|
|||
/**
|
||||
* 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.rsgroup;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.ConnectException;
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.hbase.Abortable;
|
||||
import org.apache.hadoop.hbase.HBaseClassTestRule;
|
||||
import org.apache.hadoop.hbase.HBaseTestingUtility;
|
||||
import org.apache.hadoop.hbase.HConstants;
|
||||
import org.apache.hadoop.hbase.HRegionLocation;
|
||||
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.HConnectionTestingUtility;
|
||||
import org.apache.hadoop.hbase.client.RegionInfoBuilder;
|
||||
import org.apache.hadoop.hbase.ipc.HBaseRpcController;
|
||||
import org.apache.hadoop.hbase.ipc.RpcControllerFactory;
|
||||
import org.apache.hadoop.hbase.ipc.ServerNotRunningYetException;
|
||||
import org.apache.hadoop.hbase.master.RegionState;
|
||||
import org.apache.hadoop.hbase.testclassification.MediumTests;
|
||||
import org.apache.hadoop.hbase.testclassification.MiscTests;
|
||||
import org.apache.hadoop.hbase.zookeeper.MetaTableLocator;
|
||||
import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
|
||||
import org.apache.zookeeper.KeeperException;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.mockito.Mockito;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.apache.hbase.thirdparty.com.google.protobuf.RpcController;
|
||||
import org.apache.hbase.thirdparty.com.google.protobuf.ServiceException;
|
||||
|
||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos;
|
||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.GetRegionInfoRequest;
|
||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos;
|
||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.GetRequest;
|
||||
|
||||
@Category({ MiscTests.class, MediumTests.class })
|
||||
public class TestUtility {
|
||||
|
||||
@ClassRule
|
||||
public static final HBaseClassTestRule CLASS_RULE =
|
||||
HBaseClassTestRule.forClass(TestUtility.class);
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(TestUtility.class);
|
||||
|
||||
private static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
|
||||
|
||||
private static final ServerName SN =
|
||||
ServerName.valueOf("example.org", 1234, System.currentTimeMillis());
|
||||
|
||||
private ZKWatcher watcher;
|
||||
|
||||
private Abortable abortable;
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
// Set this down so tests run quicker
|
||||
UTIL.getConfiguration().setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 3);
|
||||
UTIL.startMiniZKCluster();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() throws IOException {
|
||||
UTIL.getZkCluster().shutdown();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void before() throws IOException {
|
||||
this.abortable = new Abortable() {
|
||||
@Override
|
||||
public void abort(String why, Throwable e) {
|
||||
LOG.info(why, e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAborted() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
this.watcher =
|
||||
new ZKWatcher(UTIL.getConfiguration(), this.getClass().getSimpleName(), this.abortable, true);
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() {
|
||||
try {
|
||||
// Clean out meta location or later tests will be confused... they presume
|
||||
// start fresh in zk.
|
||||
MetaTableLocator.deleteMetaLocation(this.watcher);
|
||||
} catch (KeeperException e) {
|
||||
LOG.warn("Unable to delete hbase:meta location", e);
|
||||
}
|
||||
|
||||
this.watcher.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param admin An {@link AdminProtos.AdminService.BlockingInterface} instance; you'll likely want
|
||||
* to pass a mocked HRS; can be null.
|
||||
* @param client A mocked ClientProtocol instance, can be null
|
||||
* @return Mock up a connection that returns a {@link Configuration} when
|
||||
* {@link org.apache.hadoop.hbase.client.ClusterConnection#getConfiguration()} is called,
|
||||
* a 'location' when
|
||||
* {@link org.apache.hadoop.hbase.client.RegionLocator#getRegionLocation(byte[], boolean)}
|
||||
* is called, and that returns the passed
|
||||
* {@link AdminProtos.AdminService.BlockingInterface} instance when
|
||||
* {@link org.apache.hadoop.hbase.client.ClusterConnection#getAdmin(ServerName)} is
|
||||
* called, returns the passed {@link ClientProtos.ClientService.BlockingInterface}
|
||||
* instance when
|
||||
* {@link org.apache.hadoop.hbase.client.ClusterConnection#getClient(ServerName)} is
|
||||
* called.
|
||||
*/
|
||||
private ClusterConnection mockConnection(final AdminProtos.AdminService.BlockingInterface admin,
|
||||
final ClientProtos.ClientService.BlockingInterface client) throws IOException {
|
||||
ClusterConnection connection =
|
||||
HConnectionTestingUtility.getMockedConnection(UTIL.getConfiguration());
|
||||
Mockito.doNothing().when(connection).close();
|
||||
// Make it so we return any old location when asked.
|
||||
final HRegionLocation anyLocation =
|
||||
new HRegionLocation(RegionInfoBuilder.FIRST_META_REGIONINFO, SN);
|
||||
Mockito.when(connection.getRegionLocation((TableName) Mockito.any(), (byte[]) Mockito.any(),
|
||||
Mockito.anyBoolean())).thenReturn(anyLocation);
|
||||
Mockito.when(connection.locateRegion((TableName) Mockito.any(), (byte[]) Mockito.any()))
|
||||
.thenReturn(anyLocation);
|
||||
if (admin != null) {
|
||||
// If a call to getHRegionConnection, return this implementation.
|
||||
Mockito.when(connection.getAdmin(Mockito.any())).thenReturn(admin);
|
||||
}
|
||||
if (client != null) {
|
||||
// If a call to getClient, return this implementation.
|
||||
Mockito.when(connection.getClient(Mockito.any())).thenReturn(client);
|
||||
}
|
||||
return connection;
|
||||
}
|
||||
|
||||
private void testVerifyMetaRegionLocationWithException(Exception ex)
|
||||
throws IOException, InterruptedException, KeeperException, ServiceException {
|
||||
// Mock an ClientProtocol.
|
||||
final ClientProtos.ClientService.BlockingInterface implementation =
|
||||
Mockito.mock(ClientProtos.ClientService.BlockingInterface.class);
|
||||
|
||||
ClusterConnection connection = mockConnection(null, implementation);
|
||||
|
||||
// If a 'get' is called on mocked interface, throw connection refused.
|
||||
Mockito.when(implementation.get((RpcController) Mockito.any(), (GetRequest) Mockito.any()))
|
||||
.thenThrow(new ServiceException(ex));
|
||||
|
||||
long timeout = UTIL.getConfiguration().getLong("hbase.catalog.verification.timeout", 1000);
|
||||
MetaTableLocator.setMetaLocation(this.watcher, SN, RegionState.State.OPENING);
|
||||
assertFalse(Utility.verifyMetaRegionLocation(connection, watcher, timeout));
|
||||
|
||||
MetaTableLocator.setMetaLocation(this.watcher, SN, RegionState.State.OPEN);
|
||||
assertFalse(Utility.verifyMetaRegionLocation(connection, watcher, timeout));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get of meta region fails properly if nothing to connect to.
|
||||
*/
|
||||
@Test
|
||||
public void testVerifyMetaRegionLocationFails()
|
||||
throws IOException, InterruptedException, KeeperException, ServiceException {
|
||||
ClusterConnection connection = Mockito.mock(ClusterConnection.class);
|
||||
ServiceException connectException =
|
||||
new ServiceException(new ConnectException("Connection refused"));
|
||||
final AdminProtos.AdminService.BlockingInterface implementation =
|
||||
Mockito.mock(AdminProtos.AdminService.BlockingInterface.class);
|
||||
Mockito.when(implementation.getRegionInfo((RpcController) Mockito.any(),
|
||||
(GetRegionInfoRequest) Mockito.any())).thenThrow(connectException);
|
||||
Mockito.when(connection.getAdmin(Mockito.any())).thenReturn(implementation);
|
||||
RpcControllerFactory controllerFactory = Mockito.mock(RpcControllerFactory.class);
|
||||
Mockito.when(controllerFactory.newController())
|
||||
.thenReturn(Mockito.mock(HBaseRpcController.class));
|
||||
Mockito.when(connection.getRpcControllerFactory()).thenReturn(controllerFactory);
|
||||
|
||||
ServerName sn = ServerName.valueOf("example.com", 1234, System.currentTimeMillis());
|
||||
MetaTableLocator.setMetaLocation(this.watcher, sn, RegionState.State.OPENING);
|
||||
assertFalse(Utility.verifyMetaRegionLocation(connection, watcher, 100));
|
||||
MetaTableLocator.setMetaLocation(this.watcher, sn, RegionState.State.OPEN);
|
||||
assertFalse(Utility.verifyMetaRegionLocation(connection, watcher, 100));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test we survive a connection refused {@link ConnectException}
|
||||
*/
|
||||
@Test
|
||||
public void testGetMetaServerConnectionFails()
|
||||
throws IOException, InterruptedException, KeeperException, ServiceException {
|
||||
testVerifyMetaRegionLocationWithException(new ConnectException("Connection refused"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that verifyMetaRegionLocation properly handles getting a ServerNotRunningException. See
|
||||
* HBASE-4470. Note this doesn't check the exact exception thrown in the HBASE-4470 as there it is
|
||||
* thrown from getHConnection() and here it is thrown from get() -- but those are both called from
|
||||
* the same function anyway, and this way is less invasive than throwing from getHConnection would
|
||||
* be.
|
||||
*/
|
||||
@Test
|
||||
public void testVerifyMetaRegionServerNotRunning()
|
||||
throws IOException, InterruptedException, KeeperException, ServiceException {
|
||||
testVerifyMetaRegionLocationWithException(new ServerNotRunningYetException("mock"));
|
||||
}
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
/*
|
||||
*
|
||||
/**
|
||||
* 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
|
||||
|
@ -18,16 +17,14 @@
|
|||
*/
|
||||
package org.apache.hadoop.hbase;
|
||||
|
||||
import java.io.IOException;
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.fs.FileSystem;
|
||||
import org.apache.hadoop.hbase.client.ClusterConnection;
|
||||
import org.apache.hadoop.hbase.client.Connection;
|
||||
import org.apache.hadoop.hbase.zookeeper.MetaTableLocator;
|
||||
import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
|
||||
import org.apache.yetus.audience.InterfaceAudience;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Defines a curated set of shared functions implemented by HBase servers (Masters
|
||||
* and RegionServers). For use internally only. Be judicious adding API. Changes cause ripples
|
||||
|
@ -63,14 +60,6 @@ public interface Server extends Abortable, Stoppable {
|
|||
*/
|
||||
ClusterConnection getClusterConnection();
|
||||
|
||||
/**
|
||||
* Returns instance of {@link org.apache.hadoop.hbase.zookeeper.MetaTableLocator}
|
||||
* running inside this server. This MetaServerLocator is started and stopped by server, clients
|
||||
* shouldn't manage it's lifecycle.
|
||||
* @return instance of {@link MetaTableLocator} associated with this server.
|
||||
*/
|
||||
MetaTableLocator getMetaTableLocator();
|
||||
|
||||
/**
|
||||
* @return The unique server name for this server.
|
||||
*/
|
||||
|
|
|
@ -65,8 +65,7 @@ class MasterMetaBootstrap {
|
|||
throw new IllegalStateException("hbase:meta must be initialized first before we can " +
|
||||
"assign out its replicas");
|
||||
}
|
||||
ServerName metaServername =
|
||||
this.master.getMetaTableLocator().getMetaRegionLocation(this.master.getZooKeeper());
|
||||
ServerName metaServername = MetaTableLocator.getMetaRegionLocation(this.master.getZooKeeper());
|
||||
for (int i = 1; i < numReplicas; i++) {
|
||||
// Get current meta state for replica from zk.
|
||||
RegionState metaState = MetaTableLocator.getMetaRegionState(master.getZooKeeper(), i);
|
||||
|
|
|
@ -102,6 +102,7 @@ import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
|
|||
import org.apache.hadoop.hbase.util.ForeignExceptionUtil;
|
||||
import org.apache.hadoop.hbase.util.Pair;
|
||||
import org.apache.hadoop.hbase.wal.AbstractFSWALProvider;
|
||||
import org.apache.hadoop.hbase.zookeeper.MetaTableLocator;
|
||||
import org.apache.yetus.audience.InterfaceAudience;
|
||||
import org.apache.zookeeper.KeeperException;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -1550,9 +1551,9 @@ public class MasterRpcServices extends RSRpcServices
|
|||
}
|
||||
Pair<RegionInfo, ServerName> pair =
|
||||
MetaTableAccessor.getRegion(master.getConnection(), regionName);
|
||||
if (Bytes.equals(RegionInfoBuilder.FIRST_META_REGIONINFO.getRegionName(),regionName)) {
|
||||
if (Bytes.equals(RegionInfoBuilder.FIRST_META_REGIONINFO.getRegionName(), regionName)) {
|
||||
pair = new Pair<>(RegionInfoBuilder.FIRST_META_REGIONINFO,
|
||||
master.getMetaTableLocator().getMetaRegionLocation(master.getZooKeeper()));
|
||||
MetaTableLocator.getMetaRegionLocation(master.getZooKeeper()));
|
||||
}
|
||||
if (pair == null) {
|
||||
throw new UnknownRegionException(Bytes.toString(regionName));
|
||||
|
|
|
@ -22,17 +22,15 @@ import java.io.IOException;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.yetus.audience.InterfaceAudience;
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.hbase.ServerName;
|
||||
import org.apache.hadoop.hbase.tmpl.master.MasterStatusTmpl;
|
||||
import org.apache.hadoop.hbase.util.FSUtils;
|
||||
import org.apache.hadoop.hbase.zookeeper.MetaTableLocator;
|
||||
import org.apache.yetus.audience.InterfaceAudience;
|
||||
|
||||
/**
|
||||
* The servlet responsible for rendering the index page of the
|
||||
|
@ -82,9 +80,7 @@ public class MasterStatusServlet extends HttpServlet {
|
|||
}
|
||||
|
||||
private ServerName getMetaLocationOrNull(HMaster master) {
|
||||
MetaTableLocator metaTableLocator = master.getMetaTableLocator();
|
||||
return metaTableLocator == null ? null :
|
||||
metaTableLocator.getMetaRegionLocation(master.getZooKeeper());
|
||||
return MetaTableLocator.getMetaRegionLocation(master.getZooKeeper());
|
||||
}
|
||||
|
||||
private Map<String, Integer> getFragmentationInfo(
|
||||
|
|
|
@ -25,7 +25,6 @@ import java.util.concurrent.ExecutionException;
|
|||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.hbase.NotAllMetaRegionsOnlineException;
|
||||
import org.apache.hadoop.hbase.client.RegionInfo;
|
||||
|
@ -35,6 +34,7 @@ import org.apache.hadoop.hbase.procedure2.Procedure;
|
|||
import org.apache.hadoop.hbase.procedure2.ProcedureExecutor;
|
||||
import org.apache.hadoop.hbase.quotas.MasterQuotaManager;
|
||||
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
|
||||
import org.apache.hadoop.hbase.zookeeper.MetaTableLocator;
|
||||
import org.apache.yetus.audience.InterfaceAudience;
|
||||
import org.apache.yetus.audience.InterfaceStability;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -225,12 +225,12 @@ public final class ProcedureSyncWait {
|
|||
protected static void waitMetaRegions(final MasterProcedureEnv env) throws IOException {
|
||||
int timeout = env.getMasterConfiguration().getInt("hbase.client.catalog.timeout", 10000);
|
||||
try {
|
||||
if (env.getMasterServices().getMetaTableLocator().waitMetaRegionLocation(
|
||||
env.getMasterServices().getZooKeeper(), timeout) == null) {
|
||||
if (MetaTableLocator.waitMetaRegionLocation(env.getMasterServices().getZooKeeper(),
|
||||
timeout) == null) {
|
||||
throw new NotAllMetaRegionsOnlineException();
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
throw (InterruptedIOException)new InterruptedIOException().initCause(e);
|
||||
throw (InterruptedIOException) new InterruptedIOException().initCause(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,6 @@ import java.io.IOException;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.hadoop.fs.FileSystem;
|
||||
import org.apache.hadoop.fs.Path;
|
||||
import org.apache.hadoop.hbase.MetaTableAccessor;
|
||||
|
@ -42,6 +41,7 @@ import org.apache.yetus.audience.InterfaceAudience;
|
|||
import org.apache.yetus.audience.InterfaceStability;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
|
||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotDescription;
|
||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotRegionManifest;
|
||||
|
@ -159,7 +159,7 @@ public final class MasterSnapshotVerifier {
|
|||
private void verifyRegions(final SnapshotManifest manifest) throws IOException {
|
||||
List<RegionInfo> regions;
|
||||
if (TableName.META_TABLE_NAME.equals(tableName)) {
|
||||
regions = new MetaTableLocator().getMetaRegions(services.getZooKeeper());
|
||||
regions = MetaTableLocator.getMetaRegions(services.getZooKeeper());
|
||||
} else {
|
||||
regions = MetaTableAccessor.getTableRegions(services.getConnection(), tableName);
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@ import java.util.HashSet;
|
|||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CancellationException;
|
||||
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.fs.FileSystem;
|
||||
import org.apache.hadoop.fs.FileUtil;
|
||||
|
@ -60,6 +59,7 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.apache.hbase.thirdparty.com.google.common.base.Preconditions;
|
||||
|
||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotDescription;
|
||||
|
||||
/**
|
||||
|
@ -193,7 +193,7 @@ public abstract class TakeSnapshotHandler extends EventHandler implements Snapsh
|
|||
|
||||
List<Pair<RegionInfo, ServerName>> regionsAndLocations;
|
||||
if (TableName.META_TABLE_NAME.equals(snapshotTable)) {
|
||||
regionsAndLocations = new MetaTableLocator().getMetaRegionsAndLocations(
|
||||
regionsAndLocations = MetaTableLocator.getMetaRegionsAndLocations(
|
||||
server.getZooKeeper());
|
||||
} else {
|
||||
regionsAndLocations = MetaTableAccessor.getTableRegionsAndLocations(
|
||||
|
|
|
@ -24,7 +24,6 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.hbase.HBaseInterfaceAudience;
|
||||
import org.apache.hadoop.hbase.MetaTableAccessor;
|
||||
|
@ -43,14 +42,15 @@ import org.apache.hadoop.hbase.procedure.ProcedureCoordinatorRpcs;
|
|||
import org.apache.hadoop.hbase.procedure.ZKProcedureCoordinator;
|
||||
import org.apache.hadoop.hbase.security.User;
|
||||
import org.apache.hadoop.hbase.security.access.AccessChecker;
|
||||
import org.apache.hadoop.hbase.security.access.Permission;
|
||||
import org.apache.hadoop.hbase.util.Pair;
|
||||
import org.apache.hadoop.hbase.zookeeper.MetaTableLocator;
|
||||
import org.apache.yetus.audience.InterfaceAudience;
|
||||
import org.apache.zookeeper.KeeperException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.apache.hbase.thirdparty.com.google.common.collect.Lists;
|
||||
|
||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.ProcedureDescription;
|
||||
|
||||
@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.CONFIG)
|
||||
|
@ -131,7 +131,7 @@ public class MasterFlushTableProcedureManager extends MasterProcedureManager {
|
|||
List<Pair<RegionInfo, ServerName>> regionsAndLocations;
|
||||
|
||||
if (TableName.META_TABLE_NAME.equals(tableName)) {
|
||||
regionsAndLocations = new MetaTableLocator().getMetaRegionsAndLocations(
|
||||
regionsAndLocations = MetaTableLocator.getMetaRegionsAndLocations(
|
||||
master.getZooKeeper());
|
||||
} else {
|
||||
regionsAndLocations = MetaTableAccessor.getTableRegionsAndLocations(
|
||||
|
|
|
@ -261,14 +261,6 @@ public class HRegionServer extends HasThread implements
|
|||
*/
|
||||
protected ClusterConnection clusterConnection;
|
||||
|
||||
/*
|
||||
* Long-living meta table locator, which is created when the server is started and stopped
|
||||
* when server shuts down. References to this locator shall be used to perform according
|
||||
* operations in EventHandlers. Primary reason for this decision is to make it mockable
|
||||
* for tests.
|
||||
*/
|
||||
protected MetaTableLocator metaTableLocator;
|
||||
|
||||
/**
|
||||
* Go here to get table descriptors.
|
||||
*/
|
||||
|
@ -836,7 +828,6 @@ public class HRegionServer extends HasThread implements
|
|||
protected synchronized void setupClusterConnection() throws IOException {
|
||||
if (clusterConnection == null) {
|
||||
clusterConnection = createClusterConnection();
|
||||
metaTableLocator = new MetaTableLocator();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1104,8 +1095,6 @@ public class HRegionServer extends HasThread implements
|
|||
LOG.info("stopping server " + this.serverName);
|
||||
}
|
||||
|
||||
// so callers waiting for meta without timeout can stop
|
||||
if (this.metaTableLocator != null) this.metaTableLocator.stop();
|
||||
if (this.clusterConnection != null && !clusterConnection.isClosed()) {
|
||||
try {
|
||||
this.clusterConnection.close();
|
||||
|
@ -2173,11 +2162,6 @@ public class HRegionServer extends HasThread implements
|
|||
return this.clusterConnection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetaTableLocator getMetaTableLocator() {
|
||||
return this.metaTableLocator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop(final String msg) {
|
||||
stop(msg, false, RpcServer.getRequestUser().orElse(null));
|
||||
|
|
|
@ -32,7 +32,6 @@ import org.apache.hadoop.hbase.ServerName;
|
|||
import org.apache.hadoop.hbase.client.ClusterConnection;
|
||||
import org.apache.hadoop.hbase.client.Connection;
|
||||
import org.apache.hadoop.hbase.util.FSUtils;
|
||||
import org.apache.hadoop.hbase.zookeeper.MetaTableLocator;
|
||||
import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
|
||||
import org.apache.hadoop.util.Tool;
|
||||
import org.apache.hadoop.util.ToolRunner;
|
||||
|
@ -129,11 +128,6 @@ public class ReplicationSyncUp extends Configured implements Tool {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetaTableLocator getMetaTableLocator() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerName getServerName() {
|
||||
return ServerName.valueOf(hostname, 1234, 1L);
|
||||
|
|
|
@ -134,7 +134,6 @@ import org.apache.hadoop.hbase.util.hbck.TableIntegrityErrorHandlerImpl;
|
|||
import org.apache.hadoop.hbase.wal.WAL;
|
||||
import org.apache.hadoop.hbase.wal.WALFactory;
|
||||
import org.apache.hadoop.hbase.wal.WALSplitter;
|
||||
import org.apache.hadoop.hbase.zookeeper.MetaTableLocator;
|
||||
import org.apache.hadoop.hbase.zookeeper.ZKUtil;
|
||||
import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
|
||||
import org.apache.hadoop.hbase.zookeeper.ZNodePaths;
|
||||
|
@ -144,20 +143,20 @@ import org.apache.hadoop.security.UserGroupInformation;
|
|||
import org.apache.hadoop.util.ReflectionUtils;
|
||||
import org.apache.hadoop.util.Tool;
|
||||
import org.apache.hadoop.util.ToolRunner;
|
||||
import org.apache.hbase.thirdparty.com.google.common.annotations.VisibleForTesting;
|
||||
import org.apache.hbase.thirdparty.com.google.common.collect.Sets;
|
||||
import org.apache.yetus.audience.InterfaceAudience;
|
||||
import org.apache.yetus.audience.InterfaceStability;
|
||||
import org.apache.zookeeper.KeeperException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.apache.hbase.thirdparty.com.google.common.annotations.VisibleForTesting;
|
||||
import org.apache.hbase.thirdparty.com.google.common.base.Joiner;
|
||||
import org.apache.hbase.thirdparty.com.google.common.base.Preconditions;
|
||||
import org.apache.hbase.thirdparty.com.google.common.collect.ImmutableList;
|
||||
import org.apache.hbase.thirdparty.com.google.common.collect.Lists;
|
||||
import org.apache.hbase.thirdparty.com.google.common.collect.Multimap;
|
||||
import org.apache.hbase.thirdparty.com.google.common.collect.Ordering;
|
||||
import org.apache.hbase.thirdparty.com.google.common.collect.Sets;
|
||||
import org.apache.hbase.thirdparty.com.google.common.collect.TreeMultimap;
|
||||
|
||||
import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
|
||||
|
@ -2002,11 +2001,6 @@ public class HBaseFsck extends Configured implements Closeable {
|
|||
});
|
||||
}
|
||||
|
||||
private ServerName getMetaRegionServerName(int replicaId)
|
||||
throws IOException, KeeperException {
|
||||
return new MetaTableLocator().getMetaRegionLocation(zkw, replicaId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Contacts each regionserver and fetches metadata about regions.
|
||||
* @param regionServerList - the list of region servers to connect to
|
||||
|
|
|
@ -77,8 +77,6 @@
|
|||
<%
|
||||
HMaster master = (HMaster)getServletContext().getAttribute(HMaster.MASTER);
|
||||
Configuration conf = master.getConfiguration();
|
||||
|
||||
MetaTableLocator metaTableLocator = new MetaTableLocator();
|
||||
String fqtn = request.getParameter("name");
|
||||
final String escaped_fqtn = StringEscapeUtils.escapeHtml4(fqtn);
|
||||
Table table;
|
||||
|
@ -202,7 +200,7 @@ if ( fqtn != null ) {
|
|||
for (int j = 0; j < numMetaReplicas; j++) {
|
||||
RegionInfo meta = RegionReplicaUtil.getRegionInfoForReplica(
|
||||
RegionInfoBuilder.FIRST_META_REGIONINFO, j);
|
||||
ServerName metaLocation = metaTableLocator.waitMetaRegionLocation(master.getZooKeeper(), j, 1);
|
||||
ServerName metaLocation = MetaTableLocator.waitMetaRegionLocation(master.getZooKeeper(), j, 1);
|
||||
for (int i = 0; i < 1; i++) {
|
||||
String hostAndPort = "";
|
||||
String readReq = "N/A";
|
||||
|
|
|
@ -55,7 +55,6 @@ import org.apache.hadoop.hbase.regionserver.compactions.CompactionRequester;
|
|||
import org.apache.hadoop.hbase.regionserver.throttle.ThroughputController;
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
import org.apache.hadoop.hbase.wal.WAL;
|
||||
import org.apache.hadoop.hbase.zookeeper.MetaTableLocator;
|
||||
import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -161,11 +160,6 @@ public class MockRegionServerServices implements RegionServerServices {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetaTableLocator getMetaTableLocator() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZKWatcher getZooKeeper() {
|
||||
return zkw;
|
||||
|
|
|
@ -247,13 +247,11 @@ public class TestMetaTableAccessor {
|
|||
abstract void metaTask() throws Throwable;
|
||||
}
|
||||
|
||||
@Test public void testGetRegionsFromMetaTable()
|
||||
throws IOException, InterruptedException {
|
||||
List<RegionInfo> regions =
|
||||
new MetaTableLocator().getMetaRegions(UTIL.getZooKeeperWatcher());
|
||||
@Test
|
||||
public void testGetRegionsFromMetaTable() throws IOException, InterruptedException {
|
||||
List<RegionInfo> regions = MetaTableLocator.getMetaRegions(UTIL.getZooKeeperWatcher());
|
||||
assertTrue(regions.size() >= 1);
|
||||
assertTrue(new MetaTableLocator().getMetaRegionsAndLocations(
|
||||
UTIL.getZooKeeperWatcher()).size() >= 1);
|
||||
assertTrue(MetaTableLocator.getMetaRegionsAndLocations(UTIL.getZooKeeperWatcher()).size() >= 1);
|
||||
}
|
||||
|
||||
@Test public void testTableExists() throws IOException {
|
||||
|
|
|
@ -18,18 +18,10 @@
|
|||
package org.apache.hadoop.hbase;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.ConnectException;
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.hbase.client.ClusterConnection;
|
||||
import org.apache.hadoop.hbase.client.HConnectionTestingUtility;
|
||||
import org.apache.hadoop.hbase.ipc.HBaseRpcController;
|
||||
import org.apache.hadoop.hbase.ipc.RpcControllerFactory;
|
||||
import org.apache.hadoop.hbase.ipc.ServerNotRunningYetException;
|
||||
import org.apache.hadoop.hbase.master.RegionState;
|
||||
import org.apache.hadoop.hbase.testclassification.MediumTests;
|
||||
import org.apache.hadoop.hbase.testclassification.MiscTests;
|
||||
|
@ -51,8 +43,6 @@ import org.slf4j.LoggerFactory;
|
|||
import org.apache.hbase.thirdparty.com.google.protobuf.RpcController;
|
||||
import org.apache.hbase.thirdparty.com.google.protobuf.ServiceException;
|
||||
|
||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos;
|
||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.GetRegionInfoRequest;
|
||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos;
|
||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.GetRequest;
|
||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.GetResponse;
|
||||
|
@ -60,31 +50,34 @@ import org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.GetRespons
|
|||
/**
|
||||
* Test {@link org.apache.hadoop.hbase.zookeeper.MetaTableLocator}
|
||||
*/
|
||||
@Category({MiscTests.class, MediumTests.class})
|
||||
@Category({ MiscTests.class, MediumTests.class })
|
||||
public class TestMetaTableLocator {
|
||||
|
||||
@ClassRule
|
||||
public static final HBaseClassTestRule CLASS_RULE =
|
||||
HBaseClassTestRule.forClass(TestMetaTableLocator.class);
|
||||
HBaseClassTestRule.forClass(TestMetaTableLocator.class);
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(TestMetaTableLocator.class);
|
||||
private static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
|
||||
private static final ServerName SN =
|
||||
ServerName.valueOf("example.org", 1234, System.currentTimeMillis());
|
||||
ServerName.valueOf("example.org", 1234, System.currentTimeMillis());
|
||||
private ZKWatcher watcher;
|
||||
private Abortable abortable;
|
||||
|
||||
@BeforeClass public static void beforeClass() throws Exception {
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
// Set this down so tests run quicker
|
||||
UTIL.getConfiguration().setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 3);
|
||||
UTIL.startMiniZKCluster();
|
||||
}
|
||||
|
||||
@AfterClass public static void afterClass() throws IOException {
|
||||
@AfterClass
|
||||
public static void afterClass() throws IOException {
|
||||
UTIL.getZkCluster().shutdown();
|
||||
}
|
||||
|
||||
@Before public void before() throws IOException {
|
||||
@Before
|
||||
public void before() throws IOException {
|
||||
this.abortable = new Abortable() {
|
||||
@Override
|
||||
public void abort(String why, Throwable e) {
|
||||
|
@ -92,19 +85,20 @@ public class TestMetaTableLocator {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isAborted() {
|
||||
public boolean isAborted() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
this.watcher = new ZKWatcher(UTIL.getConfiguration(),
|
||||
this.getClass().getSimpleName(), this.abortable, true);
|
||||
this.watcher =
|
||||
new ZKWatcher(UTIL.getConfiguration(), this.getClass().getSimpleName(), this.abortable, true);
|
||||
}
|
||||
|
||||
@After public void after() {
|
||||
@After
|
||||
public void after() {
|
||||
try {
|
||||
// Clean out meta location or later tests will be confused... they presume
|
||||
// start fresh in zk.
|
||||
new MetaTableLocator().deleteMetaLocation(this.watcher);
|
||||
MetaTableLocator.deleteMetaLocation(this.watcher);
|
||||
} catch (KeeperException e) {
|
||||
LOG.warn("Unable to delete hbase:meta location", e);
|
||||
}
|
||||
|
@ -115,178 +109,47 @@ public class TestMetaTableLocator {
|
|||
/**
|
||||
* Test normal operations
|
||||
*/
|
||||
@Test public void testMetaLookup()
|
||||
throws IOException, InterruptedException, ServiceException, KeeperException {
|
||||
@Test
|
||||
public void testMetaLookup()
|
||||
throws IOException, InterruptedException, ServiceException, KeeperException {
|
||||
final ClientProtos.ClientService.BlockingInterface client =
|
||||
Mockito.mock(ClientProtos.ClientService.BlockingInterface.class);
|
||||
Mockito.mock(ClientProtos.ClientService.BlockingInterface.class);
|
||||
|
||||
Mockito.when(client.get((RpcController)Mockito.any(), (GetRequest)Mockito.any())).
|
||||
thenReturn(GetResponse.newBuilder().build());
|
||||
Mockito.when(client.get((RpcController) Mockito.any(), (GetRequest) Mockito.any()))
|
||||
.thenReturn(GetResponse.newBuilder().build());
|
||||
|
||||
final MetaTableLocator mtl = new MetaTableLocator();
|
||||
assertNull(mtl.getMetaRegionLocation(this.watcher));
|
||||
assertNull(MetaTableLocator.getMetaRegionLocation(this.watcher));
|
||||
for (RegionState.State state : RegionState.State.values()) {
|
||||
if (state.equals(RegionState.State.OPEN))
|
||||
if (state.equals(RegionState.State.OPEN)) {
|
||||
continue;
|
||||
}
|
||||
MetaTableLocator.setMetaLocation(this.watcher, SN, state);
|
||||
assertNull(mtl.getMetaRegionLocation(this.watcher));
|
||||
assertNull(MetaTableLocator.getMetaRegionLocation(this.watcher));
|
||||
assertEquals(state, MetaTableLocator.getMetaRegionState(this.watcher).getState());
|
||||
}
|
||||
MetaTableLocator.setMetaLocation(this.watcher, SN, RegionState.State.OPEN);
|
||||
assertEquals(SN, mtl.getMetaRegionLocation(this.watcher));
|
||||
assertEquals(SN, MetaTableLocator.getMetaRegionLocation(this.watcher));
|
||||
assertEquals(RegionState.State.OPEN,
|
||||
MetaTableLocator.getMetaRegionState(this.watcher).getState());
|
||||
|
||||
mtl.deleteMetaLocation(this.watcher);
|
||||
MetaTableLocator.deleteMetaLocation(this.watcher);
|
||||
assertNull(MetaTableLocator.getMetaRegionState(this.watcher).getServerName());
|
||||
assertEquals(RegionState.State.OFFLINE,
|
||||
MetaTableLocator.getMetaRegionState(this.watcher).getState());
|
||||
assertNull(mtl.getMetaRegionLocation(this.watcher));
|
||||
MetaTableLocator.getMetaRegionState(this.watcher).getState());
|
||||
assertNull(MetaTableLocator.getMetaRegionLocation(this.watcher));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test interruptable while blocking wait on meta.
|
||||
* @throws IOException
|
||||
* @throws ServiceException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
@Test public void testInterruptWaitOnMeta()
|
||||
throws IOException, InterruptedException, ServiceException {
|
||||
final ClientProtos.ClientService.BlockingInterface client =
|
||||
Mockito.mock(ClientProtos.ClientService.BlockingInterface.class);
|
||||
|
||||
Mockito.when(client.get((RpcController)Mockito.any(), (GetRequest)Mockito.any())).
|
||||
thenReturn(GetResponse.newBuilder().build());
|
||||
|
||||
final MetaTableLocator mtl = new MetaTableLocator();
|
||||
ServerName meta = new MetaTableLocator().getMetaRegionLocation(this.watcher);
|
||||
assertNull(meta);
|
||||
Thread t = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
mtl.waitMetaRegionLocation(watcher);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("Interrupted", e);
|
||||
}
|
||||
}
|
||||
};
|
||||
t.start();
|
||||
while (!t.isAlive())
|
||||
Threads.sleep(1);
|
||||
Threads.sleep(1);
|
||||
assertTrue(t.isAlive());
|
||||
mtl.stop();
|
||||
// Join the thread... should exit shortly.
|
||||
t.join();
|
||||
}
|
||||
|
||||
private void testVerifyMetaRegionLocationWithException(Exception ex)
|
||||
throws IOException, InterruptedException, KeeperException, ServiceException {
|
||||
// Mock an ClientProtocol.
|
||||
final ClientProtos.ClientService.BlockingInterface implementation =
|
||||
Mockito.mock(ClientProtos.ClientService.BlockingInterface.class);
|
||||
|
||||
ClusterConnection connection = mockConnection(null, implementation);
|
||||
|
||||
// If a 'get' is called on mocked interface, throw connection refused.
|
||||
Mockito.when(implementation.get((RpcController) Mockito.any(), (GetRequest) Mockito.any())).
|
||||
thenThrow(new ServiceException(ex));
|
||||
|
||||
long timeout = UTIL.getConfiguration().
|
||||
getLong("hbase.catalog.verification.timeout", 1000);
|
||||
MetaTableLocator.setMetaLocation(this.watcher, SN, RegionState.State.OPENING);
|
||||
assertFalse(new MetaTableLocator().verifyMetaRegionLocation(
|
||||
connection, watcher, timeout));
|
||||
|
||||
MetaTableLocator.setMetaLocation(this.watcher, SN, RegionState.State.OPEN);
|
||||
assertFalse(new MetaTableLocator().verifyMetaRegionLocation(
|
||||
connection, watcher, timeout));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test we survive a connection refused {@link ConnectException}
|
||||
* @throws IOException
|
||||
* @throws InterruptedException
|
||||
* @throws KeeperException
|
||||
* @throws ServiceException
|
||||
*/
|
||||
@Test
|
||||
public void testGetMetaServerConnectionFails()
|
||||
throws IOException, InterruptedException, KeeperException, ServiceException {
|
||||
testVerifyMetaRegionLocationWithException(new ConnectException("Connection refused"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that verifyMetaRegionLocation properly handles getting a
|
||||
* ServerNotRunningException. See HBASE-4470.
|
||||
* Note this doesn't check the exact exception thrown in the
|
||||
* HBASE-4470 as there it is thrown from getHConnection() and
|
||||
* here it is thrown from get() -- but those are both called
|
||||
* from the same function anyway, and this way is less invasive than
|
||||
* throwing from getHConnection would be.
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws InterruptedException
|
||||
* @throws KeeperException
|
||||
* @throws ServiceException
|
||||
*/
|
||||
@Test
|
||||
public void testVerifyMetaRegionServerNotRunning()
|
||||
throws IOException, InterruptedException, KeeperException, ServiceException {
|
||||
testVerifyMetaRegionLocationWithException(new ServerNotRunningYetException("mock"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get of meta region fails properly if nothing to connect to.
|
||||
* @throws IOException
|
||||
* @throws InterruptedException
|
||||
* @throws KeeperException
|
||||
* @throws ServiceException
|
||||
*/
|
||||
@Test
|
||||
public void testVerifyMetaRegionLocationFails()
|
||||
throws IOException, InterruptedException, KeeperException, ServiceException {
|
||||
ClusterConnection connection = Mockito.mock(ClusterConnection.class);
|
||||
ServiceException connectException =
|
||||
new ServiceException(new ConnectException("Connection refused"));
|
||||
final AdminProtos.AdminService.BlockingInterface implementation =
|
||||
Mockito.mock(AdminProtos.AdminService.BlockingInterface.class);
|
||||
Mockito.when(implementation.getRegionInfo((RpcController)Mockito.any(),
|
||||
(GetRegionInfoRequest)Mockito.any())).thenThrow(connectException);
|
||||
Mockito.when(connection.getAdmin(Mockito.any())).
|
||||
thenReturn(implementation);
|
||||
RpcControllerFactory controllerFactory = Mockito.mock(RpcControllerFactory.class);
|
||||
Mockito.when(controllerFactory.newController()).thenReturn(
|
||||
Mockito.mock(HBaseRpcController.class));
|
||||
Mockito.when(connection.getRpcControllerFactory()).thenReturn(controllerFactory);
|
||||
|
||||
ServerName sn = ServerName.valueOf("example.com", 1234, System.currentTimeMillis());
|
||||
MetaTableLocator.setMetaLocation(this.watcher,
|
||||
sn,
|
||||
RegionState.State.OPENING);
|
||||
assertFalse(new MetaTableLocator().verifyMetaRegionLocation(connection, watcher, 100));
|
||||
MetaTableLocator.setMetaLocation(this.watcher, sn, RegionState.State.OPEN);
|
||||
assertFalse(new MetaTableLocator().verifyMetaRegionLocation(connection, watcher, 100));
|
||||
}
|
||||
|
||||
@Test (expected = NotAllMetaRegionsOnlineException.class)
|
||||
public void testTimeoutWaitForMeta()
|
||||
throws IOException, InterruptedException {
|
||||
new MetaTableLocator().waitMetaRegionLocation(watcher, 100);
|
||||
@Test(expected = NotAllMetaRegionsOnlineException.class)
|
||||
public void testTimeoutWaitForMeta() throws IOException, InterruptedException {
|
||||
MetaTableLocator.waitMetaRegionLocation(watcher, 100);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test waiting on meat w/ no timeout specified.
|
||||
* @throws IOException
|
||||
* @throws InterruptedException
|
||||
* @throws KeeperException
|
||||
*/
|
||||
@Test public void testNoTimeoutWaitForMeta()
|
||||
throws IOException, InterruptedException, KeeperException {
|
||||
final MetaTableLocator mtl = new MetaTableLocator();
|
||||
ServerName hsa = mtl.getMetaRegionLocation(watcher);
|
||||
@Test
|
||||
public void testNoTimeoutWaitForMeta() throws IOException, InterruptedException, KeeperException {
|
||||
ServerName hsa = MetaTableLocator.getMetaRegionLocation(watcher);
|
||||
assertNull(hsa);
|
||||
|
||||
// Now test waiting on meta location getting set.
|
||||
|
@ -298,54 +161,12 @@ public class TestMetaTableLocator {
|
|||
// Join the thread... should exit shortly.
|
||||
t.join();
|
||||
// Now meta is available.
|
||||
assertTrue(mtl.getMetaRegionLocation(watcher).equals(hsa));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param admin An {@link AdminProtos.AdminService.BlockingInterface} instance; you'll likely
|
||||
* want to pass a mocked HRS; can be null.
|
||||
* @param client A mocked ClientProtocol instance, can be null
|
||||
* @return Mock up a connection that returns a {@link Configuration} when
|
||||
* {@link org.apache.hadoop.hbase.client.ClusterConnection#getConfiguration()} is called, a 'location' when
|
||||
* {@link org.apache.hadoop.hbase.client.RegionLocator#getRegionLocation(byte[], boolean)} is called,
|
||||
* and that returns the passed {@link AdminProtos.AdminService.BlockingInterface} instance when
|
||||
* {@link org.apache.hadoop.hbase.client.ClusterConnection#getAdmin(ServerName)} is called, returns the passed
|
||||
* {@link ClientProtos.ClientService.BlockingInterface} instance when
|
||||
* {@link org.apache.hadoop.hbase.client.ClusterConnection#getClient(ServerName)} is called.
|
||||
* @throws IOException
|
||||
*/
|
||||
private ClusterConnection mockConnection(final AdminProtos.AdminService.BlockingInterface admin,
|
||||
final ClientProtos.ClientService.BlockingInterface client)
|
||||
throws IOException {
|
||||
ClusterConnection connection =
|
||||
HConnectionTestingUtility.getMockedConnection(UTIL.getConfiguration());
|
||||
Mockito.doNothing().when(connection).close();
|
||||
// Make it so we return any old location when asked.
|
||||
final HRegionLocation anyLocation = new HRegionLocation(HRegionInfo.FIRST_META_REGIONINFO, SN);
|
||||
Mockito.when(connection.getRegionLocation((TableName) Mockito.any(),
|
||||
(byte[]) Mockito.any(), Mockito.anyBoolean())).
|
||||
thenReturn(anyLocation);
|
||||
Mockito.when(connection.locateRegion((TableName) Mockito.any(),
|
||||
(byte[]) Mockito.any())).
|
||||
thenReturn(anyLocation);
|
||||
if (admin != null) {
|
||||
// If a call to getHRegionConnection, return this implementation.
|
||||
Mockito.when(connection.getAdmin(Mockito.any())).
|
||||
thenReturn(admin);
|
||||
}
|
||||
if (client != null) {
|
||||
// If a call to getClient, return this implementation.
|
||||
Mockito.when(connection.getClient(Mockito.any())).
|
||||
thenReturn(client);
|
||||
}
|
||||
return connection;
|
||||
assertTrue(MetaTableLocator.getMetaRegionLocation(watcher).equals(hsa));
|
||||
}
|
||||
|
||||
private void startWaitAliveThenWaitItLives(final Thread t, final int ms) {
|
||||
t.start();
|
||||
while(!t.isAlive()) {
|
||||
// Wait
|
||||
}
|
||||
UTIL.waitFor(2000, t::isAlive);
|
||||
// Wait one second.
|
||||
Threads.sleep(ms);
|
||||
assertTrue("Assert " + t.getName() + " still waiting", t.isAlive());
|
||||
|
@ -372,9 +193,13 @@ public class TestMetaTableLocator {
|
|||
|
||||
void doWaiting() throws InterruptedException {
|
||||
try {
|
||||
while (new MetaTableLocator().waitMetaRegionLocation(watcher, 10000) == null);
|
||||
for (;;) {
|
||||
if (MetaTableLocator.waitMetaRegionLocation(watcher, 10000) != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (NotAllMetaRegionsOnlineException e) {
|
||||
//Ignore
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,6 +58,7 @@ import org.apache.hadoop.hbase.util.HBaseFsck.ErrorReporter.ERROR_CODE;
|
|||
import org.apache.hadoop.hbase.util.HBaseFsckRepair;
|
||||
import org.apache.hadoop.hbase.util.hbck.HbckTestingUtil;
|
||||
import org.apache.hadoop.hbase.zookeeper.LoadBalancerTracker;
|
||||
import org.apache.hadoop.hbase.zookeeper.MetaTableLocator;
|
||||
import org.apache.hadoop.hbase.zookeeper.ZKUtil;
|
||||
import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
|
||||
import org.apache.hadoop.hbase.zookeeper.ZNodePaths;
|
||||
|
@ -100,8 +101,7 @@ public class TestMetaWithReplicas {
|
|||
AssignmentManager am = TEST_UTIL.getMiniHBaseCluster().getMaster().getAssignmentManager();
|
||||
Set<ServerName> sns = new HashSet<ServerName>();
|
||||
ServerName hbaseMetaServerName =
|
||||
TEST_UTIL.getMiniHBaseCluster().getMaster().getMetaTableLocator().
|
||||
getMetaRegionLocation(TEST_UTIL.getZooKeeperWatcher());
|
||||
MetaTableLocator.getMetaRegionLocation(TEST_UTIL.getZooKeeperWatcher());
|
||||
LOG.info("HBASE:META DEPLOY: on " + hbaseMetaServerName);
|
||||
sns.add(hbaseMetaServerName);
|
||||
for (int replicaId = 1; replicaId < 3; replicaId++) {
|
||||
|
|
|
@ -54,7 +54,6 @@ import org.apache.hadoop.hbase.replication.ReplicationException;
|
|||
import org.apache.hadoop.hbase.replication.ReplicationPeerConfig;
|
||||
import org.apache.hadoop.hbase.replication.ReplicationPeerDescription;
|
||||
import org.apache.hadoop.hbase.replication.SyncReplicationState;
|
||||
import org.apache.hadoop.hbase.zookeeper.MetaTableLocator;
|
||||
import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
|
||||
|
||||
public class MockNoopMasterServices implements MasterServices {
|
||||
|
@ -160,11 +159,6 @@ public class MockNoopMasterServices implements MasterServices {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetaTableLocator getMetaTableLocator() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClusterConnection getConnection() {
|
||||
return null;
|
||||
|
|
|
@ -68,7 +68,6 @@ import org.apache.hadoop.hbase.regionserver.compactions.CompactionRequester;
|
|||
import org.apache.hadoop.hbase.regionserver.throttle.ThroughputController;
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
import org.apache.hadoop.hbase.wal.WAL;
|
||||
import org.apache.hadoop.hbase.zookeeper.MetaTableLocator;
|
||||
import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
|
||||
|
||||
import org.apache.hbase.thirdparty.com.google.protobuf.RpcController;
|
||||
|
@ -304,11 +303,6 @@ class MockRegionServer implements AdminProtos.AdminService.BlockingInterface,
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetaTableLocator getMetaTableLocator() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerName getServerName() {
|
||||
return this.sn;
|
||||
|
|
|
@ -38,7 +38,6 @@ import org.apache.hadoop.hbase.testclassification.MasterTests;
|
|||
import org.apache.hadoop.hbase.testclassification.MediumTests;
|
||||
import org.apache.hadoop.hbase.zookeeper.ClusterStatusTracker;
|
||||
import org.apache.hadoop.hbase.zookeeper.MasterAddressTracker;
|
||||
import org.apache.hadoop.hbase.zookeeper.MetaTableLocator;
|
||||
import org.apache.hadoop.hbase.zookeeper.ZKListener;
|
||||
import org.apache.hadoop.hbase.zookeeper.ZKUtil;
|
||||
import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
|
||||
|
@ -317,11 +316,6 @@ public class TestActiveMasterManager {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetaTableLocator getMetaTableLocator() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ClusterStatusTracker getClusterStatusTracker() {
|
||||
return clusterStatusTracker;
|
||||
}
|
||||
|
|
|
@ -42,7 +42,6 @@ import org.apache.hadoop.hbase.testclassification.MasterTests;
|
|||
import org.apache.hadoop.hbase.testclassification.MediumTests;
|
||||
import org.apache.hadoop.hbase.util.EnvironmentEdge;
|
||||
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
|
||||
import org.apache.hadoop.hbase.zookeeper.MetaTableLocator;
|
||||
import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
|
@ -232,11 +231,6 @@ public class TestHFileCleaner {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetaTableLocator getMetaTableLocator() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerName getServerName() {
|
||||
return ServerName.valueOf("regionserver,60020,000000");
|
||||
|
|
|
@ -41,7 +41,6 @@ import org.apache.hadoop.hbase.testclassification.MasterTests;
|
|||
import org.apache.hadoop.hbase.testclassification.MediumTests;
|
||||
import org.apache.hadoop.hbase.util.FSUtils;
|
||||
import org.apache.hadoop.hbase.util.HFileArchiveUtil;
|
||||
import org.apache.hadoop.hbase.zookeeper.MetaTableLocator;
|
||||
import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Rule;
|
||||
|
@ -168,11 +167,6 @@ public class TestHFileLinkCleaner {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetaTableLocator getMetaTableLocator() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerName getServerName() {
|
||||
return ServerName.valueOf("regionserver,60020,000000");
|
||||
|
|
|
@ -30,7 +30,6 @@ import java.util.Iterator;
|
|||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.fs.FSDataOutputStream;
|
||||
import org.apache.hadoop.fs.FileStatus;
|
||||
|
@ -55,7 +54,6 @@ import org.apache.hadoop.hbase.replication.ReplicationStorageFactory;
|
|||
import org.apache.hadoop.hbase.replication.master.ReplicationLogCleaner;
|
||||
import org.apache.hadoop.hbase.testclassification.MasterTests;
|
||||
import org.apache.hadoop.hbase.testclassification.MediumTests;
|
||||
import org.apache.hadoop.hbase.zookeeper.MetaTableLocator;
|
||||
import org.apache.hadoop.hbase.zookeeper.RecoverableZooKeeper;
|
||||
import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
|
||||
import org.apache.zookeeper.KeeperException;
|
||||
|
@ -366,11 +364,6 @@ public class TestLogsCleaner {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetaTableLocator getMetaTableLocator() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerName getServerName() {
|
||||
return ServerName.valueOf("regionserver,60020,000000");
|
||||
|
|
|
@ -55,7 +55,6 @@ import org.apache.hadoop.hbase.replication.master.ReplicationHFileCleaner;
|
|||
import org.apache.hadoop.hbase.testclassification.MasterTests;
|
||||
import org.apache.hadoop.hbase.testclassification.SmallTests;
|
||||
import org.apache.hadoop.hbase.util.Pair;
|
||||
import org.apache.hadoop.hbase.zookeeper.MetaTableLocator;
|
||||
import org.apache.hadoop.hbase.zookeeper.RecoverableZooKeeper;
|
||||
import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
|
||||
import org.apache.zookeeper.KeeperException;
|
||||
|
@ -256,11 +255,6 @@ public class TestReplicationHFileCleaner {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetaTableLocator getMetaTableLocator() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerName getServerName() {
|
||||
return ServerName.valueOf("regionserver,60020,000000");
|
||||
|
|
|
@ -49,7 +49,6 @@ import org.apache.hadoop.hbase.regionserver.HeapMemoryManager.TunerContext;
|
|||
import org.apache.hadoop.hbase.regionserver.HeapMemoryManager.TunerResult;
|
||||
import org.apache.hadoop.hbase.testclassification.RegionServerTests;
|
||||
import org.apache.hadoop.hbase.testclassification.SmallTests;
|
||||
import org.apache.hadoop.hbase.zookeeper.MetaTableLocator;
|
||||
import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
|
@ -833,11 +832,6 @@ public class TestHeapMemoryManager {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetaTableLocator getMetaTableLocator() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerName getServerName() {
|
||||
return ServerName.valueOf("server1",4000,12345);
|
||||
|
|
|
@ -111,8 +111,7 @@ public class TestRegionServerNoMaster {
|
|||
HRegionServer hrs = HTU.getHBaseCluster()
|
||||
.getLiveRegionServerThreads().get(0).getRegionServer();
|
||||
ZKWatcher zkw = hrs.getZooKeeper();
|
||||
MetaTableLocator mtl = new MetaTableLocator();
|
||||
ServerName sn = mtl.getMetaRegionLocation(zkw);
|
||||
ServerName sn = MetaTableLocator.getMetaRegionLocation(zkw);
|
||||
if (sn != null && !masterAddr.equals(sn)) {
|
||||
return;
|
||||
}
|
||||
|
@ -120,7 +119,7 @@ public class TestRegionServerNoMaster {
|
|||
ProtobufUtil.openRegion(null, hrs.getRSRpcServices(),
|
||||
hrs.getServerName(), HRegionInfo.FIRST_META_REGIONINFO);
|
||||
while (true) {
|
||||
sn = mtl.getMetaRegionLocation(zkw);
|
||||
sn = MetaTableLocator.getMetaRegionLocation(zkw);
|
||||
if (sn != null && sn.equals(hrs.getServerName())
|
||||
&& hrs.onlineRegions.containsKey(
|
||||
HRegionInfo.FIRST_META_REGIONINFO.getEncodedName())) {
|
||||
|
|
|
@ -49,7 +49,6 @@ import org.apache.hadoop.hbase.executor.ExecutorType;
|
|||
import org.apache.hadoop.hbase.testclassification.MediumTests;
|
||||
import org.apache.hadoop.hbase.testclassification.RegionServerTests;
|
||||
import org.apache.hadoop.hbase.util.CancelableProgressable;
|
||||
import org.apache.hadoop.hbase.zookeeper.MetaTableLocator;
|
||||
import org.apache.hadoop.hbase.zookeeper.ZKSplitLog;
|
||||
import org.apache.hadoop.hbase.zookeeper.ZKUtil;
|
||||
import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
|
||||
|
@ -135,11 +134,6 @@ public class TestSplitLogWorker {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetaTableLocator getMetaTableLocator() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChoreService getChoreService() {
|
||||
return null;
|
||||
|
|
|
@ -53,7 +53,6 @@ import org.apache.hadoop.hbase.wal.WALEdit;
|
|||
import org.apache.hadoop.hbase.wal.WALKey;
|
||||
import org.apache.hadoop.hbase.wal.WALKeyImpl;
|
||||
import org.apache.hadoop.hbase.wal.WALProvider.Writer;
|
||||
import org.apache.hadoop.hbase.zookeeper.MetaTableLocator;
|
||||
import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
|
@ -474,11 +473,6 @@ public class TestWALLockup {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetaTableLocator getMetaTableLocator() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerName getServerName() {
|
||||
return ServerName.valueOf(this.serverName);
|
||||
|
|
|
@ -36,7 +36,6 @@ import org.apache.hadoop.hbase.client.ClusterConnection;
|
|||
import org.apache.hadoop.hbase.client.Connection;
|
||||
import org.apache.hadoop.hbase.testclassification.MediumTests;
|
||||
import org.apache.hadoop.hbase.testclassification.ReplicationTests;
|
||||
import org.apache.hadoop.hbase.zookeeper.MetaTableLocator;
|
||||
import org.apache.hadoop.hbase.zookeeper.ZKClusterId;
|
||||
import org.apache.hadoop.hbase.zookeeper.ZKUtil;
|
||||
import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
|
||||
|
@ -213,11 +212,6 @@ public class TestReplicationTrackerZKImpl {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetaTableLocator getMetaTableLocator() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerName getServerName() {
|
||||
return ServerName.valueOf(this.serverName);
|
||||
|
|
|
@ -88,7 +88,6 @@ import org.apache.hadoop.hbase.wal.WAL;
|
|||
import org.apache.hadoop.hbase.wal.WALEdit;
|
||||
import org.apache.hadoop.hbase.wal.WALFactory;
|
||||
import org.apache.hadoop.hbase.wal.WALKeyImpl;
|
||||
import org.apache.hadoop.hbase.zookeeper.MetaTableLocator;
|
||||
import org.apache.hadoop.hbase.zookeeper.ZKClusterId;
|
||||
import org.apache.hadoop.hbase.zookeeper.ZKUtil;
|
||||
import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
|
||||
|
@ -857,11 +856,6 @@ public abstract class TestReplicationSourceManager {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetaTableLocator getMetaTableLocator() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerName getServerName() {
|
||||
return ServerName.valueOf(hostname, 1234, 1L);
|
||||
|
|
|
@ -70,7 +70,6 @@ import org.apache.hadoop.hbase.util.Sleeper;
|
|||
import org.apache.hadoop.hbase.util.Strings;
|
||||
import org.apache.hadoop.hbase.util.Threads;
|
||||
import org.apache.hadoop.hbase.util.Writables;
|
||||
import org.apache.hadoop.hbase.zookeeper.MetaTableLocator;
|
||||
import org.apache.hadoop.hbase.zookeeper.ZKClusterId;
|
||||
import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
|
||||
import org.apache.hadoop.net.DNS;
|
||||
|
@ -215,11 +214,6 @@ public class TestTokenAuthentication {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetaTableLocator getMetaTableLocator() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZKWatcher getZooKeeper() {
|
||||
return zookeeper;
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
package org.apache.hadoop.hbase.util;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.fs.FileSystem;
|
||||
import org.apache.hadoop.hbase.ChoreService;
|
||||
|
@ -30,7 +29,6 @@ import org.apache.hadoop.hbase.ZooKeeperConnectionException;
|
|||
import org.apache.hadoop.hbase.client.ClusterConnection;
|
||||
import org.apache.hadoop.hbase.client.Connection;
|
||||
import org.apache.hadoop.hbase.log.HBaseMarkers;
|
||||
import org.apache.hadoop.hbase.zookeeper.MetaTableLocator;
|
||||
import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -109,11 +107,6 @@ public class MockServer implements Server {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetaTableLocator getMetaTableLocator() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerName getServerName() {
|
||||
return NAME;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/**
|
||||
* 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
|
||||
|
@ -17,75 +17,55 @@
|
|||
*/
|
||||
package org.apache.hadoop.hbase.zookeeper;
|
||||
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.net.ConnectException;
|
||||
import java.net.NoRouteToHostException;
|
||||
import java.net.SocketException;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.hbase.HConstants;
|
||||
import org.apache.hadoop.hbase.NotAllMetaRegionsOnlineException;
|
||||
import org.apache.hadoop.hbase.ServerName;
|
||||
import org.apache.hadoop.hbase.client.ClusterConnection;
|
||||
import org.apache.hadoop.hbase.client.RegionInfo;
|
||||
import org.apache.hadoop.hbase.client.RegionInfoBuilder;
|
||||
import org.apache.hadoop.hbase.client.RegionReplicaUtil;
|
||||
import org.apache.hadoop.hbase.client.RetriesExhaustedException;
|
||||
import org.apache.hadoop.hbase.exceptions.DeserializationException;
|
||||
import org.apache.hadoop.hbase.ipc.FailedServerException;
|
||||
import org.apache.hadoop.hbase.ipc.HBaseRpcController;
|
||||
import org.apache.hadoop.hbase.ipc.ServerNotRunningYetException;
|
||||
import org.apache.hadoop.hbase.master.RegionState;
|
||||
import org.apache.hadoop.hbase.regionserver.RegionServerStoppedException;
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
import org.apache.hadoop.hbase.util.Pair;
|
||||
import org.apache.hadoop.ipc.RemoteException;
|
||||
import org.apache.yetus.audience.InterfaceAudience;
|
||||
import org.apache.zookeeper.KeeperException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.apache.hbase.thirdparty.com.google.protobuf.InvalidProtocolBufferException;
|
||||
|
||||
import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
|
||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos;
|
||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.AdminService;
|
||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos;
|
||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.ZooKeeperProtos;
|
||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.ZooKeeperProtos.MetaRegionServer;
|
||||
|
||||
/**
|
||||
* Utility class to perform operation (get/wait for/verify/set/delete) on znode in ZooKeeper
|
||||
* which keeps hbase:meta region server location.
|
||||
*
|
||||
* Stateless class with a bunch of static methods. Doesn't manage resources passed in
|
||||
* (e.g. Connection, ZKWatcher etc).
|
||||
*
|
||||
* Meta region location is set by <code>RegionServerServices</code>.
|
||||
* This class doesn't use ZK watchers, rather accesses ZK directly.
|
||||
*
|
||||
* This class it stateless. The only reason it's not made a non-instantiable util class
|
||||
* with a collection of static methods is that it'd be rather hard to mock properly in tests.
|
||||
*
|
||||
* Utility class to perform operation (get/wait for/verify/set/delete) on znode in ZooKeeper which
|
||||
* keeps hbase:meta region server location.
|
||||
* <p/>
|
||||
* Stateless class with a bunch of static methods. Doesn't manage resources passed in (e.g.
|
||||
* Connection, ZKWatcher etc).
|
||||
* <p/>
|
||||
* Meta region location is set by <code>RegionServerServices</code>. This class doesn't use ZK
|
||||
* watchers, rather accesses ZK directly.
|
||||
* <p/>
|
||||
* TODO: rewrite using RPC calls to master to find out about hbase:meta.
|
||||
*/
|
||||
@InterfaceAudience.Private
|
||||
public class MetaTableLocator {
|
||||
public final class MetaTableLocator {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(MetaTableLocator.class);
|
||||
|
||||
// only needed to allow non-timeout infinite waits to stop when cluster shuts down
|
||||
private volatile boolean stopped = false;
|
||||
private MetaTableLocator() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the meta region location is available.
|
||||
* @return true if meta region location is available, false if not
|
||||
*/
|
||||
public boolean isLocationAvailable(ZKWatcher zkw) {
|
||||
public static boolean isLocationAvailable(ZKWatcher zkw) {
|
||||
return getMetaRegionLocation(zkw) != null;
|
||||
}
|
||||
|
||||
|
@ -93,7 +73,7 @@ public class MetaTableLocator {
|
|||
* @param zkw ZooKeeper watcher to be used
|
||||
* @return meta table regions and their locations.
|
||||
*/
|
||||
public List<Pair<RegionInfo, ServerName>> getMetaRegionsAndLocations(ZKWatcher zkw) {
|
||||
public static List<Pair<RegionInfo, ServerName>> getMetaRegionsAndLocations(ZKWatcher zkw) {
|
||||
return getMetaRegionsAndLocations(zkw, RegionInfo.DEFAULT_REPLICA_ID);
|
||||
}
|
||||
|
||||
|
@ -104,7 +84,7 @@ public class MetaTableLocator {
|
|||
* @param replicaId the ID of the replica
|
||||
* @return meta table regions and their locations.
|
||||
*/
|
||||
public List<Pair<RegionInfo, ServerName>> getMetaRegionsAndLocations(ZKWatcher zkw,
|
||||
public static List<Pair<RegionInfo, ServerName>> getMetaRegionsAndLocations(ZKWatcher zkw,
|
||||
int replicaId) {
|
||||
ServerName serverName = getMetaRegionLocation(zkw, replicaId);
|
||||
List<Pair<RegionInfo, ServerName>> list = new ArrayList<>(1);
|
||||
|
@ -119,30 +99,30 @@ public class MetaTableLocator {
|
|||
* @param zkw ZooKeeper watcher to be used
|
||||
* @return List of meta regions
|
||||
*/
|
||||
public List<RegionInfo> getMetaRegions(ZKWatcher zkw) {
|
||||
public static List<RegionInfo> getMetaRegions(ZKWatcher zkw) {
|
||||
return getMetaRegions(zkw, RegionInfo.DEFAULT_REPLICA_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the meta regions for the given path and replica ID.
|
||||
*
|
||||
* @param zkw reference to the {@link ZKWatcher} which also contains configuration and operation
|
||||
* @param replicaId the ID of the replica
|
||||
* @return List of meta regions
|
||||
*/
|
||||
public List<RegionInfo> getMetaRegions(ZKWatcher zkw, int replicaId) {
|
||||
public static List<RegionInfo> getMetaRegions(ZKWatcher zkw, int replicaId) {
|
||||
List<Pair<RegionInfo, ServerName>> result;
|
||||
result = getMetaRegionsAndLocations(zkw, replicaId);
|
||||
return getListOfRegionInfos(result);
|
||||
}
|
||||
|
||||
private List<RegionInfo> getListOfRegionInfos(final List<Pair<RegionInfo, ServerName>> pairs) {
|
||||
private static List<RegionInfo> getListOfRegionInfos(
|
||||
final List<Pair<RegionInfo, ServerName>> pairs) {
|
||||
if (pairs == null || pairs.isEmpty()) {
|
||||
return Collections.EMPTY_LIST;
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
List<RegionInfo> result = new ArrayList<>(pairs.size());
|
||||
for (Pair<RegionInfo, ServerName> pair: pairs) {
|
||||
for (Pair<RegionInfo, ServerName> pair : pairs) {
|
||||
result.add(pair.getFirst());
|
||||
}
|
||||
return result;
|
||||
|
@ -153,7 +133,7 @@ public class MetaTableLocator {
|
|||
* @param zkw zookeeper connection to use
|
||||
* @return server name or null if we failed to get the data.
|
||||
*/
|
||||
public ServerName getMetaRegionLocation(final ZKWatcher zkw) {
|
||||
public static ServerName getMetaRegionLocation(final ZKWatcher zkw) {
|
||||
try {
|
||||
RegionState state = getMetaRegionState(zkw);
|
||||
return state.isOpened() ? state.getServerName() : null;
|
||||
|
@ -168,7 +148,7 @@ public class MetaTableLocator {
|
|||
* @param replicaId the ID of the replica
|
||||
* @return server name
|
||||
*/
|
||||
public ServerName getMetaRegionLocation(final ZKWatcher zkw, int replicaId) {
|
||||
public static ServerName getMetaRegionLocation(final ZKWatcher zkw, int replicaId) {
|
||||
try {
|
||||
RegionState state = getMetaRegionState(zkw, replicaId);
|
||||
return state.isOpened() ? state.getServerName() : null;
|
||||
|
@ -178,42 +158,39 @@ public class MetaTableLocator {
|
|||
}
|
||||
|
||||
/**
|
||||
* Gets the meta region location, if available, and waits for up to the
|
||||
* specified timeout if not immediately available.
|
||||
* Given the zookeeper notification could be delayed, we will try to
|
||||
* get the latest data.
|
||||
*
|
||||
* Gets the meta region location, if available, and waits for up to the specified timeout if not
|
||||
* immediately available. Given the zookeeper notification could be delayed, we will try to get
|
||||
* the latest data.
|
||||
* @param zkw reference to the {@link ZKWatcher} which also contains configuration and operation
|
||||
* @param timeout maximum time to wait, in millis
|
||||
* @return server name for server hosting meta region formatted as per
|
||||
* {@link ServerName}, or null if none available
|
||||
* @return server name for server hosting meta region formatted as per {@link ServerName}, or null
|
||||
* if none available
|
||||
* @throws InterruptedException if interrupted while waiting
|
||||
* @throws NotAllMetaRegionsOnlineException if a meta or root region is not online
|
||||
*/
|
||||
public ServerName waitMetaRegionLocation(ZKWatcher zkw, long timeout)
|
||||
throws InterruptedException, NotAllMetaRegionsOnlineException {
|
||||
public static ServerName waitMetaRegionLocation(ZKWatcher zkw, long timeout)
|
||||
throws InterruptedException, NotAllMetaRegionsOnlineException {
|
||||
return waitMetaRegionLocation(zkw, RegionInfo.DEFAULT_REPLICA_ID, timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the meta region location, if available, and waits for up to the specified timeout if not
|
||||
* immediately available. Given the zookeeper notification could be delayed, we will try to
|
||||
* get the latest data.
|
||||
*
|
||||
* immediately available. Given the zookeeper notification could be delayed, we will try to get
|
||||
* the latest data.
|
||||
* @param zkw reference to the {@link ZKWatcher} which also contains configuration and operation
|
||||
* @param replicaId the ID of the replica
|
||||
* @param timeout maximum time to wait, in millis
|
||||
* @return server name for server hosting meta region formatted as per
|
||||
* {@link ServerName}, or null if none available
|
||||
* @return server name for server hosting meta region formatted as per {@link ServerName}, or null
|
||||
* if none available
|
||||
* @throws InterruptedException if waiting for the socket operation fails
|
||||
* @throws NotAllMetaRegionsOnlineException if a meta or root region is not online
|
||||
*/
|
||||
public ServerName waitMetaRegionLocation(ZKWatcher zkw, int replicaId, long timeout)
|
||||
throws InterruptedException, NotAllMetaRegionsOnlineException {
|
||||
public static ServerName waitMetaRegionLocation(ZKWatcher zkw, int replicaId, long timeout)
|
||||
throws InterruptedException, NotAllMetaRegionsOnlineException {
|
||||
try {
|
||||
if (ZKUtil.checkExists(zkw, zkw.getZNodePaths().baseZNode) == -1) {
|
||||
String errorMsg = "Check the value configured in 'zookeeper.znode.parent'. "
|
||||
+ "There could be a mismatch with the one configured in the master.";
|
||||
String errorMsg = "Check the value configured in 'zookeeper.znode.parent'. " +
|
||||
"There could be a mismatch with the one configured in the master.";
|
||||
LOG.error(errorMsg);
|
||||
throw new IllegalArgumentException(errorMsg);
|
||||
}
|
||||
|
@ -229,198 +206,6 @@ public class MetaTableLocator {
|
|||
return sn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits indefinitely for availability of <code>hbase:meta</code>. Used during
|
||||
* cluster startup. Does not verify meta, just that something has been
|
||||
* set up in zk.
|
||||
* @see #waitMetaRegionLocation(ZKWatcher, long)
|
||||
* @throws InterruptedException if interrupted while waiting
|
||||
*/
|
||||
public void waitMetaRegionLocation(ZKWatcher zkw) throws InterruptedException {
|
||||
long startTime = System.currentTimeMillis();
|
||||
while (!stopped) {
|
||||
try {
|
||||
if (waitMetaRegionLocation(zkw, 100) != null) {
|
||||
break;
|
||||
}
|
||||
|
||||
long sleepTime = System.currentTimeMillis() - startTime;
|
||||
// +1 in case sleepTime=0
|
||||
if ((sleepTime + 1) % 10000 == 0) {
|
||||
LOG.warn("Have been waiting for meta to be assigned for " + sleepTime + "ms");
|
||||
}
|
||||
} catch (NotAllMetaRegionsOnlineException e) {
|
||||
if (LOG.isTraceEnabled()) {
|
||||
LOG.trace("hbase:meta still not available, sleeping and retrying." +
|
||||
" Reason: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify <code>hbase:meta</code> is deployed and accessible.
|
||||
*
|
||||
* @param hConnection the connection to use
|
||||
* @param zkw reference to the {@link ZKWatcher} which also contains configuration and operation
|
||||
* @param timeout How long to wait on zk for meta address (passed through to
|
||||
* the internal call to {@link #getMetaServerConnection}.
|
||||
* @return True if the <code>hbase:meta</code> location is healthy.
|
||||
* @throws IOException if the number of retries for getting the connection is exceeded
|
||||
* @throws InterruptedException if waiting for the socket operation fails
|
||||
*/
|
||||
public boolean verifyMetaRegionLocation(ClusterConnection hConnection, ZKWatcher zkw,
|
||||
final long timeout) throws InterruptedException, IOException {
|
||||
return verifyMetaRegionLocation(hConnection, zkw, timeout, RegionInfo.DEFAULT_REPLICA_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify <code>hbase:meta</code> is deployed and accessible.
|
||||
*
|
||||
* @param connection the connection to use
|
||||
* @param zkw reference to the {@link ZKWatcher} which also contains configuration and operation
|
||||
* @param timeout How long to wait on zk for meta address (passed through to
|
||||
* @param replicaId the ID of the replica
|
||||
* @return True if the <code>hbase:meta</code> location is healthy.
|
||||
* @throws InterruptedException if waiting for the socket operation fails
|
||||
* @throws IOException if the number of retries for getting the connection is exceeded
|
||||
*/
|
||||
public boolean verifyMetaRegionLocation(ClusterConnection connection, ZKWatcher zkw,
|
||||
final long timeout, int replicaId) throws InterruptedException, IOException {
|
||||
AdminProtos.AdminService.BlockingInterface service = null;
|
||||
try {
|
||||
service = getMetaServerConnection(connection, zkw, timeout, replicaId);
|
||||
} catch (NotAllMetaRegionsOnlineException e) {
|
||||
// Pass
|
||||
} catch (ServerNotRunningYetException e) {
|
||||
// Pass -- remote server is not up so can't be carrying root
|
||||
} catch (UnknownHostException e) {
|
||||
// Pass -- server name doesn't resolve so it can't be assigned anything.
|
||||
} catch (RegionServerStoppedException e) {
|
||||
// Pass -- server name sends us to a server that is dying or already dead.
|
||||
}
|
||||
return (service != null) && verifyRegionLocation(connection, service,
|
||||
getMetaRegionLocation(zkw, replicaId), RegionReplicaUtil.getRegionInfoForReplica(
|
||||
RegionInfoBuilder.FIRST_META_REGIONINFO, replicaId).getRegionName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify we can connect to <code>hostingServer</code> and that its carrying
|
||||
* <code>regionName</code>.
|
||||
* @param hostingServer Interface to the server hosting <code>regionName</code>
|
||||
* @param address The servername that goes with the <code>metaServer</code> interface.
|
||||
* Used logging.
|
||||
* @param regionName The regionname we are interested in.
|
||||
* @return True if we were able to verify the region located at other side of the interface.
|
||||
*/
|
||||
// TODO: We should be able to get the ServerName from the AdminProtocol
|
||||
// rather than have to pass it in. Its made awkward by the fact that the
|
||||
// HRI is likely a proxy against remote server so the getServerName needs
|
||||
// to be fixed to go to a local method or to a cache before we can do this.
|
||||
private boolean verifyRegionLocation(final ClusterConnection connection,
|
||||
AdminService.BlockingInterface hostingServer, final ServerName address,
|
||||
final byte [] regionName) {
|
||||
if (hostingServer == null) {
|
||||
LOG.info("Passed hostingServer is null");
|
||||
return false;
|
||||
}
|
||||
Throwable t;
|
||||
HBaseRpcController controller = connection.getRpcControllerFactory().newController();
|
||||
try {
|
||||
// Try and get regioninfo from the hosting server.
|
||||
return ProtobufUtil.getRegionInfo(controller, hostingServer, regionName) != null;
|
||||
} catch (ConnectException e) {
|
||||
t = e;
|
||||
} catch (RetriesExhaustedException e) {
|
||||
t = e;
|
||||
} catch (RemoteException e) {
|
||||
IOException ioe = e.unwrapRemoteException();
|
||||
t = ioe;
|
||||
} catch (IOException e) {
|
||||
Throwable cause = e.getCause();
|
||||
if (cause != null && cause instanceof EOFException) {
|
||||
t = cause;
|
||||
} else if (cause != null && cause.getMessage() != null
|
||||
&& cause.getMessage().contains("Connection reset")) {
|
||||
t = cause;
|
||||
} else {
|
||||
t = e;
|
||||
}
|
||||
}
|
||||
LOG.info("Failed verification of " + Bytes.toStringBinary(regionName) +
|
||||
" at address=" + address + ", exception=" + t.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a connection to the server hosting meta, as reported by ZooKeeper, waiting up to the
|
||||
* specified timeout for availability.
|
||||
*
|
||||
* <p>WARNING: Does not retry. Use an {@link org.apache.hadoop.hbase.client.HTable} instead.
|
||||
*
|
||||
* @param connection the connection to use
|
||||
* @param zkw reference to the {@link ZKWatcher} which also contains configuration and operation
|
||||
* @param timeout How long to wait on meta location
|
||||
* @param replicaId the ID of the replica
|
||||
* @return connection to server hosting meta
|
||||
* @throws InterruptedException if waiting for the socket operation fails
|
||||
* @throws IOException if the number of retries for getting the connection is exceeded
|
||||
*/
|
||||
private AdminService.BlockingInterface getMetaServerConnection(ClusterConnection connection,
|
||||
ZKWatcher zkw, long timeout, int replicaId) throws InterruptedException, IOException {
|
||||
return getCachedConnection(connection, waitMetaRegionLocation(zkw, replicaId, timeout));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param sn ServerName to get a connection against.
|
||||
* @return The AdminProtocol we got when we connected to <code>sn</code>
|
||||
* May have come from cache, may not be good, may have been setup by this invocation, or
|
||||
* may be null.
|
||||
* @throws IOException if the number of retries for getting the connection is exceeded
|
||||
*/
|
||||
private static AdminService.BlockingInterface getCachedConnection(ClusterConnection connection,
|
||||
ServerName sn) throws IOException {
|
||||
if (sn == null) {
|
||||
return null;
|
||||
}
|
||||
AdminService.BlockingInterface service = null;
|
||||
try {
|
||||
service = connection.getAdmin(sn);
|
||||
} catch (RetriesExhaustedException e) {
|
||||
if (e.getCause() != null && e.getCause() instanceof ConnectException) {
|
||||
LOG.debug("Catch this; presume it means the cached connection has gone bad.");
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
} catch (SocketTimeoutException e) {
|
||||
LOG.debug("Timed out connecting to " + sn);
|
||||
} catch (NoRouteToHostException e) {
|
||||
LOG.debug("Connecting to " + sn, e);
|
||||
} catch (SocketException e) {
|
||||
LOG.debug("Exception connecting to " + sn);
|
||||
} catch (UnknownHostException e) {
|
||||
LOG.debug("Unknown host exception connecting to " + sn);
|
||||
} catch (FailedServerException e) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Server " + sn + " is in failed server list.");
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
Throwable cause = ioe.getCause();
|
||||
if (ioe instanceof ConnectException) {
|
||||
LOG.debug("Catch. Connect refused.");
|
||||
} else if (cause != null && cause instanceof EOFException) {
|
||||
LOG.debug("Catch. Other end disconnected us.");
|
||||
} else if (cause != null && cause.getMessage() != null &&
|
||||
cause.getMessage().toLowerCase(Locale.ROOT).contains("connection reset")) {
|
||||
LOG.debug("Catch. Connection reset.");
|
||||
} else {
|
||||
throw ioe;
|
||||
}
|
||||
|
||||
}
|
||||
return service;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the location of <code>hbase:meta</code> in ZooKeeper to the
|
||||
* specified server address.
|
||||
|
@ -498,7 +283,7 @@ public class MetaTableLocator {
|
|||
try {
|
||||
int prefixLen = ProtobufUtil.lengthOfPBMagic();
|
||||
ZooKeeperProtos.MetaRegionServer rl =
|
||||
ZooKeeperProtos.MetaRegionServer.PARSER.parseFrom(data, prefixLen,
|
||||
ZooKeeperProtos.MetaRegionServer.parser().parseFrom(data, prefixLen,
|
||||
data.length - prefixLen);
|
||||
if (rl.hasState()) {
|
||||
state = RegionState.State.convert(rl.getState());
|
||||
|
@ -532,12 +317,12 @@ public class MetaTableLocator {
|
|||
* @param zookeeper zookeeper reference
|
||||
* @throws KeeperException unexpected zookeeper exception
|
||||
*/
|
||||
public void deleteMetaLocation(ZKWatcher zookeeper)
|
||||
public static void deleteMetaLocation(ZKWatcher zookeeper)
|
||||
throws KeeperException {
|
||||
deleteMetaLocation(zookeeper, RegionInfo.DEFAULT_REPLICA_ID);
|
||||
}
|
||||
|
||||
public void deleteMetaLocation(ZKWatcher zookeeper, int replicaId)
|
||||
public static void deleteMetaLocation(ZKWatcher zookeeper, int replicaId)
|
||||
throws KeeperException {
|
||||
if (replicaId == RegionInfo.DEFAULT_REPLICA_ID) {
|
||||
LOG.info("Deleting hbase:meta region location in ZooKeeper");
|
||||
|
@ -561,7 +346,7 @@ public class MetaTableLocator {
|
|||
* @return ServerName or null if we timed out.
|
||||
* @throws InterruptedException if waiting for the socket operation fails
|
||||
*/
|
||||
public List<ServerName> blockUntilAvailable(final ZKWatcher zkw, final long timeout,
|
||||
public static List<ServerName> blockUntilAvailable(final ZKWatcher zkw, final long timeout,
|
||||
Configuration conf) throws InterruptedException {
|
||||
int numReplicasConfigured = 1;
|
||||
|
||||
|
@ -596,22 +381,21 @@ public class MetaTableLocator {
|
|||
* @return ServerName or null if we timed out.
|
||||
* @throws InterruptedException if waiting for the socket operation fails
|
||||
*/
|
||||
public ServerName blockUntilAvailable(final ZKWatcher zkw, final long timeout)
|
||||
throws InterruptedException {
|
||||
public static ServerName blockUntilAvailable(final ZKWatcher zkw, final long timeout)
|
||||
throws InterruptedException {
|
||||
return blockUntilAvailable(zkw, RegionInfo.DEFAULT_REPLICA_ID, timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait until the meta region is available and is not in transition.
|
||||
*
|
||||
* @param zkw reference to the {@link ZKWatcher} which also contains configuration and constants
|
||||
* @param replicaId the ID of the replica
|
||||
* @param timeout maximum time to wait in millis
|
||||
* @return ServerName or null if we timed out.
|
||||
* @throws InterruptedException if waiting for the socket operation fails
|
||||
*/
|
||||
public ServerName blockUntilAvailable(final ZKWatcher zkw, int replicaId, final long timeout)
|
||||
throws InterruptedException {
|
||||
public static ServerName blockUntilAvailable(final ZKWatcher zkw, int replicaId,
|
||||
final long timeout) throws InterruptedException {
|
||||
if (timeout < 0) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
@ -624,23 +408,12 @@ public class MetaTableLocator {
|
|||
ServerName sn = null;
|
||||
while (true) {
|
||||
sn = getMetaRegionLocation(zkw, replicaId);
|
||||
if (sn != null || (System.currentTimeMillis() - startTime)
|
||||
> timeout - HConstants.SOCKET_RETRY_WAIT_MS) {
|
||||
if (sn != null ||
|
||||
(System.currentTimeMillis() - startTime) > timeout - HConstants.SOCKET_RETRY_WAIT_MS) {
|
||||
break;
|
||||
}
|
||||
Thread.sleep(HConstants.SOCKET_RETRY_WAIT_MS);
|
||||
}
|
||||
return sn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop working.
|
||||
* Interrupts any ongoing waits.
|
||||
*/
|
||||
public void stop() {
|
||||
if (!stopped) {
|
||||
LOG.debug("Stopping MetaTableLocator");
|
||||
stopped = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,10 +34,8 @@ import java.util.HashMap;
|
|||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.security.auth.login.AppConfigurationEntry;
|
||||
import javax.security.auth.login.AppConfigurationEntry.LoginModuleControlFlag;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.hbase.AuthUtil;
|
||||
|
@ -75,6 +73,7 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.apache.hbase.thirdparty.com.google.protobuf.InvalidProtocolBufferException;
|
||||
|
||||
import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
|
||||
import org.apache.hadoop.hbase.shaded.protobuf.generated.ReplicationProtos;
|
||||
|
||||
|
@ -1748,13 +1747,13 @@ public final class ZKUtil {
|
|||
sb.append("\n ").append(child);
|
||||
}
|
||||
sb.append("\nRegion server holding hbase:meta: "
|
||||
+ new MetaTableLocator().getMetaRegionLocation(zkw));
|
||||
+ MetaTableLocator.getMetaRegionLocation(zkw));
|
||||
Configuration conf = HBaseConfiguration.create();
|
||||
int numMetaReplicas = conf.getInt(HConstants.META_REPLICAS_NUM,
|
||||
HConstants.DEFAULT_META_REPLICA_NUM);
|
||||
for (int i = 1; i < numMetaReplicas; i++) {
|
||||
sb.append("\nRegion server holding hbase:meta, replicaId " + i + " "
|
||||
+ new MetaTableLocator().getMetaRegionLocation(zkw, i));
|
||||
+ MetaTableLocator.getMetaRegionLocation(zkw, i));
|
||||
}
|
||||
sb.append("\nRegion servers:");
|
||||
for (String child : listChildrenNoWatch(zkw, zkw.getZNodePaths().rsZNode)) {
|
||||
|
|
Loading…
Reference in New Issue