Search in sources :

Example 16 with ScanRequest

use of org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.ScanRequest in project hbase by apache.

the class TestAsyncTableRpcPriority method setUp.

@Before
public void setUp() throws IOException {
    stub = mock(ClientService.Interface.class);
    AtomicInteger scanNextCalled = new AtomicInteger(0);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            ScanRequest req = invocation.getArgument(1);
            RpcCallback<ScanResponse> done = invocation.getArgument(2);
            if (!req.hasScannerId()) {
                done.run(ScanResponse.newBuilder().setScannerId(1).setTtl(800).setMoreResultsInRegion(true).setMoreResults(true).build());
            } else {
                if (req.hasCloseScanner() && req.getCloseScanner()) {
                    done.run(ScanResponse.getDefaultInstance());
                } else {
                    Cell cell = CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY).setType(Type.Put).setRow(Bytes.toBytes(scanNextCalled.incrementAndGet())).setFamily(Bytes.toBytes("cf")).setQualifier(Bytes.toBytes("cq")).setValue(Bytes.toBytes("v")).build();
                    Result result = Result.create(Arrays.asList(cell));
                    done.run(ScanResponse.newBuilder().setScannerId(1).setTtl(800).setMoreResultsInRegion(true).setMoreResults(true).addResults(ProtobufUtil.toResult(result)).build());
                }
            }
            return null;
        }
    }).when(stub).scan(any(HBaseRpcController.class), any(ScanRequest.class), any());
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            ClientProtos.MultiResponse resp = ClientProtos.MultiResponse.newBuilder().addRegionActionResult(RegionActionResult.newBuilder().addResultOrException(ResultOrException.newBuilder().setResult(ProtobufUtil.toResult(new Result())))).build();
            RpcCallback<ClientProtos.MultiResponse> done = invocation.getArgument(2);
            done.run(resp);
            return null;
        }
    }).when(stub).multi(any(HBaseRpcController.class), any(ClientProtos.MultiRequest.class), any());
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            MutationProto req = ((MutateRequest) invocation.getArgument(1)).getMutation();
            MutateResponse resp;
            switch(req.getMutateType()) {
                case INCREMENT:
                    ColumnValue value = req.getColumnValue(0);
                    QualifierValue qvalue = value.getQualifierValue(0);
                    Cell cell = CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY).setType(Type.Put).setRow(req.getRow().toByteArray()).setFamily(value.getFamily().toByteArray()).setQualifier(qvalue.getQualifier().toByteArray()).setValue(qvalue.getValue().toByteArray()).build();
                    resp = MutateResponse.newBuilder().setResult(ProtobufUtil.toResult(Result.create(Arrays.asList(cell)))).build();
                    break;
                default:
                    resp = MutateResponse.getDefaultInstance();
                    break;
            }
            RpcCallback<MutateResponse> done = invocation.getArgument(2);
            done.run(resp);
            return null;
        }
    }).when(stub).mutate(any(HBaseRpcController.class), any(MutateRequest.class), any());
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            RpcCallback<GetResponse> done = invocation.getArgument(2);
            done.run(GetResponse.getDefaultInstance());
            return null;
        }
    }).when(stub).get(any(HBaseRpcController.class), any(GetRequest.class), any());
    conn = new AsyncConnectionImpl(CONF, new DoNothingConnectionRegistry(CONF), "test", null, UserProvider.instantiate(CONF).getCurrent()) {

        @Override
        AsyncRegionLocator getLocator() {
            AsyncRegionLocator locator = mock(AsyncRegionLocator.class);
            Answer<CompletableFuture<HRegionLocation>> answer = new Answer<CompletableFuture<HRegionLocation>>() {

                @Override
                public CompletableFuture<HRegionLocation> answer(InvocationOnMock invocation) throws Throwable {
                    TableName tableName = invocation.getArgument(0);
                    RegionInfo info = RegionInfoBuilder.newBuilder(tableName).build();
                    ServerName serverName = ServerName.valueOf("rs", 16010, 12345);
                    HRegionLocation loc = new HRegionLocation(info, serverName);
                    return CompletableFuture.completedFuture(loc);
                }
            };
            doAnswer(answer).when(locator).getRegionLocation(any(TableName.class), any(byte[].class), any(RegionLocateType.class), anyLong());
            doAnswer(answer).when(locator).getRegionLocation(any(TableName.class), any(byte[].class), anyInt(), any(RegionLocateType.class), anyLong());
            return locator;
        }

        @Override
        ClientService.Interface getRegionServerStub(ServerName serverName) throws IOException {
            return stub;
        }
    };
}
Also used : MutationProto(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutationProto) RegionActionResult(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.RegionActionResult) MutateResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutateResponse) CompletableFuture(java.util.concurrent.CompletableFuture) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) GetRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.GetRequest) RpcCallback(org.apache.hbase.thirdparty.com.google.protobuf.RpcCallback) Cell(org.apache.hadoop.hbase.Cell) QualifierValue(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutationProto.ColumnValue.QualifierValue) MutateRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutateRequest) IOException(java.io.IOException) ScanRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.ScanRequest) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(org.mockito.stubbing.Answer) TableName(org.apache.hadoop.hbase.TableName) HBaseRpcController(org.apache.hadoop.hbase.ipc.HBaseRpcController) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ServerName(org.apache.hadoop.hbase.ServerName) ColumnValue(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutationProto.ColumnValue) ClientProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos) Before(org.junit.Before)

