@Override public AdminProtos.AdminService.BlockingInterface getAdminProtocol(ServerName serverName) throws IOException { return ((ClusterConnection)this.connection).getAdmin(serverName); }
/** * Explicitly clears the region cache to fetch the latest value from META. * This is a power user function: avoid unless you know the ramifications. */ public void clearRegionCache() { this.connection.clearRegionCache(); }
private ClusterConnection getMockedConnection(final Configuration conf) throws IOException, org.apache.hbase.thirdparty.com.google.protobuf.ServiceException { ClusterConnection c = Mockito.mock(ClusterConnection.class); Mockito.when(c.getConfiguration()).thenReturn(conf); Mockito.doNothing().when(c).close(); // Make it so we return a particular location when asked. final HRegionLocation loc = new HRegionLocation(RegionInfoBuilder.FIRST_META_REGIONINFO, ServerName.valueOf("example.org", 1234, 0)); Mockito.when( c.getRegionLocation((TableName) Mockito.any(), (byte[]) Mockito.any(), Mockito.anyBoolean())) .thenReturn(loc); Mockito.when(c.locateRegion((TableName) Mockito.any(), (byte[]) Mockito.any())).thenReturn(loc); ClientProtos.ClientService.BlockingInterface hri = Mockito.mock(ClientProtos.ClientService.BlockingInterface.class); Mockito .when( hri.bulkLoadHFile((RpcController) Mockito.any(), (BulkLoadHFileRequest) Mockito.any())) .thenThrow(new ServiceException(new IOException("injecting bulk load error"))); Mockito.when(c.getClient(Mockito.any())).thenReturn(hri); return c; }
HBaseAdmin(ClusterConnection connection) throws IOException { this.conf = connection.getConfiguration(); this.connection = connection; // TODO: receive ConnectionConfiguration here rather than re-parsing these configs every time. this.pause = this.conf.getLong(HConstants.HBASE_CLIENT_PAUSE, HConstants.DEFAULT_HBASE_CLIENT_PAUSE); this.numRetries = this.conf.getInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER); this.operationTimeout = this.conf.getInt(HConstants.HBASE_CLIENT_OPERATION_TIMEOUT, HConstants.DEFAULT_HBASE_CLIENT_OPERATION_TIMEOUT); this.rpcTimeout = this.conf.getInt(HConstants.HBASE_RPC_TIMEOUT_KEY, HConstants.DEFAULT_HBASE_RPC_TIMEOUT); this.syncWaitTimeout = this.conf.getInt( "hbase.client.sync.wait.timeout.msec", 10 * 60000); // 10min this.getProcedureTimeout = this.conf.getInt("hbase.client.procedure.future.get.timeout.msec", 10 * 60000); // 10min this.rpcCallerFactory = connection.getRpcRetryingCallerFactory(); this.rpcControllerFactory = connection.getRpcControllerFactory(); this.ng = this.connection.getNonceGenerator(); }
static RegionLocations getRegionLocations(boolean useCache, int replicaId, ClusterConnection cConnection, TableName tableName, byte[] row) throws RetriesExhaustedException, DoNotRetryIOException, InterruptedIOException { RegionLocations rl; try { if (useCache) { rl = cConnection.locateRegion(tableName, row, true, true, replicaId); } else { rl = cConnection.relocateRegion(tableName, row, replicaId); } } catch (DoNotRetryIOException | InterruptedIOException | RetriesExhaustedException e) { throw e; } catch (IOException e) { throw new RetriesExhaustedException("Can't get the location for replica " + replicaId, e); } if (rl == null) { throw new RetriesExhaustedException("Can't get the location for replica " + replicaId); } return rl; } }
private ClusterConnection createHConnectionCommon() { ClusterConnection hc = Mockito.mock(ClusterConnection.class); NonceGenerator ng = Mockito.mock(NonceGenerator.class); Mockito.when(ng.getNonceGroup()).thenReturn(HConstants.NO_NONCE); Mockito.when(hc.getNonceGenerator()).thenReturn(ng); Mockito.when(hc.getConfiguration()).thenReturn(CONF); Mockito.when(hc.getConnectionConfiguration()).thenReturn(CONNECTION_CONFIG); return hc; }
AdminService.BlockingInterface rs = connection.getAdmin(server); HBaseRpcController controller = connection.getRpcControllerFactory().newController(); try { ProtobufUtil.closeRegion(controller, rs, server, region.getRegionName());
private static ClusterConnection createHConnection() throws IOException { ClusterConnection hc = Mockito.mock(ClusterConnection.class); NonceGenerator ng = Mockito.mock(NonceGenerator.class); Mockito.when(ng.getNonceGroup()).thenReturn(HConstants.NO_NONCE); Mockito.when(hc.getNonceGenerator()).thenReturn(ng); Mockito.when(hc.getConfiguration()).thenReturn(CONF); Mockito.when(hc.getConnectionConfiguration()).thenReturn(new ConnectionConfiguration(CONF)); setMockLocation(hc, GOOD_ROW, new RegionLocations(REGION_LOCATION)); setMockLocation(hc, BAD_ROW, new RegionLocations(REGION_LOCATION)); Mockito .when(hc.locateRegions(Mockito.eq(DUMMY_TABLE), Mockito.anyBoolean(), Mockito.anyBoolean())) .thenReturn(Collections.singletonList(REGION_LOCATION)); return hc; }
(connection).locateRegion((TableName)Mockito.any(), (byte[])Mockito.any(), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anyInt()); when(connection).getClient(Mockito.any()); scan((RpcController)Mockito.any(), (ScanRequest)Mockito.any()); } finally { if (connection != null && !connection.isClosed()) connection.close(); zkw.close();
switch (compactType) { case MOB: compact(this.connection.getAdminForMaster(), RegionInfo.createMobRegionInfo(tableName), major, columnFamily); break; case NORMAL: checkTableExists(tableName); for (HRegionLocation loc :connection.locateRegions(tableName, false, false)) { ServerName sn = loc.getServerName(); if (sn == null) { compact(this.connection.getAdmin(sn), loc.getRegion(), major, columnFamily); } catch (NotServingRegionException e) { if (LOG.isDebugEnabled()) {
Admin admin = conn.getAdmin(); HTable table = (HTable) conn.getTable(tn); try { ColumnFamilyDescriptorBuilder cfDescBuilder = table.put(put); conn.clearRegionCache();
@Test @SuppressWarnings("deprecation") public void testShortCircuitConnection() throws IOException, InterruptedException { final TableName tableName = TableName.valueOf(name.getMethodName()); HTableDescriptor htd = UTIL.createTableDescriptor(tableName); HColumnDescriptor hcd = new HColumnDescriptor(Bytes.toBytes("cf")); htd.addFamily(hcd); UTIL.createTable(htd, null); HRegionServer regionServer = UTIL.getRSForFirstRegionInTable(tableName); ClusterConnection connection = regionServer.getClusterConnection(); Table tableIf = connection.getTable(tableName); assertTrue(tableIf instanceof HTable); HTable table = (HTable) tableIf; assertTrue(table.getConnection() == connection); AdminService.BlockingInterface admin = connection.getAdmin(regionServer.getServerName()); ClientService.BlockingInterface client = connection.getClient(regionServer.getServerName()); assertTrue(admin instanceof RSRpcServices); assertTrue(client instanceof RSRpcServices); ServerName anotherSn = ServerName.valueOf(regionServer.getServerName().getHostAndPort(), EnvironmentEdgeManager.currentTime()); admin = connection.getAdmin(anotherSn); client = connection.getClient(anotherSn); assertFalse(admin instanceof RSRpcServices); assertFalse(client instanceof RSRpcServices); assertTrue(connection.getAdmin().getConnection() == connection); } }
protected Table createTable() throws IOException { return connection.getTable(tableName); }
when(connection.getConfiguration()).thenReturn(configuration); MasterKeepAliveConnection masterAdmin = Mockito.mock(MasterKeepAliveConnection.class, new Answer() { Mockito.when(connection.getMaster()).thenReturn(masterAdmin); RpcControllerFactory rpcControllerFactory = Mockito.mock(RpcControllerFactory.class); Mockito.when(connection.getRpcControllerFactory()).thenReturn(rpcControllerFactory); Mockito.when(rpcControllerFactory.newController()).thenReturn( Mockito.mock(HBaseRpcController.class)); Mockito.when(connection.getRpcRetryingCallerFactory()).thenReturn(callerFactory);
public void close() { if (connection != null) { try { connection.close(); } catch (Exception ex) { LOG.warn("Could not close the connection: " + ex); } } }
@Test public void testPrepareDoesNotUseCache() throws Exception { TableName tableName = TableName.valueOf("MyTable"); Mockito.when(connection.relocateRegion(tableName, ROW, 0)).thenReturn(regionLocations); ReversedScannerCallable callable = new ReversedScannerCallable(connection, tableName, scan, null, rpcFactory); callable.prepare(true); Mockito.verify(connection).relocateRegion(tableName, ROW, 0); }
@Test public void testPrepareUsesCache() throws Exception { TableName tableName = TableName.valueOf("MyTable"); Mockito.when(connection.locateRegion(tableName, ROW, true, true, 0)) .thenReturn(regionLocations); ReversedScannerCallable callable = new ReversedScannerCallable(connection, tableName, scan, null, rpcFactory); callable.prepare(false); Mockito.verify(connection).locateRegion(tableName, ROW, true, true, 0); } }
private ClusterConnection createHConnectionWithReplicas() throws IOException { ClusterConnection hc = createHConnectionCommon(); setMockLocation(hc, DUMMY_BYTES_1, hrls1); setMockLocation(hc, DUMMY_BYTES_2, hrls2); setMockLocation(hc, DUMMY_BYTES_3, hrls3); List<HRegionLocation> locations = new ArrayList<>(); for (HRegionLocation loc : hrls1.getRegionLocations()) { locations.add(loc); } for (HRegionLocation loc : hrls2.getRegionLocations()) { locations.add(loc); } for (HRegionLocation loc : hrls3.getRegionLocations()) { locations.add(loc); } Mockito.when(hc.locateRegions(Mockito.eq(DUMMY_TABLE), Mockito.anyBoolean(), Mockito.anyBoolean())).thenReturn(locations); return hc; }
@Override public ClientProtos.ClientService.BlockingInterface getClientProtocol(ServerName serverName) throws IOException { return ((ClusterConnection)this.connection).getClient(serverName); }
@Override protected Message callExecService(RpcController controller, Descriptors.MethodDescriptor method, Message request, Message responsePrototype) throws IOException { if (LOG.isTraceEnabled()) { LOG.trace("Call: " + method.getName() + ", " + request.toString()); } CoprocessorServiceRequest csr = CoprocessorRpcUtils.getCoprocessorServiceRequest(method, request); // TODO: Are we retrying here? Does not seem so. We should use RetryingRpcCaller // TODO: Make this same as RegionCoprocessorRpcChannel and MasterCoprocessorRpcChannel. They // are all different though should do same thing; e.g. RpcChannel setup. ClientProtos.ClientService.BlockingInterface stub = connection.getClient(serverName); CoprocessorServiceResponse result; try { result = stub. execRegionServerService(connection.getRpcControllerFactory().newController(), csr); return CoprocessorRpcUtils.getResponse(result, responsePrototype); } catch (ServiceException e) { throw ProtobufUtil.handleRemoteException(e); } } };