Search in sources :

Example 6 with RequestHeader

use of org.apache.hadoop.hbase.shaded.protobuf.generated.RPCProtos.RequestHeader in project hbase by apache.

the class TestSimpleRpcScheduler method testScanQueues.

@Test
public void testScanQueues() throws Exception {
    Configuration schedConf = HBaseConfiguration.create();
    schedConf.setFloat(RpcExecutor.CALL_QUEUE_HANDLER_FACTOR_CONF_KEY, 1.0f);
    schedConf.setFloat(RWQueueRpcExecutor.CALL_QUEUE_READ_SHARE_CONF_KEY, 0.7f);
    schedConf.setFloat(RWQueueRpcExecutor.CALL_QUEUE_SCAN_SHARE_CONF_KEY, 0.5f);
    PriorityFunction priority = mock(PriorityFunction.class);
    when(priority.getPriority(any(RPCProtos.RequestHeader.class), any(Message.class), any(User.class))).thenReturn(HConstants.NORMAL_QOS);
    RpcScheduler scheduler = new SimpleRpcScheduler(schedConf, 3, 1, 1, priority, HConstants.QOS_THRESHOLD);
    try {
        scheduler.start();
        CallRunner putCallTask = mock(CallRunner.class);
        RpcServer.Call putCall = mock(RpcServer.Call.class);
        putCall.param = RequestConverter.buildMutateRequest(Bytes.toBytes("abc"), new Put(Bytes.toBytes("row")));
        RequestHeader putHead = RequestHeader.newBuilder().setMethodName("mutate").build();
        when(putCallTask.getRpcCall()).thenReturn(putCall);
        when(putCall.getHeader()).thenReturn(putHead);
        when(putCall.getParam()).thenReturn(putCall.param);
        CallRunner getCallTask = mock(CallRunner.class);
        RpcServer.Call getCall = mock(RpcServer.Call.class);
        RequestHeader getHead = RequestHeader.newBuilder().setMethodName("get").build();
        when(getCallTask.getRpcCall()).thenReturn(getCall);
        when(getCall.getHeader()).thenReturn(getHead);
        CallRunner scanCallTask = mock(CallRunner.class);
        RpcServer.Call scanCall = mock(RpcServer.Call.class);
        scanCall.param = ScanRequest.newBuilder().setScannerId(1).build();
        RequestHeader scanHead = RequestHeader.newBuilder().setMethodName("scan").build();
        when(scanCallTask.getRpcCall()).thenReturn(scanCall);
        when(scanCall.getHeader()).thenReturn(scanHead);
        when(scanCall.getParam()).thenReturn(scanCall.param);
        ArrayList<Integer> work = new ArrayList<>();
        doAnswerTaskExecution(putCallTask, work, 1, 1000);
        doAnswerTaskExecution(getCallTask, work, 2, 1000);
        doAnswerTaskExecution(scanCallTask, work, 3, 1000);
        // There are 3 queues: [puts], [gets], [scans]
        // so the calls will be interleaved
        scheduler.dispatch(putCallTask);
        scheduler.dispatch(putCallTask);
        scheduler.dispatch(putCallTask);
        scheduler.dispatch(getCallTask);
        scheduler.dispatch(getCallTask);
        scheduler.dispatch(getCallTask);
        scheduler.dispatch(scanCallTask);
        scheduler.dispatch(scanCallTask);
        scheduler.dispatch(scanCallTask);
        while (work.size() < 6) {
            Thread.sleep(100);
        }
        for (int i = 0; i < work.size() - 2; i += 3) {
            assertNotEquals(work.get(i + 0), work.get(i + 1));
            assertNotEquals(work.get(i + 0), work.get(i + 2));
            assertNotEquals(work.get(i + 1), work.get(i + 2));
        }
    } finally {
        scheduler.stop();
    }
}
Also used : User(org.apache.hadoop.hbase.security.User) Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) Message(org.apache.hadoop.hbase.shaded.com.google.protobuf.Message) ArrayList(java.util.ArrayList) Put(org.apache.hadoop.hbase.client.Put) RequestHeader(org.apache.hadoop.hbase.shaded.protobuf.generated.RPCProtos.RequestHeader) Call(org.apache.hadoop.hbase.ipc.RpcServer.Call) Test(org.junit.Test)

