@Override public Hbck getHbck(ServerName masterServer) throws IOException { // we will not create a new connection when creating a new protobuf stub, and for hbck there // will be no performance consideration, so for simplification we will create a new stub every // time instead of caching the stub here. return new HBaseHbck(MasterProtos.HbckService.newBlockingStub( rpcClient.createBlockingRpcChannel(masterServer, user, rpcTimeout)), rpcControllerFactory); } }
public static BlockingInterface newBlockingStub(RpcClient client, InetSocketAddress addr, User user) throws IOException { return TestProtobufRpcProto.newBlockingStub(client.createBlockingRpcChannel( ServerName.valueOf(addr.getHostName(), addr.getPort(), System.currentTimeMillis()), user, 0)); }
@Override public AdminProtos.AdminService.BlockingInterface getAdmin(ServerName serverName) throws IOException { checkClosed(); if (isDeadServer(serverName)) { throw new RegionServerStoppedException(serverName + " is dead."); } String key = getStubKey(AdminProtos.AdminService.BlockingInterface.class.getName(), serverName, this.hostnamesCanChange); return (AdminProtos.AdminService.BlockingInterface) computeIfAbsentEx(stubs, key, () -> { BlockingRpcChannel channel = this.rpcClient.createBlockingRpcChannel(serverName, user, rpcTimeout); return AdminProtos.AdminService.newBlockingStub(channel); }); }
@Override public BlockingInterface getClient(ServerName serverName) throws IOException { checkClosed(); if (isDeadServer(serverName)) { throw new RegionServerStoppedException(serverName + " is dead."); } String key = getStubKey(ClientProtos.ClientService.BlockingInterface.class.getName(), serverName, this.hostnamesCanChange); return (ClientProtos.ClientService.BlockingInterface) computeIfAbsentEx(stubs, key, () -> { BlockingRpcChannel channel = this.rpcClient.createBlockingRpcChannel(serverName, user, rpcTimeout); return ClientProtos.ClientService.newBlockingStub(channel); }); }
@Override public Hbck getHbck(ServerName masterServer) throws IOException { checkClosed(); if (isDeadServer(masterServer)) { throw new RegionServerStoppedException(masterServer + " is dead."); } String key = getStubKey(MasterProtos.HbckService.BlockingInterface.class.getName(), masterServer, this.hostnamesCanChange); return new HBaseHbck( (MasterProtos.HbckService.BlockingInterface) computeIfAbsentEx(stubs, key, () -> { BlockingRpcChannel channel = this.rpcClient.createBlockingRpcChannel(masterServer, user, rpcTimeout); return MasterProtos.HbckService.newBlockingStub(channel); }), rpcControllerFactory); }
this.rpcClient.createBlockingRpcChannel(sn, userProvider.getCurrent(), shortOperationTimeout); intRssStub = RegionServerStatusService.newBlockingStub(channel);
/** * Create a stub. Try once only. It is not typed because there is no common type to protobuf * services nor their interfaces. Let the caller do appropriate casting. * @return A stub for master services. */ private MasterProtos.MasterService.BlockingInterface makeStubNoRetries() throws IOException, KeeperException { ServerName sn = get(registry.getMasterAddress()); if (sn == null) { String msg = "ZooKeeper available but no active master location found"; LOG.info(msg); throw new MasterNotRunningException(msg); } if (isDeadServer(sn)) { throw new MasterNotRunningException(sn + " is dead."); } // Use the security info interface name as our stub key String key = getStubKey(MasterProtos.MasterService.getDescriptor().getName(), sn, hostnamesCanChange); MasterProtos.MasterService.BlockingInterface stub = (MasterProtos.MasterService.BlockingInterface) computeIfAbsentEx(stubs, key, () -> { BlockingRpcChannel channel = rpcClient.createBlockingRpcChannel(sn, user, rpcTimeout); return MasterProtos.MasterService.newBlockingStub(channel); }); isMasterRunning(stub); return stub; }
@Test public void testRPCException() throws IOException, InterruptedException, KeeperException { ServerName sm = master.getServerName(); boolean fakeZNodeDelete = false; for (int i = 0; i < 20; i++) { try { BlockingRpcChannel channel = rpcClient.createBlockingRpcChannel(sm, User.getCurrent(), 0); MasterProtos.MasterService.BlockingInterface stub = MasterProtos.MasterService.newBlockingStub(channel); assertTrue(stub.isMasterRunning(null, IsMasterRunningRequest.getDefaultInstance()) .getIsMasterRunning()); return; } catch (ServiceException ex) { IOException ie = ProtobufUtil.handleRemoteException(ex); // No SocketTimeoutException here. RpcServer is already started after the construction of // HMaster. assertTrue(ie.getMessage().startsWith( "org.apache.hadoop.hbase.ipc.ServerNotRunningYetException: Server is not running yet")); LOG.info("Expected exception: ", ie); if (!fakeZNodeDelete) { testUtil.getZooKeeperWatcher().getRecoverableZooKeeper() .delete(testUtil.getZooKeeperWatcher().getZNodePaths().masterAddressZNode, -1); fakeZNodeDelete = true; } } Thread.sleep(1000); } } }
@Override public AdminProtos.AdminService.BlockingInterface getAdmin(ServerName serverName) throws IOException { checkClosed(); if (isDeadServer(serverName)) { throw new RegionServerStoppedException(serverName + " is dead."); } String key = getStubKey(AdminProtos.AdminService.BlockingInterface.class.getName(), serverName, this.hostnamesCanChange); return (AdminProtos.AdminService.BlockingInterface) computeIfAbsentEx(stubs, key, () -> { BlockingRpcChannel channel = this.rpcClient.createBlockingRpcChannel(serverName, user, rpcTimeout); return AdminProtos.AdminService.newBlockingStub(channel); }); }
@Override public BlockingInterface getClient(ServerName serverName) throws IOException { checkClosed(); if (isDeadServer(serverName)) { throw new RegionServerStoppedException(serverName + " is dead."); } String key = getStubKey(ClientProtos.ClientService.BlockingInterface.class.getName(), serverName, this.hostnamesCanChange); return (ClientProtos.ClientService.BlockingInterface) computeIfAbsentEx(stubs, key, () -> { BlockingRpcChannel channel = this.rpcClient.createBlockingRpcChannel(serverName, user, rpcTimeout); return ClientProtos.ClientService.newBlockingStub(channel); }); }
@Override public Hbck getHbck(ServerName masterServer) throws IOException { checkClosed(); if (isDeadServer(masterServer)) { throw new RegionServerStoppedException(masterServer + " is dead."); } String key = getStubKey(MasterProtos.HbckService.BlockingInterface.class.getName(), masterServer, this.hostnamesCanChange); return new HBaseHbck(this, (MasterProtos.HbckService.BlockingInterface) computeIfAbsentEx(stubs, key, () -> { BlockingRpcChannel channel = this.rpcClient.createBlockingRpcChannel(masterServer, user, rpcTimeout); return MasterProtos.HbckService.newBlockingStub(channel); })); }
/** * Create a stub. Try once only. It is not typed because there is no common type to protobuf * services nor their interfaces. Let the caller do appropriate casting. * @return A stub for master services. */ private MasterProtos.MasterService.BlockingInterface makeStubNoRetries() throws IOException, KeeperException { ServerName sn = get(registry.getMasterAddress()); if (sn == null) { String msg = "ZooKeeper available but no active master location found"; LOG.info(msg); throw new MasterNotRunningException(msg); } if (isDeadServer(sn)) { throw new MasterNotRunningException(sn + " is dead."); } // Use the security info interface name as our stub key String key = getStubKey(MasterProtos.MasterService.getDescriptor().getName(), sn, hostnamesCanChange); MasterProtos.MasterService.BlockingInterface stub = (MasterProtos.MasterService.BlockingInterface) computeIfAbsentEx(stubs, key, () -> { BlockingRpcChannel channel = rpcClient.createBlockingRpcChannel(sn, user, rpcTimeout); return MasterProtos.MasterService.newBlockingStub(channel); }); isMasterRunning(stub); return stub; }
@Override public ClientService.BlockingInterface getClient(final ServerName sn) throws IOException { if (isDeadServer(sn)) { throw new RegionServerStoppedException(sn + " is dead."); } String key = getStubKey(ClientService.BlockingInterface.class.getName(), sn.getHostname(), sn.getPort(), this.hostnamesCanChange); this.connectionLock.putIfAbsent(key, key); ClientService.BlockingInterface stub = null; synchronized (this.connectionLock.get(key)) { stub = (ClientService.BlockingInterface)this.stubs.get(key); if (stub == null) { BlockingRpcChannel channel = this.rpcClient.createBlockingRpcChannel(sn, user, rpcTimeout); stub = ClientService.newBlockingStub(channel); // In old days, after getting stub/proxy, we'd make a call. We are not doing that here. // Just fail on first actual call rather than in here on setup. this.stubs.put(key, stub); } } return stub; }
@Override // Nothing is done w/ the 'master' parameter. It is ignored. public AdminService.BlockingInterface getAdmin(final ServerName serverName, final boolean master) throws IOException { if (isDeadServer(serverName)) { throw new RegionServerStoppedException(serverName + " is dead."); } String key = getStubKey(AdminService.BlockingInterface.class.getName(), serverName.getHostname(), serverName.getPort(), this.hostnamesCanChange); this.connectionLock.putIfAbsent(key, key); AdminService.BlockingInterface stub = null; synchronized (this.connectionLock.get(key)) { stub = (AdminService.BlockingInterface)this.stubs.get(key); if (stub == null) { BlockingRpcChannel channel = this.rpcClient.createBlockingRpcChannel(serverName, user, rpcTimeout); stub = AdminService.newBlockingStub(channel); this.stubs.put(key, stub); } } return stub; }
public static BlockingInterface newBlockingStub(RpcClient client, InetSocketAddress addr, User user) throws IOException { return TestProtobufRpcProto.newBlockingStub(client.createBlockingRpcChannel( ServerName.valueOf(addr.getHostName(), addr.getPort(), System.currentTimeMillis()), user, 0)); }
@Override public BlockingInterface getClient(ServerName serverName) throws IOException { checkClosed(); if (isDeadServer(serverName)) { throw new RegionServerStoppedException(serverName + " is dead."); } ServerName vhostSN = detectVServerName(serverName); String key = getStubKey(ClientProtos.ClientService.BlockingInterface.class.getName(), vhostSN, this.hostnamesCanChange); return (ClientProtos.ClientService.BlockingInterface) computeIfAbsentEx(stubs, key, () -> { BlockingRpcChannel channel = this.rpcClient.createBlockingRpcChannel(vhostSN, user, rpcTimeout); return ClientProtos.ClientService.newBlockingStub(channel); }); }
@Override public AdminProtos.AdminService.BlockingInterface getAdmin(ServerName serverName) throws IOException { checkClosed(); if (isDeadServer(serverName)) { throw new RegionServerStoppedException(serverName + " is dead."); } ServerName vhostSN = detectVServerName(serverName); String key = getStubKey(AdminProtos.AdminService.BlockingInterface.class.getName(), vhostSN, this.hostnamesCanChange); return (AdminProtos.AdminService.BlockingInterface) computeIfAbsentEx(stubs, key, () -> { BlockingRpcChannel channel = this.rpcClient.createBlockingRpcChannel(vhostSN, user, rpcTimeout); return AdminProtos.AdminService.newBlockingStub(channel); }); }
/** * Create a stub. Try once only. It is not typed because there is no common type to protobuf * services nor their interfaces. Let the caller do appropriate casting. * @return A stub for master services. */ private MasterProtos.MasterService.BlockingInterface makeStubNoRetries() throws IOException, KeeperException { ServerName sn = get(registry.getMasterAddress()); if (sn == null) { String msg = "ZooKeeper available but no active master location found"; LOG.info(msg); throw new MasterNotRunningException(msg); } if (isDeadServer(sn)) { throw new MasterNotRunningException(sn + " is dead."); } // Use the security info interface name as our stub key ServerName vhostSN = detectVServerName(sn); String key = getStubKey(MasterProtos.MasterService.getDescriptor().getName(), vhostSN, hostnamesCanChange); MasterProtos.MasterService.BlockingInterface stub = (MasterProtos.MasterService.BlockingInterface) computeIfAbsentEx(stubs, key, () -> { BlockingRpcChannel channel = rpcClient.createBlockingRpcChannel(vhostSN, user, rpcTimeout); return MasterProtos.MasterService.newBlockingStub(channel); }); isMasterRunning(stub); return stub; }
stub = stubs.get(key); if (stub == null) { BlockingRpcChannel channel = rpcClient.createBlockingRpcChannel(sn, user, rpcTimeout); stub = makeStub(channel); isMasterRunning();
@Test public void testRPCException() throws IOException, InterruptedException, KeeperException { ServerName sm = master.getServerName(); boolean fakeZNodeDelete = false; for (int i = 0; i < 20; i++) { try { BlockingRpcChannel channel = rpcClient.createBlockingRpcChannel(sm, User.getCurrent(), 0); MasterProtos.MasterService.BlockingInterface stub = MasterProtos.MasterService.newBlockingStub(channel); assertTrue(stub.isMasterRunning(null, IsMasterRunningRequest.getDefaultInstance()) .getIsMasterRunning()); return; } catch (ServiceException ex) { IOException ie = ProtobufUtil.handleRemoteException(ex); // No SocketTimeoutException here. RpcServer is already started after the construction of // HMaster. assertTrue(ie.getMessage().startsWith( "org.apache.hadoop.hbase.ipc.ServerNotRunningYetException: Server is not running yet")); LOG.info("Expected exception: ", ie); if (!fakeZNodeDelete) { testUtil.getZooKeeperWatcher().getRecoverableZooKeeper() .delete(testUtil.getZooKeeperWatcher().getZNodePaths().masterAddressZNode, -1); fakeZNodeDelete = true; } } Thread.sleep(1000); } } }