Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ public interface Connection extends Abortable, Closeable {
*/
Admin getAdmin() throws IOException;

/**
* @return the cluster ID unique to this HBase cluster.
*/
String getClusterId() throws IOException;

@Override
public void close() throws IOException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ public boolean isTableAvailable(byte[] tableName, byte[][] splitKeys)
return wrappedConnection.isTableAvailable(tableName, splitKeys);
}

@Override
public TableState getTableState(TableName tableName) throws IOException {
return wrappedConnection.getTableState(tableName);
}

@Override
public HTableDescriptor[] listTables() throws IOException {
return wrappedConnection.listTables();
Expand Down Expand Up @@ -496,4 +501,9 @@ public RpcRetryingCallerFactory getRpcRetryingCallerFactory() {
public RpcControllerFactory getRpcControllerFactory() {
return wrappedConnection.getRpcControllerFactory();
}

@Override
public String getClusterId() throws IOException {
return wrappedConnection.getClusterId();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.ClientService;
import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.CoprocessorServiceRequest;
import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.CoprocessorServiceResponse;
import org.apache.hadoop.hbase.protobuf.generated.*;
import org.apache.hadoop.hbase.protobuf.generated.MasterProtos;
import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.AddColumnRequest;
import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.AddColumnResponse;
import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.AssignRegionRequest;
Expand Down Expand Up @@ -123,6 +123,8 @@
import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.GetTableDescriptorsResponse;
import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.GetTableNamesRequest;
import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.GetTableNamesResponse;
import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.GetTableStateRequest;
import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.GetTableStateResponse;
import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.GetProcedureResultRequest;
import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.GetProcedureResultResponse;
import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.IsBalancerEnabledRequest;
Expand Down Expand Up @@ -632,7 +634,7 @@ static class HConnectionImplementation implements ClusterConnection, Closeable {
/**
* Cluster registry of basic info such as clusterid and meta region location.
*/
Registry registry;
ConnectionRegistry registry;

private final ClientBackoffPolicy backoffPolicy;

Expand Down Expand Up @@ -821,6 +823,11 @@ public Admin getAdmin() throws IOException {
return new HBaseAdmin(this);
}

@Override
public String getClusterId() throws IOException {
return registry.getClusterId();
}

@Override
public MetricsConnection getConnectionMetrics() {
return this.metrics;
Expand Down Expand Up @@ -917,8 +924,8 @@ private void shutdownBatchPool(ExecutorService pool) {
* @return The cluster registry implementation to use.
* @throws IOException
*/
private Registry setupRegistry() throws IOException {
return RegistryFactory.getRegistry(this);
private ConnectionRegistry setupRegistry() throws IOException {
return ConnectionRegistryFactory.getRegistry(this);
}

/**
Expand All @@ -939,7 +946,7 @@ public String toString(){

protected String clusterId = null;

void retrieveClusterId() {
void retrieveClusterId() throws IOException {
if (clusterId != null) return;
this.clusterId = this.registry.getClusterId();
if (clusterId == null) {
Expand Down Expand Up @@ -1005,7 +1012,7 @@ public HRegionLocation getRegionLocation(final byte[] tableName,

@Override
public boolean isTableEnabled(TableName tableName) throws IOException {
return this.registry.isTableOnlineState(tableName, true);
return getTableState(tableName).inStates(TableState.State.ENABLED);
}

@Override
Expand All @@ -1015,7 +1022,7 @@ public boolean isTableEnabled(byte[] tableName) throws IOException {

@Override
public boolean isTableDisabled(TableName tableName) throws IOException {
return this.registry.isTableOnlineState(tableName, false);
return getTableState(tableName).inStates(TableState.State.DISABLED);
}

@Override
Expand Down Expand Up @@ -1256,7 +1263,7 @@ private RegionLocations locateMeta(final TableName tableName,
}
}
// Look up from zookeeper
metaLocations = this.registry.getMetaRegionLocation();
metaLocations = this.registry.getMetaRegionLocations();
lastMetaLookupTime = EnvironmentEdgeManager.currentTime();
if (metaLocations != null &&
metaLocations.getRegionLocation(replicaId) != null) {
Expand Down Expand Up @@ -1571,43 +1578,31 @@ abstract class StubMaker {
* @throws KeeperException
* @throws ServiceException
*/
private Object makeStubNoRetries() throws IOException, KeeperException, ServiceException {
ZooKeeperKeepAliveConnection zkw;
try {
zkw = getKeepAliveZooKeeperWatcher();
} catch (IOException e) {
ExceptionUtil.rethrowIfInterrupt(e);
throw new ZooKeeperConnectionException("Can't connect to ZooKeeper", e);
}
try {
checkIfBaseNodeAvailable(zkw);
ServerName sn = MasterAddressTracker.getMasterAddress(zkw);
if (sn == null) {
String msg = "ZooKeeper available but no active master location found";
LOG.info(msg);
throw new MasterNotRunningException(msg);
}
if (isDeadServer(sn)) {
throw new MasterNotRunningException(sn + " is dead.");
}
// Use the security info interface name as our stub key
String key = getStubKey(getServiceName(),
sn.getHostname(), sn.getPort(), hostnamesCanChange);
connectionLock.putIfAbsent(key, key);
Object stub = null;
synchronized (connectionLock.get(key)) {
stub = stubs.get(key);
if (stub == null) {
BlockingRpcChannel channel = rpcClient.createBlockingRpcChannel(sn, user, rpcTimeout);
stub = makeStub(channel);
isMasterRunning();
stubs.put(key, stub);
}
private Object makeStubNoRetries() throws IOException, ServiceException {
ServerName sn = registry.getActiveMaster();
if (sn == null) {
String msg = "No active master location found";
LOG.info(msg);
throw new MasterNotRunningException(msg);
}
if (isDeadServer(sn)) {
throw new MasterNotRunningException(sn + " is dead.");
}
// Use the security info interface name as our stub key
String key = getStubKey(getServiceName(),
sn.getHostname(), sn.getPort(), hostnamesCanChange);
connectionLock.putIfAbsent(key, key);
Object stub = null;
synchronized (connectionLock.get(key)) {
stub = stubs.get(key);
if (stub == null) {
BlockingRpcChannel channel = rpcClient.createBlockingRpcChannel(sn, user, rpcTimeout);
stub = makeStub(channel);
isMasterRunning();
stubs.put(key, stub);
}
return stub;
} finally {
zkw.close();
}
return stub;
}

/**
Expand All @@ -1625,12 +1620,9 @@ Object makeStub() throws IOException {
return makeStubNoRetries();
} catch (IOException e) {
exceptionCaught = e;
} catch (KeeperException e) {
exceptionCaught = e;
} catch (ServiceException e) {
exceptionCaught = e;
}

throw new MasterNotRunningException(exceptionCaught);
} else {
throw new DoNotRetryIOException("Connection was closed while trying to get master");
Expand Down Expand Up @@ -2157,6 +2149,13 @@ public ListTableNamesByNamespaceResponse listTableNamesByNamespace(
return stub.listTableNamesByNamespace(controller, request);
}

@Override
public GetTableStateResponse getTableState(
RpcController controller, GetTableStateRequest request)
throws ServiceException {
return stub.getTableState(controller, request);
}

@Override
public void close() {
release(this.mss);
Expand Down Expand Up @@ -2577,6 +2576,9 @@ void internalClose() {
if (this.closed) {
return;
}
if (this.registry != null) {
this.registry.close();
}
closeMaster();
shutdownPools();
if (this.metrics != null) {
Expand Down Expand Up @@ -2784,6 +2786,19 @@ public RpcRetryingCallerFactory getRpcRetryingCallerFactory() {
public RpcControllerFactory getRpcControllerFactory() {
return this.rpcControllerFactory;
}

public TableState getTableState(TableName tableName) throws IOException {
MasterKeepAliveConnection master = getKeepAliveMasterService();
try {
GetTableStateResponse resp = master.getTableState(null,
RequestConverter.buildGetTableStateRequest(tableName));
return TableState.convert(resp.getTableState());
} catch (ServiceException se) {
throw ProtobufUtil.getRemoteException(se);
} finally {
master.close();
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,42 +19,46 @@

import java.io.IOException;

import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.classification.InterfaceAudience;
import org.apache.hadoop.hbase.RegionLocations;
import org.apache.hadoop.hbase.TableName;

/**
* Cluster registry.
* Implementations hold cluster information such as this cluster's id, location of hbase:meta, etc.
* needed by cluster connections.
* Internal use only.
*/
@InterfaceAudience.Private
interface Registry {
interface ConnectionRegistry {
/**
* @param connection
*/
void init(Connection connection);
void init(Connection connection) throws IOException;

/**
* @return the currently active master, null if none exists.
*/
ServerName getActiveMaster() throws IOException;

/**
* @return Meta region location
* @throws IOException
*/
RegionLocations getMetaRegionLocation() throws IOException;
RegionLocations getMetaRegionLocations() throws IOException;

/**
* @return Cluster id.
*/
String getClusterId();
String getClusterId() throws IOException;

/**
* @param enabled Return true if table is enabled
* @return Count of 'running' regionservers
* @throws IOException
*/
boolean isTableOnlineState(TableName tableName, boolean enabled) throws IOException;
int getCurrentNrHRS() throws IOException;

/**
* @return Count of 'running' regionservers
* @throws IOException
* Cleanup state, if any.
*/
int getCurrentNrHRS() throws IOException;
void close();
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,26 @@

import java.io.IOException;

import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.classification.InterfaceAudience;

/**
* Get instance of configured Registry.
* Get instance of configured Connection Registry.
*/
@InterfaceAudience.Private
class RegistryFactory {
static final String REGISTRY_IMPL_CONF_KEY = "hbase.client.registry.impl";
class ConnectionRegistryFactory {

/**
* @return The cluster registry implementation to use.
* @throws IOException
*/
static Registry getRegistry(final Connection connection)
static ConnectionRegistry getRegistry(final Connection connection)
throws IOException {
String registryClass = connection.getConfiguration().get(REGISTRY_IMPL_CONF_KEY,
ZooKeeperRegistry.class.getName());
Registry registry = null;
String registryClass = connection.getConfiguration().get(HConstants.REGISTRY_IMPL_CONF_KEY,
ZKConnectionRegistry.class.getName());
ConnectionRegistry registry = null;
try {
registry = (Registry)Class.forName(registryClass).getDeclaredConstructor().newInstance();
registry = (ConnectionRegistry)Class.forName(registryClass).getDeclaredConstructor().newInstance();
} catch (Throwable t) {
throw new IOException(t);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,13 @@ boolean isMasterRunning()
@Deprecated
boolean isTableDisabled(byte[] tableName) throws IOException;

/**
* Retrieve TableState, represent current table state.
* @param tableName table state for
* @return state of the table
*/
public TableState getTableState(TableName tableName) throws IOException;

/**
* @param tableName table name
* @return true if all regions of the table are available, false otherwise
Expand Down
Loading