Example 17 with ScanRequest

use of org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.ScanRequest in project hbase by apache.

the class AsyncScanSingleRegionRpcRetryingCaller method call.

private void call() {
    // As we have a call sequence for scan, it is useless to have a different rpc timeout which is
    // less than the scan timeout. If the server does not respond in time(usually this will not
    // happen as we have heartbeat now), we will get an OutOfOrderScannerNextException when
    // resending the next request and the only way to fix this is to close the scanner and open a
    // new one.
    long callTimeoutNs;
    if (scanTimeoutNs > 0) {
        long remainingNs = scanTimeoutNs - (System.nanoTime() - nextCallStartNs);
        if (remainingNs <= 0) {
            completeExceptionally(true);
            return;
        }
        callTimeoutNs = remainingNs;
    } else {
        callTimeoutNs = 0L;
    }
    incRPCCallsMetrics(scanMetrics, regionServerRemote);
    if (tries > 1) {
        incRPCRetriesMetrics(scanMetrics, regionServerRemote);
    }
    resetController(controller, callTimeoutNs, priority);
    ScanRequest req = RequestConverter.buildScanRequest(scannerId, scan.getCaching(), false, nextCallSeq, scan.isScanMetricsEnabled(), false, scan.getLimit());
    stub.scan(controller, req, resp -> onComplete(controller, resp));
}
Also used : ScanRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.ScanRequest)

Example 18 with ScanRequest

use of org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.ScanRequest in project hbase by apache.

the class AsyncScanSingleRegionRpcRetryingCaller method renewLease.

private void renewLease() {
    incRPCCallsMetrics(scanMetrics, regionServerRemote);
    nextCallSeq++;
    resetController(controller, rpcTimeoutNs, priority);
    ScanRequest req = RequestConverter.buildScanRequest(scannerId, 0, false, nextCallSeq, false, true, -1);
    stub.scan(controller, req, resp -> {
    });
}
Also used : ScanRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.ScanRequest)

Example 19 with ScanRequest

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 = mock(HRegion.class);
    RSRpcServices mockRpc = mock(RSRpcServices.class);
    when(mockRpc.getConfiguration()).thenReturn(CONF);
    RegionInfo mockRegionInfo = mock(RegionInfo.class);
    when(mockRpc.getRegion(any())).thenReturn(mockRegion);
    when(mockRegion.getRegionInfo()).thenReturn(mockRegionInfo);
    // make isSystemTable return false
    when(mockRegionInfo.getTable()).thenReturn(TableName.valueOf("testQosFunctionForScanMethod"));
    RSAnnotationReadingPriorityFunction qosFunc = new RSAnnotationReadingPriorityFunction(mockRpc);
    final int qos = qosFunc.getPriority(header, scanRequest, createSomeUser());
    assertEquals(Integer.toString(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 = mock(RegionScanner.class);
    when(mockRpc.getScanner(12345)).thenReturn(mockRegionScanner);
    when(mockRegionScanner.getRegionInfo()).thenReturn(mockRegionInfo);
    when(mockRpc.getRegion((RegionSpecifier) any())).thenReturn(mockRegion);
    when(mockRegion.getRegionInfo()).thenReturn(mockRegionInfo);
    when(mockRegionInfo.getTable()).thenReturn(RegionInfoBuilder.FIRST_META_REGIONINFO.getTable());
    assertEquals(HConstants.SYSTEMTABLE_QOS, qosFunc.getPriority(header, scanRequest, createSomeUser()));
    // the same as above but with non-meta region
    // make isSystemTable return false
    when(mockRegionInfo.getTable()).thenReturn(TableName.valueOf("testQosFunctionForScanMethod"));
    assertEquals(HConstants.NORMAL_QOS, qosFunc.getPriority(header, scanRequest, createSomeUser()));
}
Also used : ScanRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.ScanRequest) RequestHeader(org.apache.hadoop.hbase.shaded.protobuf.generated.RPCProtos.RequestHeader) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) Test(org.junit.Test)

Aggregations

ScanRequest (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.ScanRequest)19 IOException (java.io.IOException)6 ScanResponse (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.ScanResponse)5 HBaseRpcController (org.apache.hadoop.hbase.ipc.HBaseRpcController)4 Test (org.junit.Test)4 InterruptedIOException (java.io.InterruptedIOException)3 UnknownHostException (java.net.UnknownHostException)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)3 HBaseIOException (org.apache.hadoop.hbase.HBaseIOException)3 HRegionLocation (org.apache.hadoop.hbase.HRegionLocation)3 NotServingRegionException (org.apache.hadoop.hbase.NotServingRegionException)3 TableName (org.apache.hadoop.hbase.TableName)3 UnknownScannerException (org.apache.hadoop.hbase.UnknownScannerException)3 ScannerResetException (org.apache.hadoop.hbase.exceptions.ScannerResetException)3 RegionServerStoppedException (org.apache.hadoop.hbase.regionserver.RegionServerStoppedException)3 GetRequest (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.GetRequest)3 MutateRequest (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutateRequest)3 MutationProto (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutationProto)3 RegionSpecifier (org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RegionSpecifier)3