Example 7 with RequestHeader

use of org.apache.hadoop.hbase.shaded.protobuf.generated.RPCProtos.RequestHeader 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" })));
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) ScanRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.ScanRequest) RequestHeader(org.apache.hadoop.hbase.shaded.protobuf.generated.RPCProtos.RequestHeader) ByteString(org.apache.hadoop.hbase.shaded.com.google.protobuf.ByteString) Test(org.junit.Test)

Example 8 with RequestHeader

use of org.apache.hadoop.hbase.shaded.protobuf.generated.RPCProtos.RequestHeader in project hbase by apache.

the class TestPriorityRpc method testQosFunctionForMeta.

@Test
public void testQosFunctionForMeta() throws IOException {
    priority = regionServer.rpcServices.getPriority();
    RequestHeader.Builder headerBuilder = RequestHeader.newBuilder();
    //create a rpc request that has references to hbase:meta region and also
    //uses one of the known argument classes (known argument classes are
    //listed in HRegionServer.QosFunctionImpl.knownArgumentClasses)
    headerBuilder.setMethodName("foo");
    GetRequest.Builder getRequestBuilder = GetRequest.newBuilder();
    RegionSpecifier.Builder regionSpecifierBuilder = RegionSpecifier.newBuilder();
    regionSpecifierBuilder.setType(RegionSpecifierType.REGION_NAME);
    ByteString name = UnsafeByteOperations.unsafeWrap(HRegionInfo.FIRST_META_REGIONINFO.getRegionName());
    regionSpecifierBuilder.setValue(name);
    RegionSpecifier regionSpecifier = regionSpecifierBuilder.build();
    getRequestBuilder.setRegion(regionSpecifier);
    Get.Builder getBuilder = Get.newBuilder();
    getBuilder.setRow(UnsafeByteOperations.unsafeWrap("somerow".getBytes()));
    getRequestBuilder.setGet(getBuilder.build());
    GetRequest getRequest = getRequestBuilder.build();
    RequestHeader header = headerBuilder.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(true);
    // Presume type.
    ((AnnotationReadingPriorityFunction) priority).setRegionServer(mockRS);
    assertEquals(HConstants.SYSTEMTABLE_QOS, priority.getPriority(header, getRequest, User.createUserForTesting(regionServer.conf, "someuser", new String[] { "somegroup" })));
}
Also used : ByteString(org.apache.hadoop.hbase.shaded.com.google.protobuf.ByteString) RegionSpecifier(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RegionSpecifier) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) GetRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.GetRequest) Get(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.Get) RequestHeader(org.apache.hadoop.hbase.shaded.protobuf.generated.RPCProtos.RequestHeader) Test(org.junit.Test)

Aggregations

RequestHeader (org.apache.hadoop.hbase.shaded.protobuf.generated.RPCProtos.RequestHeader)8 Test (org.junit.Test)5 Configuration (org.apache.hadoop.conf.Configuration)3 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)3 Call (org.apache.hadoop.hbase.ipc.RpcServer.Call)3 User (org.apache.hadoop.hbase.security.User)3 Message (org.apache.hadoop.hbase.shaded.com.google.protobuf.Message)3 ArrayList (java.util.ArrayList)2 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)2 Put (org.apache.hadoop.hbase.client.Put)2 ByteString (org.apache.hadoop.hbase.shaded.com.google.protobuf.ByteString)2 CellBlockMeta (org.apache.hadoop.hbase.shaded.protobuf.generated.RPCProtos.CellBlockMeta)2 ByteBuf (io.netty.buffer.ByteBuf)1 ByteBufOutputStream (io.netty.buffer.ByteBufOutputStream)1 ChannelPromise (io.netty.channel.ChannelPromise)1 PromiseCombiner (io.netty.util.concurrent.PromiseCombiner)1 IOException (java.io.IOException)1 InterruptedIOException (java.io.InterruptedIOException)1 ByteBuffer (java.nio.ByteBuffer)1 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)1