use of org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.ScanRequest in project hbase by apache.
the class TestPriorityRpc method testQosFunctionForScanMethod.
@Test
public void testQosFunctionForScanMethod() throws IOException {
RequestHeader.Builder headerBuilder = RequestHeader.newBuilder();
headerBuilder.setMethodName("Scan");
RequestHeader header = headerBuilder.build();
//build an empty scan request
ScanRequest.Builder scanBuilder = ScanRequest.newBuilder();
ScanRequest scanRequest = scanBuilder.build();
HRegion mockRegion = Mockito.mock(HRegion.class);
HRegionServer mockRS = Mockito.mock(HRegionServer.class);
RSRpcServices mockRpc = Mockito.mock(RSRpcServices.class);
Mockito.when(mockRS.getRSRpcServices()).thenReturn(mockRpc);
HRegionInfo mockRegionInfo = Mockito.mock(HRegionInfo.class);
Mockito.when(mockRpc.getRegion((RegionSpecifier) Mockito.any())).thenReturn(mockRegion);
Mockito.when(mockRegion.getRegionInfo()).thenReturn(mockRegionInfo);
Mockito.when(mockRegionInfo.isSystemTable()).thenReturn(false);
// Presume type.
((AnnotationReadingPriorityFunction) priority).setRegionServer(mockRS);
int qos = priority.getPriority(header, scanRequest, User.createUserForTesting(regionServer.conf, "someuser", new String[] { "somegroup" }));
assertTrue("" + qos, qos == HConstants.NORMAL_QOS);
//build a scan request with scannerID
scanBuilder = ScanRequest.newBuilder();
scanBuilder.setScannerId(12345);
scanRequest = scanBuilder.build();
//mock out a high priority type handling and see the QoS returned
RegionScanner mockRegionScanner = Mockito.mock(RegionScanner.class);
Mockito.when(mockRpc.getScanner(12345)).thenReturn(mockRegionScanner);
Mockito.when(mockRegionScanner.getRegionInfo()).thenReturn(mockRegionInfo);
Mockito.when(mockRpc.getRegion((RegionSpecifier) Mockito.any())).thenReturn(mockRegion);
Mockito.when(mockRegion.getRegionInfo()).thenReturn(mockRegionInfo);
Mockito.when(mockRegionInfo.isSystemTable()).thenReturn(true);
// Presume type.
((AnnotationReadingPriorityFunction) priority).setRegionServer(mockRS);
assertEquals(HConstants.SYSTEMTABLE_QOS, priority.getPriority(header, scanRequest, User.createUserForTesting(regionServer.conf, "someuser", new String[] { "somegroup" })));
//the same as above but with non-meta region
Mockito.when(mockRegionInfo.isSystemTable()).thenReturn(false);
assertEquals(HConstants.NORMAL_QOS, priority.getPriority(header, scanRequest, User.createUserForTesting(regionServer.conf, "someuser", new String[] { "somegroup" })));
}
use of org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.ScanRequest in project hbase by apache.
the class ScannerCallable method next.
private ScanResponse next() throws IOException {
// Reset the heartbeat flag prior to each RPC in case an exception is thrown by the server
setHeartbeatMessage(false);
incRPCcallsMetrics();
ScanRequest request = RequestConverter.buildScanRequest(scannerId, caching, false, nextCallSeq, this.scanMetrics != null, renew, scan.getLimit());
try {
ScanResponse response = getStub().scan(getRpcController(), request);
nextCallSeq++;
return response;
} catch (Exception e) {
IOException ioe = ProtobufUtil.handleRemoteException(e);
if (logScannerActivity) {
LOG.info("Got exception making request " + ProtobufUtil.toText(request) + " to " + getLocation(), e);
}
if (logScannerActivity) {
if (ioe instanceof UnknownScannerException) {
try {
HRegionLocation location = getConnection().relocateRegion(getTableName(), scan.getStartRow());
LOG.info("Scanner=" + scannerId + " expired, current region location is " + location.toString());
} catch (Throwable t) {
LOG.info("Failed to relocate region", t);
}
} else if (ioe instanceof ScannerResetException) {
LOG.info("Scanner=" + scannerId + " has received an exception, and the server " + "asked us to reset the scanner state.", ioe);
}
}
// yeah and hard to follow and in need of a refactor).
if (ioe instanceof NotServingRegionException) {
// Attach NSRE to signal client that it needs to re-setup scanner.
if (this.scanMetrics != null) {
this.scanMetrics.countOfNSRE.incrementAndGet();
}
throw new DoNotRetryIOException("Resetting the scanner -- see exception cause", ioe);
} else if (ioe instanceof RegionServerStoppedException) {
// open scanner against new location.
throw new DoNotRetryIOException("Resetting the scanner -- see exception cause", ioe);
} else {
// The outer layers will retry
throw ioe;
}
}
}
use of org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.ScanRequest in project hbase by apache.
the class ScannerCallable method close.
private void close() {
if (this.scannerId == -1L) {
return;
}
try {
incRPCcallsMetrics();
ScanRequest request = RequestConverter.buildScanRequest(this.scannerId, 0, true, this.scanMetrics != null);
try {
getStub().scan(getRpcController(), request);
} catch (Exception e) {
throw ProtobufUtil.handleRemoteException(e);
}
} catch (IOException e) {
TableName table = getTableName();
String tableDetails = (table == null) ? "" : (" on table: " + table.getNameAsString());
LOG.warn("Ignore, probably already closed. Current scan: " + getScan().toString() + tableDetails, e);
}
this.scannerId = -1L;
}
use of org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.ScanRequest in project hbase by apache.
the class RequestConverter method buildScanRequest.
/**
* Create a protocol buffer ScanRequest for a client Scan
*
* @param regionName
* @param scan
* @param numberOfRows
* @param closeScanner
* @return a scan request
* @throws IOException
*/
public static ScanRequest buildScanRequest(byte[] regionName, Scan scan, int numberOfRows, boolean closeScanner) throws IOException {
ScanRequest.Builder builder = ScanRequest.newBuilder();
RegionSpecifier region = buildRegionSpecifier(RegionSpecifierType.REGION_NAME, regionName);
builder.setNumberOfRows(numberOfRows);
builder.setCloseScanner(closeScanner);
builder.setRegion(region);
builder.setScan(ProtobufUtil.toScan(scan));
builder.setClientHandlesPartials(true);
builder.setClientHandlesHeartbeats(true);
builder.setTrackScanMetrics(scan.isScanMetricsEnabled());
if (scan.getLimit() > 0) {
builder.setLimitOfRows(scan.getLimit());
}
return builder.build();
}
use of org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.ScanRequest in project hbase by apache.
the class AsyncScanSingleRegionRpcRetryingCaller method renewLease.
private void renewLease() {
nextCallSeq++;
resetController(controller, rpcTimeoutNs);
ScanRequest req = RequestConverter.buildScanRequest(scannerId, 0, false, nextCallSeq, false, true, -1);
stub.scan(controller, req, resp -> {
});
}
Aggregations