Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HBASE-23055 Alter hbase:meta #646

Closed
wants to merge 1 commit into from
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 @@ -304,11 +304,18 @@ public static HRegionLocation getRegionLocation(Connection connection, byte[] re
*/
public static HRegionLocation getRegionLocation(Connection connection, RegionInfo regionInfo)
throws IOException {
byte[] row = getMetaKeyForRegion(regionInfo);
Get get = new Get(row);
return getRegionLocation(getCatalogFamilyRow(connection, regionInfo),
regionInfo, regionInfo.getReplicaId());
}

/**
* @return Return the {@link HConstants#CATALOG_FAMILY} row from hbase:meta.
*/
public static Result getCatalogFamilyRow(Connection connection, RegionInfo ri)
throws IOException {
Get get = new Get(getMetaKeyForRegion(ri));
get.addFamily(HConstants.CATALOG_FAMILY);
Result r = get(getMetaHTable(connection), get);
return getRegionLocation(r, regionInfo, regionInfo.getReplicaId());
return get(getMetaHTable(connection), get);
}

/** Returns the row key to use for this regionInfo */
Expand Down Expand Up @@ -1110,7 +1117,7 @@ public static RegionInfo getRegionInfo(final Result r, byte [] qualifier) {
public static TableState getTableState(Connection conn, TableName tableName)
throws IOException {
if (tableName.equals(TableName.META_TABLE_NAME)) {
return new TableState(tableName, TableState.State.ENABLED);
throw new IllegalAccessError("Go to the Master to find hbase:meta table state, not here");
}
Table metaHTable = getMetaHTable(conn);
Get get = new Get(tableName.getName()).addColumn(getTableFamily(), getTableStateColumn());
Expand Down Expand Up @@ -1138,7 +1145,8 @@ public static Map<TableName, TableState> getTableStates(Connection conn)
}

/**
* Updates state in META
* Updates state in META.
* Do not use. For internal use only.
* @param conn connection to use
* @param tableName table to look for
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
Expand Down Expand Up @@ -45,6 +45,7 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReentrantLock;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.AuthUtil;
import org.apache.hadoop.hbase.CallQueueTooBigException;
Expand All @@ -71,6 +72,7 @@
import org.apache.hadoop.hbase.log.HBaseMarkers;
import org.apache.hadoop.hbase.regionserver.RegionServerStoppedException;
import org.apache.hadoop.hbase.security.User;
import org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.apache.hadoop.hbase.util.ExceptionUtil;
Expand Down Expand Up @@ -163,6 +165,7 @@ class ConnectionImplementation implements ClusterConnection, Closeable {
private final int metaReplicaCallTimeoutScanInMicroSecond;
private final int numTries;
final int rpcTimeout;
private final int operationTimeout;

/**
* Global nonceGenerator shared per client.Currently there's no reason to limit its scope.
Expand Down Expand Up @@ -330,6 +333,8 @@ public void newDead(ServerName sn) {
close();
throw e;
}
this.operationTimeout = this.conf.getInt(HConstants.HBASE_CLIENT_OPERATION_TIMEOUT,
HConstants.DEFAULT_HBASE_CLIENT_OPERATION_TIMEOUT);
}

private void spawnRenewalChore(final UserGroupInformation user) {
Expand Down Expand Up @@ -2057,12 +2062,32 @@ public NonceGenerator getNonceGenerator() {

@Override
public TableState getTableState(TableName tableName) throws IOException {
checkClosed();
TableState tableState = MetaTableAccessor.getTableState(this, tableName);
if (tableState == null) {
throw new TableNotFoundException(tableName);
// Go to the Master for Table State. It is the authority. It knows State for user-space
// and for system-space tables. Previous we went direct to the hbase:meta table to find
// table-state. hbase:meta does not have system-table states. This puts new load on Master.
// Now it proxies reads to the hbase:meta. Benefit is that we hide table state implementation.
// Benefit is more load. Master is host for hbase:meta table-state (and for that of other
// tables). Going to Master means one-stop-shop for all table states.
try (MasterCallable<TableState.State> callable =
new MasterCallable<TableState.State>(this, getRpcControllerFactory()) {
@Override
protected TableState.State rpcCall() throws Exception {
setPriority(tableName);
MasterProtos.GetTableStateRequest req = RequestConverter.buildGetTableStateRequest(tableName);
MasterProtos.GetTableStateResponse ret = master.getTableState(getRpcController(), req);
if (!ret.hasTableState() || ret.getTableState() == null) {
throw new TableNotFoundException(tableName);
}
if (ret.hasTableState() || ret.getTableState() == null) {
throw new TableNotFoundException(tableName);
}
return TableState.State.valueOf(ret.getTableState().getState().toString());
}
}) {
RpcRetryingCaller<TableState.State> caller = getRpcRetryingCallerFactory().
newCaller(this.rpcTimeout);
return new TableState(tableName, caller.callWithRetries(callable, this.operationTimeout));
}
return tableState;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -543,7 +543,9 @@ public HTableDescriptor getTableDescriptor(final TableName tableName) throws IOE
static TableDescriptor getTableDescriptor(final TableName tableName, Connection connection,
RpcRetryingCallerFactory rpcCallerFactory, final RpcControllerFactory rpcControllerFactory,
int operationTimeout, int rpcTimeout) throws IOException {
if (tableName == null) return null;
if (tableName == null) {
return null;
}
TableDescriptor td =
executeCallable(new MasterCallable<TableDescriptor>(connection, rpcControllerFactory) {
@Override
Expand Down Expand Up @@ -948,22 +950,13 @@ public HTableDescriptor[] disableTables(Pattern pattern) throws IOException {
@Override
public boolean isTableEnabled(final TableName tableName) throws IOException {
checkTableExists(tableName);
return executeCallable(new RpcRetryingCallable<Boolean>() {
@Override
protected Boolean rpcCall(int callTimeout) throws Exception {
TableState tableState = MetaTableAccessor.getTableState(getConnection(), tableName);
if (tableState == null) {
throw new TableNotFoundException(tableName);
}
return tableState.inStates(TableState.State.ENABLED);
}
});
return this.connection.getTableState(tableName).isEnabled();
}

@Override
public boolean isTableDisabled(TableName tableName) throws IOException {
checkTableExists(tableName);
return connection.isTableDisabled(tableName);
return this.connection.getTableState(tableName).isDisabled();
}

@Override
Expand Down Expand Up @@ -4357,5 +4350,4 @@ protected Boolean rpcCall() throws Exception {
});

}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* Copyright The Apache Software Foundation
*
* Licensed to the Apache Software Foundation (ASF) under one
Expand All @@ -23,6 +23,8 @@
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos;
import org.apache.yetus.audience.InterfaceAudience;

import java.io.Closeable;

/**
* A KeepAlive connection is not physically closed immediately after the close,
* but rather kept alive for a few minutes. It makes sense only if it is shared.
Expand All @@ -35,7 +37,7 @@
* final user code. Hence it's package protected.
*/
@InterfaceAudience.Private
interface MasterKeepAliveConnection extends MasterProtos.MasterService.BlockingInterface {
interface MasterKeepAliveConnection extends MasterProtos.MasterService.BlockingInterface, Closeable {
// Do this instead of implement Closeable because closeable returning IOE is PITA.
void close();
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
import org.apache.hadoop.hbase.security.access.Permission;
import org.apache.hadoop.hbase.security.access.ShadedAccessControlUtil;
import org.apache.hadoop.hbase.security.access.UserPermission;
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos;
import org.apache.hadoop.hbase.snapshot.ClientSnapshotDescriptionUtils;
import org.apache.hadoop.hbase.snapshot.RestoreSnapshotException;
import org.apache.hadoop.hbase.snapshot.SnapshotCreationException;
Expand Down Expand Up @@ -663,42 +664,23 @@ public CompletableFuture<Void> disableTable(TableName tableName) {

@Override
public CompletableFuture<Boolean> isTableEnabled(TableName tableName) {
if (TableName.isMetaTableName(tableName)) {
return CompletableFuture.completedFuture(true);
}
CompletableFuture<Boolean> future = new CompletableFuture<>();
addListener(AsyncMetaTableAccessor.getTableState(metaTable, tableName), (state, error) -> {
if (error != null) {
future.completeExceptionally(error);
return;
}
if (state.isPresent()) {
future.complete(state.get().inStates(TableState.State.ENABLED));
} else {
future.completeExceptionally(new TableNotFoundException(tableName));
}
});
return future;
return isTableState(tableName, TableState.State.ENABLED);
}

@Override
public CompletableFuture<Boolean> isTableDisabled(TableName tableName) {
if (TableName.isMetaTableName(tableName)) {
return CompletableFuture.completedFuture(false);
}
CompletableFuture<Boolean> future = new CompletableFuture<>();
addListener(AsyncMetaTableAccessor.getTableState(metaTable, tableName), (state, error) -> {
if (error != null) {
future.completeExceptionally(error);
return;
}
if (state.isPresent()) {
future.complete(state.get().inStates(TableState.State.DISABLED));
} else {
future.completeExceptionally(new TableNotFoundException(tableName));
}
});
return future;
return isTableState(tableName, TableState.State.DISABLED);
}

/**
* @return Future that calls Master getTableState and compares to <code>state</code>
*/
private CompletableFuture<Boolean> isTableState(TableName tableName, TableState.State state) {
return this.<Boolean> newMasterCaller().action((controller, stub) ->
this.<MasterProtos.GetTableStateRequest, MasterProtos.GetTableStateResponse, Boolean> call(
controller, stub, MasterProtos.GetTableStateRequest.newBuilder().
setTableName(ProtobufUtil.toProtoTableName(tableName)).build(), (s, c, req, done) ->
s.getTableState(c, req, done), resp -> resp.getTableState().equals(state))).call();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -158,7 +158,8 @@ private void getMetaRegionLocation(CompletableFuture<RegionLocations> future,
}
Pair<RegionState.State, ServerName> stateAndServerName = getStateAndServerName(proto);
if (stateAndServerName.getFirst() != RegionState.State.OPEN) {
LOG.warn("Meta region is in state " + stateAndServerName.getFirst());
LOG.warn("hbase:meta region (replicaId={}) is in state {}", replicaId,
stateAndServerName.getFirst());
}
locs[DEFAULT_REPLICA_ID] = new HRegionLocation(
getRegionInfoForDefaultReplica(FIRST_META_REGIONINFO), stateAndServerName.getSecond());
Expand All @@ -173,7 +174,7 @@ private void getMetaRegionLocation(CompletableFuture<RegionLocations> future,
LOG.warn("Failed to fetch " + path, error);
locs[replicaId] = null;
} else if (proto == null) {
LOG.warn("Meta znode for replica " + replicaId + " is null");
LOG.warn("hbase:meta znode for replica " + replicaId + " is null");
locs[replicaId] = null;
} else {
Pair<RegionState.State, ServerName> stateAndServerName = getStateAndServerName(proto);
Expand All @@ -197,9 +198,8 @@ private void getMetaRegionLocation(CompletableFuture<RegionLocations> future,
public CompletableFuture<RegionLocations> getMetaRegionLocation() {
CompletableFuture<RegionLocations> future = new CompletableFuture<>();
addListener(
zk.list(znodePaths.baseZNode)
.thenApply(children -> children.stream()
.filter(c -> c.startsWith(znodePaths.metaZNodePrefix)).collect(Collectors.toList())),
zk.list(znodePaths.baseZNode).thenApply(children -> children.stream().
filter(c -> znodePaths.isMetaZNodePrefix(c)).collect(Collectors.toList())),
(metaReplicaZNodes, error) -> {
if (error != null) {
future.completeExceptionally(error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
import org.apache.hadoop.hbase.client.SnapshotType;
import org.apache.hadoop.hbase.client.TableDescriptor;
import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
import org.apache.hadoop.hbase.client.TableState;
import org.apache.hadoop.hbase.client.metrics.ScanMetrics;
import org.apache.hadoop.hbase.client.security.SecurityCapability;
import org.apache.hadoop.hbase.exceptions.DeserializationException;
Expand Down
Loading