diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServer.java index 6cdf7f1..1758822 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServer.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServer.java @@ -128,7 +128,20 @@ import com.google.protobuf.TextFormat; /** * An RPC server that hosts protobuf described Services. - *

Once was copied from Hadoop to local to fix HBASE-900 but deviated long ago. + * + * An RpcServer instance has a Listener that hosts the socket. Listener has fixed number of + * Readers in an ExecutorPool. 10 by default. The Listener does an accept and then round robin a + * Reader is chosen to do the read. The reader is registered. Read does total read off the + * channel and the parse from which it makes a Call. The call is wrapped in a CallRunner and then + * passed to the scheduler to be run. Reader goes back to see if more to be done and loops till + * done. + * + * Scheduler has handlers to which it has given the queues into which calls are inserted. Handlers + * run taking from the queue. They run the CallRunner#run method on each item gotten from queue + * and keep taking while the server is up. + * + * CallRunner#run executes the call (Why we have handlers, which are threads, run a CallRunner, + * which is a thread? * * @see RpcClient */ @@ -171,10 +184,9 @@ public class RpcServer implements RpcServerInterface { protected SecretManager secretManager; protected ServiceAuthorizationManager authManager; - protected static final ThreadLocal SERVER = new ThreadLocal(); private volatile boolean started = false; - /** This is set to Call object before Handler invokes an RPC and reset + /** This is set to Call object before Handler invokes an RPC and undone * after the call returns. */ protected static final ThreadLocal CurCall = new ThreadLocal(); @@ -462,7 +474,7 @@ public class RpcServer implements RpcServerInterface { /** * If we have a response, and delay is not set, then respond * immediately. Otherwise, do not respond to client. This is - * called the by the RPC code in the context of the Handler thread. + * called by the RPC code in the context of the Handler thread. */ public synchronized void sendResponseIfReady() throws IOException { if (!this.delayResponse) { @@ -643,7 +655,6 @@ public class RpcServer implements RpcServerInterface { @Override public void run() { LOG.info(getName() + ": starting"); - SERVER.set(RpcServer.this); while (running) { SelectionKey key = null; @@ -815,7 +826,6 @@ public class RpcServer implements RpcServerInterface { @Override public void run() { LOG.info(getName() + ": starting"); - SERVER.set(RpcServer.this); try { doRunLoop(); } finally { @@ -1773,7 +1783,6 @@ public class RpcServer implements RpcServerInterface { @Override public void run() { MonitoredRPCHandler status = getStatus(); - SERVER.set(RpcServer.this); try { status.setStatus("Setting up call"); status.setConnection(call.connection.getHostAddress(), call.connection.getRemotePort()); @@ -2394,17 +2403,6 @@ public class RpcServer implements RpcServerInterface { } /** - * May be called under - * {@code #call(Class, RpcRequestBody, long, MonitoredRPCHandler)} implementations, - * and under protobuf methods of parameters and return values. - * Permits applications to access the server context. - * @return the server instance called under or null - */ - public static RpcServerInterface get() { - return SERVER.get(); - } - - /** * A convenience method to bind to a given address and report * better exceptions if the address is not a valid host. * @param socket the socket to bind diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/SimpleRpcScheduler.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/SimpleRpcScheduler.java index c3021cc..a34f481 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/SimpleRpcScheduler.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/SimpleRpcScheduler.java @@ -161,6 +161,8 @@ public class SimpleRpcScheduler implements RpcScheduler { private void consumerLoop(BlockingQueue myQueue) { while (running) { try { + // CallRunnable is a Runnable but we are not running it in a Thread; we are calling its + // run synchronously here. RpcServer.CallRunner task = myQueue.take(); task.run(); } catch (InterruptedException e) {