Search in sources :

Example 11 with ScanRequest

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

the class TestMetaTableAccessorNoCluster method testRideOverServerNotRunning.

/**
   * Test that MetaTableAccessor will ride over server throwing
   * "Server not running" IOEs.
   * @see @link {https://issues.apache.org/jira/browse/HBASE-3446}
   * @throws IOException
   * @throws InterruptedException
   */
@Test
public void testRideOverServerNotRunning() throws IOException, InterruptedException, ServiceException {
    // Need a zk watcher.
    ZooKeeperWatcher zkw = new ZooKeeperWatcher(UTIL.getConfiguration(), this.getClass().getSimpleName(), ABORTABLE, true);
    // This is a servername we use in a few places below.
    ServerName sn = ServerName.valueOf("example.com", 1234, System.currentTimeMillis());
    ClusterConnection connection = null;
    try {
        // Mock an ClientProtocol. Our mock implementation will fail a few
        // times when we go to open a scanner.
        final ClientProtos.ClientService.BlockingInterface implementation = Mockito.mock(ClientProtos.ClientService.BlockingInterface.class);
        // When scan called throw IOE 'Server not running' a few times
        // before we return a scanner id.  Whats WEIRD is that these
        // exceptions do not show in the log because they are caught and only
        // printed if we FAIL.  We eventually succeed after retry so these don't
        // show.  We will know if they happened or not because we will ask
        // mockito at the end of this test to verify that scan was indeed
        // called the wanted number of times.
        List<Cell> kvs = new ArrayList<>();
        final byte[] rowToVerify = Bytes.toBytes("rowToVerify");
        kvs.add(new KeyValue(rowToVerify, HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER, HRegionInfo.FIRST_META_REGIONINFO.toByteArray()));
        kvs.add(new KeyValue(rowToVerify, HConstants.CATALOG_FAMILY, HConstants.SERVER_QUALIFIER, Bytes.toBytes(sn.getHostAndPort())));
        kvs.add(new KeyValue(rowToVerify, HConstants.CATALOG_FAMILY, HConstants.STARTCODE_QUALIFIER, Bytes.toBytes(sn.getStartcode())));
        final List<CellScannable> cellScannables = new ArrayList<>(1);
        cellScannables.add(Result.create(kvs));
        final ScanResponse.Builder builder = ScanResponse.newBuilder();
        for (CellScannable result : cellScannables) {
            builder.addCellsPerResult(((Result) result).size());
        }
        Mockito.when(implementation.scan((RpcController) Mockito.any(), (ScanRequest) Mockito.any())).thenThrow(new ServiceException("Server not running (1 of 3)")).thenThrow(new ServiceException("Server not running (2 of 3)")).thenThrow(new ServiceException("Server not running (3 of 3)")).thenAnswer(new Answer<ScanResponse>() {

            public ScanResponse answer(InvocationOnMock invocation) throws Throwable {
                ((HBaseRpcController) invocation.getArguments()[0]).setCellScanner(CellUtil.createCellScanner(cellScannables));
                return builder.setScannerId(1234567890L).setMoreResults(false).build();
            }
        });
        // Associate a spied-upon Connection with UTIL.getConfiguration.  Need
        // to shove this in here first so it gets picked up all over; e.g. by
        // HTable.
        connection = HConnectionTestingUtility.getSpiedConnection(UTIL.getConfiguration());
        // Fix the location lookup so it 'works' though no network.  First
        // make an 'any location' object.
        final HRegionLocation anyLocation = new HRegionLocation(HRegionInfo.FIRST_META_REGIONINFO, sn);
        final RegionLocations rl = new RegionLocations(anyLocation);
        // Return the RegionLocations object when locateRegion
        // The ugly format below comes of 'Important gotcha on spying real objects!' from
        // http://mockito.googlecode.com/svn/branches/1.6/javadoc/org/mockito/Mockito.html
        Mockito.doReturn(rl).when(connection).locateRegion((TableName) Mockito.any(), (byte[]) Mockito.any(), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anyInt());
        // Now shove our HRI implementation into the spied-upon connection.
        Mockito.doReturn(implementation).when(connection).getClient(Mockito.any(ServerName.class));
        // Scan meta for user tables and verify we got back expected answer.
        NavigableMap<HRegionInfo, Result> hris = MetaTableAccessor.getServerUserRegions(connection, sn);
        assertEquals(1, hris.size());
        assertTrue(hris.firstEntry().getKey().equals(HRegionInfo.FIRST_META_REGIONINFO));
        assertTrue(Bytes.equals(rowToVerify, hris.firstEntry().getValue().getRow()));
        // Finally verify that scan was called four times -- three times
        // with exception and then on 4th attempt we succeed
        Mockito.verify(implementation, Mockito.times(4)).scan((RpcController) Mockito.any(), (ScanRequest) Mockito.any());
    } finally {
        if (connection != null && !connection.isClosed())
            connection.close();
        zkw.close();
    }
}
Also used : ArrayList(java.util.ArrayList) Result(org.apache.hadoop.hbase.client.Result) ClusterConnection(org.apache.hadoop.hbase.client.ClusterConnection) ZooKeeperWatcher(org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher) ScanResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.ScanResponse) HBaseRpcController(org.apache.hadoop.hbase.ipc.HBaseRpcController) RpcController(org.apache.hadoop.hbase.shaded.com.google.protobuf.RpcController) ScanRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.ScanRequest) ServiceException(org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Test(org.junit.Test)

Example 12 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 = 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)

Aggregations

ScanRequest (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.ScanRequest)12 IOException (java.io.IOException)4 InterruptedIOException (java.io.InterruptedIOException)3 UnknownHostException (java.net.UnknownHostException)3 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)3 HBaseIOException (org.apache.hadoop.hbase.HBaseIOException)3 NotServingRegionException (org.apache.hadoop.hbase.NotServingRegionException)3 UnknownScannerException (org.apache.hadoop.hbase.UnknownScannerException)3 ScannerResetException (org.apache.hadoop.hbase.exceptions.ScannerResetException)3 RegionServerStoppedException (org.apache.hadoop.hbase.regionserver.RegionServerStoppedException)3 ScanResponse (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.ScanResponse)3 RegionSpecifier (org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.RegionSpecifier)2 Test (org.junit.Test)2 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)1 HRegionLocation (org.apache.hadoop.hbase.HRegionLocation)1 TableName (org.apache.hadoop.hbase.TableName)1 ClusterConnection (org.apache.hadoop.hbase.client.ClusterConnection)1