use of org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.RegionSpecifierAndState in project hbase by apache.
the class HBaseHbck method setRegionStateInMeta.
@Override
public Map<String, RegionState.State> setRegionStateInMeta(Map<String, RegionState.State> nameOrEncodedName2State) throws IOException {
try {
if (LOG.isDebugEnabled()) {
nameOrEncodedName2State.forEach((k, v) -> LOG.debug("region={}, state={}", k, v));
}
MasterProtos.SetRegionStateInMetaResponse response = hbck.setRegionStateInMeta(rpcControllerFactory.newController(), RequestConverter.buildSetRegionStateInMetaRequest(nameOrEncodedName2State));
Map<String, RegionState.State> result = new HashMap<>();
for (RegionSpecifierAndState nameAndState : response.getStatesList()) {
result.put(nameAndState.getRegionSpecifier().getValue().toStringUtf8(), RegionState.State.convert(nameAndState.getState()));
}
return result;
} catch (ServiceException se) {
throw new IOException(se);
}
}
use of org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.RegionSpecifierAndState in project hbase by apache.
the class MasterRpcServices method setRegionStateInMeta.
/**
* Update state of the region in meta only. This is required by hbck in some situations to cleanup
* stuck assign/ unassign regions procedures for the table.
*
* @return previous states of the regions
*/
@Override
public SetRegionStateInMetaResponse setRegionStateInMeta(RpcController controller, SetRegionStateInMetaRequest request) throws ServiceException {
rpcPreCheck("setRegionStateInMeta");
SetRegionStateInMetaResponse.Builder builder = SetRegionStateInMetaResponse.newBuilder();
try {
for (RegionSpecifierAndState s : request.getStatesList()) {
RegionSpecifier spec = s.getRegionSpecifier();
String encodedName;
if (spec.getType() == RegionSpecifierType.ENCODED_REGION_NAME) {
encodedName = spec.getValue().toStringUtf8();
} else {
// TODO: actually, a full region name can save a lot on meta scan, improve later.
encodedName = RegionInfo.encodeRegionName(spec.getValue().toByteArray());
}
RegionInfo info = this.server.getAssignmentManager().loadRegionFromMeta(encodedName);
LOG.trace("region info loaded from meta table: {}", info);
RegionState prevState = this.server.getAssignmentManager().getRegionStates().getRegionState(info);
RegionState.State newState = RegionState.State.convert(s.getState());
LOG.info("{} set region={} state from {} to {}", server.getClientIdAuditPrefix(), info, prevState.getState(), newState);
Put metaPut = MetaTableAccessor.makePutFromRegionInfo(info, EnvironmentEdgeManager.currentTime());
metaPut.addColumn(HConstants.CATALOG_FAMILY, HConstants.STATE_QUALIFIER, Bytes.toBytes(newState.name()));
List<Put> putList = new ArrayList<>();
putList.add(metaPut);
MetaTableAccessor.putsToMetaTable(this.server.getConnection(), putList);
// Loads from meta again to refresh AM cache with the new region state
this.server.getAssignmentManager().loadRegionFromMeta(encodedName);
builder.addStates(RegionSpecifierAndState.newBuilder().setRegionSpecifier(spec).setState(prevState.getState().convert()));
}
} catch (Exception e) {
throw new ServiceException(e);
}
return builder.build();
}
Aggregations