下面列出了org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos#RegionSpecifier ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Get RegionInfo from Master using content of RegionSpecifier as key.
* @return RegionInfo found by decoding <code>rs</code> or null if none found
*/
private RegionInfo getRegionInfo(HBaseProtos.RegionSpecifier rs) throws UnknownRegionException {
RegionInfo ri = null;
switch(rs.getType()) {
case REGION_NAME:
final byte[] regionName = rs.getValue().toByteArray();
ri = this.master.getAssignmentManager().getRegionInfo(regionName);
break;
case ENCODED_REGION_NAME:
String encodedRegionName = Bytes.toString(rs.getValue().toByteArray());
RegionState regionState = this.master.getAssignmentManager().getRegionStates().
getRegionState(encodedRegionName);
ri = regionState == null ?
this.master.getAssignmentManager().loadRegionFromMeta(encodedRegionName) :
regionState.getRegion();
break;
default:
break;
}
return ri;
}
/**
* Throw some exceptions. Mostly throw exceptions which do not clear meta cache.
* Periodically throw NotSevingRegionException which clears the meta cache.
* @throws ServiceException
*/
private void throwSomeExceptions(FakeRSRpcServices rpcServices,
HBaseProtos.RegionSpecifier regionSpec)
throws ServiceException {
if (!isTestTable(rpcServices, regionSpec)) {
return;
}
numReqs++;
// Succeed every 5 request, throw cache clearing exceptions twice every 5 requests and throw
// meta cache preserving exceptions otherwise.
if (numReqs % 5 ==0) {
return;
} else if (numReqs % 5 == 1 || numReqs % 5 == 2) {
throw new ServiceException(new NotServingRegionException());
}
// Round robin between different special exceptions.
// This is not ideal since exception types are not tied to the operation performed here,
// But, we don't really care here if we throw MultiActionTooLargeException while doing
// single Gets.
expCount++;
Throwable t = metaCachePreservingExceptions.get(
expCount % metaCachePreservingExceptions.size());
throw new ServiceException(t);
}
/**
* A 'raw' version of assign that does bulk and skirts Master state checks (assigns can be made
* during Master startup). For use by Hbck2.
*/
@Override
public MasterProtos.AssignsResponse assigns(RpcController controller,
MasterProtos.AssignsRequest request)
throws ServiceException {
if (this.master.getMasterProcedureExecutor() == null) {
throw new ServiceException("Master's ProcedureExecutor not initialized; retry later");
}
MasterProtos.AssignsResponse.Builder responseBuilder =
MasterProtos.AssignsResponse.newBuilder();
try {
boolean override = request.getOverride();
LOG.info("{} assigns, override={}", master.getClientIdAuditPrefix(), override);
for (HBaseProtos.RegionSpecifier rs: request.getRegionList()) {
RegionInfo ri = getRegionInfo(rs);
if (ri == null) {
LOG.info("Unknown={}", rs);
responseBuilder.addPid(Procedure.NO_PROC_ID);
continue;
}
responseBuilder.addPid(this.master.getMasterProcedureExecutor().submitProcedure(this.master
.getAssignmentManager().createOneAssignProcedure(ri, override)));
}
return responseBuilder.build();
} catch (IOException ioe) {
throw new ServiceException(ioe);
}
}
/**
* A 'raw' version of unassign that does bulk and skirts Master state checks (unassigns can be
* made during Master startup). For use by Hbck2.
*/
@Override
public MasterProtos.UnassignsResponse unassigns(RpcController controller,
MasterProtos.UnassignsRequest request)
throws ServiceException {
if (this.master.getMasterProcedureExecutor() == null) {
throw new ServiceException("Master's ProcedureExecutor not initialized; retry later");
}
MasterProtos.UnassignsResponse.Builder responseBuilder =
MasterProtos.UnassignsResponse.newBuilder();
try {
boolean override = request.getOverride();
LOG.info("{} unassigns, override={}", master.getClientIdAuditPrefix(), override);
for (HBaseProtos.RegionSpecifier rs: request.getRegionList()) {
RegionInfo ri = getRegionInfo(rs);
if (ri == null) {
LOG.info("Unknown={}", rs);
responseBuilder.addPid(Procedure.NO_PROC_ID);
continue;
}
responseBuilder.addPid(this.master.getMasterProcedureExecutor().submitProcedure(this.master
.getAssignmentManager().createOneUnassignProcedure(ri, override)));
}
return responseBuilder.build();
} catch (IOException ioe) {
throw new ServiceException(ioe);
}
}
private ClusterStatusProtos.ServerLoad createServerLoadProto() {
HBaseProtos.RegionSpecifier rSpecOne = HBaseProtos.RegionSpecifier.newBuilder()
.setType(HBaseProtos.RegionSpecifier.RegionSpecifierType.ENCODED_REGION_NAME)
.setValue(ByteString.copyFromUtf8("ASDFGQWERT")).build();
HBaseProtos.RegionSpecifier rSpecTwo = HBaseProtos.RegionSpecifier.newBuilder()
.setType(HBaseProtos.RegionSpecifier.RegionSpecifierType.ENCODED_REGION_NAME)
.setValue(ByteString.copyFromUtf8("QWERTYUIOP")).build();
ClusterStatusProtos.RegionLoad rlOne =
ClusterStatusProtos.RegionLoad.newBuilder().setRegionSpecifier(rSpecOne).setStores(10)
.setStorefiles(101).setStoreUncompressedSizeMB(106).setStorefileSizeMB(520)
.setFilteredReadRequestsCount(100).setStorefileIndexSizeKB(42).setRootIndexSizeKB(201)
.setReadRequestsCount(Integer.MAX_VALUE).setWriteRequestsCount(Integer.MAX_VALUE)
.build();
ClusterStatusProtos.RegionLoad rlTwo =
ClusterStatusProtos.RegionLoad.newBuilder().setRegionSpecifier(rSpecTwo).setStores(3)
.setStorefiles(13).setStoreUncompressedSizeMB(23).setStorefileSizeMB(300)
.setFilteredReadRequestsCount(200).setStorefileIndexSizeKB(40).setRootIndexSizeKB(303)
.setReadRequestsCount(Integer.MAX_VALUE).setWriteRequestsCount(Integer.MAX_VALUE)
.setCpRequestsCount(100)
.build();
ClusterStatusProtos.ServerLoad sl =
ClusterStatusProtos.ServerLoad.newBuilder().addRegionLoads(rlOne).
addRegionLoads(rlTwo).build();
return sl;
}
protected boolean isTestTable(FakeRSRpcServices rpcServices,
HBaseProtos.RegionSpecifier regionSpec) throws ServiceException {
try {
return TABLE_NAME.equals(
rpcServices.getRegion(regionSpec).getTableDescriptor().getTableName());
} catch (IOException ioe) {
throw new ServiceException(ioe);
}
}
public static CacheEvictionStats toCacheEvictionStats(
HBaseProtos.CacheEvictionStats stats) throws IOException{
CacheEvictionStatsBuilder builder = CacheEvictionStats.builder();
builder.withEvictedBlocks(stats.getEvictedBlocks())
.withMaxCacheSize(stats.getMaxCacheSize());
if (stats.getExceptionCount() > 0) {
for (HBaseProtos.RegionExceptionMessage exception : stats.getExceptionList()) {
HBaseProtos.RegionSpecifier rs = exception.getRegion();
byte[] regionName = rs.getValue().toByteArray();
builder.addException(regionName, ProtobufUtil.toException(exception.getException()));
}
}
return builder.build();
}
/**
* Get the results from a protocol buffer MultiResponse
*
* @param request the original protocol buffer MultiRequest
* @param indexMap Used to support RowMutations/CheckAndMutate in batch
* @param response the protocol buffer MultiResponse to convert
* @param cells Cells to go with the passed in <code>proto</code>. Can be null.
* @return the results that were in the MultiResponse (a Result or an Exception).
* @throws IOException
*/
public static org.apache.hadoop.hbase.client.MultiResponse getResults(final MultiRequest request,
final Map<Integer, Integer> indexMap, final MultiResponse response,
final CellScanner cells) throws IOException {
int requestRegionActionCount = request.getRegionActionCount();
int responseRegionActionResultCount = response.getRegionActionResultCount();
if (requestRegionActionCount != responseRegionActionResultCount) {
throw new IllegalStateException("Request mutation count=" + requestRegionActionCount +
" does not match response mutation result count=" + responseRegionActionResultCount);
}
org.apache.hadoop.hbase.client.MultiResponse results =
new org.apache.hadoop.hbase.client.MultiResponse();
for (int i = 0; i < responseRegionActionResultCount; i++) {
RegionAction actions = request.getRegionAction(i);
RegionActionResult actionResult = response.getRegionActionResult(i);
HBaseProtos.RegionSpecifier rs = actions.getRegion();
if (rs.hasType() &&
(rs.getType() != HBaseProtos.RegionSpecifier.RegionSpecifierType.REGION_NAME)){
throw new IllegalArgumentException(
"We support only encoded types for protobuf multi response.");
}
byte[] regionName = rs.getValue().toByteArray();
if (actionResult.hasException()) {
Throwable regionException = ProtobufUtil.toException(actionResult.getException());
results.addException(regionName, regionException);
continue;
}
if (actions.getActionCount() != actionResult.getResultOrExceptionCount()) {
throw new IllegalStateException("actions.getActionCount=" + actions.getActionCount() +
", actionResult.getResultOrExceptionCount=" +
actionResult.getResultOrExceptionCount() + " for region " + actions.getRegion());
}
Object responseValue;
// For RowMutations/CheckAndMutate action, if there is an exception, the exception is set
// at the RegionActionResult level and the ResultOrException is null at the original index
Integer index = (indexMap == null ? null : indexMap.get(i));
if (index != null) {
// This RegionAction is from a RowMutations/CheckAndMutate in a batch.
// If there is an exception from the server, the exception is set at
// the RegionActionResult level, which has been handled above.
responseValue = actionResult.getProcessed() ?
ProtobufUtil.EMPTY_RESULT_EXISTS_TRUE :
ProtobufUtil.EMPTY_RESULT_EXISTS_FALSE;
results.add(regionName, index, responseValue);
continue;
}
for (ResultOrException roe : actionResult.getResultOrExceptionList()) {
if (roe.hasException()) {
responseValue = ProtobufUtil.toException(roe.getException());
} else if (roe.hasResult()) {
responseValue = ProtobufUtil.toResult(roe.getResult(), cells);
} else if (roe.hasServiceResult()) {
responseValue = roe.getServiceResult();
} else {
// Sometimes, the response is just "it was processed". Generally, this occurs for things
// like mutateRows where either we get back 'processed' (or not) and optionally some
// statistics about the regions we touched.
responseValue = actionResult.getProcessed() ?
ProtobufUtil.EMPTY_RESULT_EXISTS_TRUE :
ProtobufUtil.EMPTY_RESULT_EXISTS_FALSE;
}
results.add(regionName, roe.getIndex(), responseValue);
}
}
if (response.hasRegionStatistics()) {
ClientProtos.MultiRegionLoadStats stats = response.getRegionStatistics();
for (int i = 0; i < stats.getRegionCount(); i++) {
results.addStatistic(stats.getRegion(i).getValue().toByteArray(), stats.getStat(i));
}
}
return results;
}