@Override public ClientProtos.ClientService.BlockingInterface getClientProtocol(ServerName serverName) throws IOException { return ((ClusterConnection)this.connection).getClient(serverName); }
@Override protected void setStubByServiceName(ServerName serviceName) throws IOException { setStub(getConnection().getClient(serviceName)); }
@Override protected void setStubByServiceName(ServerName serviceName) throws IOException { setStub(getConnection().getClient(serviceName)); }
@Override public void prepare(boolean reload) throws IOException { // Use the location we were given in the constructor rather than go look it up. setStub(getConnection().getClient(this.location.getServerName())); }
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; }
@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); } } };
/** * @param reload force reload of server location * @throws IOException */ @Override public void prepare(boolean reload) throws IOException { if (Thread.interrupted()) { throw new InterruptedIOException(); } RegionLocations rl = RpcRetryingCallerWithReadReplicas.getRegionLocations(!reload, id, getConnection(), getTableName(), getRow()); location = id < rl.size() ? rl.getRegionLocation(id) : null; if (location == null || location.getServerName() == null) { // With this exception, there will be a retry. The location can be null for a replica // when the table is created or after a split. throw new HBaseIOException("There is no location for replica id #" + id); } ServerName dest = location.getServerName(); setStub(super.getConnection().getClient(dest)); if (!instantiated || reload) { checkIfRegionServerIsRemote(); instantiated = true; } cursor = null; // check how often we retry. if (reload) { incRPCRetriesMetrics(scanMetrics, isRegionServerRemote); } }
setStub(getConnection().getClient(getLocation().getServerName())); checkIfRegionServerIsRemote(); instantiated = true;
when(connection).getClient(Mockito.any());
@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); } }
@Override protected void setStubByServiceName(ServerName serviceName) throws IOException { setStub(getConnection().getClient(serviceName)); }
@Override protected void setStubByServiceName(ServerName serviceName) throws IOException { setStub(getConnection().getClient(serviceName)); }
@Override public void prepare(boolean reload) throws IOException { // Use the location we were given in the constructor rather than go look it up. setStub(getConnection().getClient(this.location.getServerName())); }
@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); } } };
@Override public ClientService.BlockingInterface getClient( ServerName serverName) throws IOException { return wrappedConnection.getClient(serverName); }
/** * @param reload force reload of server location * @throws IOException */ @Override public void prepare(boolean reload) throws IOException { if (Thread.interrupted()) { throw new InterruptedIOException(); } RegionLocations rl = RpcRetryingCallerWithReadReplicas.getRegionLocations(!reload, id, getConnection(), getTableName(), getRow()); location = id < rl.size() ? rl.getRegionLocation(id) : null; if (location == null || location.getServerName() == null) { // With this exception, there will be a retry. The location can be null for a replica // when the table is created or after a split. throw new HBaseIOException("There is no location for replica id #" + id); } ServerName dest = location.getServerName(); setStub(super.getConnection().getClient(dest)); if (!instantiated || reload) { checkIfRegionServerIsRemote(); instantiated = true; } cursor = null; // check how often we retry. if (reload) { incRPCRetriesMetrics(scanMetrics, isRegionServerRemote); } }
setStub(getConnection().getClient(getLocation().getServerName())); checkIfRegionServerIsRemote(); instantiated = true;
@Override protected void setStubByServiceName(ServerName serviceName) throws IOException { setStub(getConnection().getClient(serviceName)); }
@Override protected void setStubByServiceName(ServerName serviceName) throws IOException { setStub(getConnection().getClient(serviceName)); }
@Override public void prepare(boolean reload) throws IOException { // Use the location we were given in the constructor rather than go look it up. setStub(getConnection().getClient(this.location.getServerName())); }