HBase1.0.0 RPC mechanism analysis and source code interpretation (1), hbase1.0.0rpc

Source: Internet
Author: User

HBase1.0.0 RPC mechanism analysis and source code interpretation (1), hbase1.0.0rpc
In addition to the protocal buf tool, HBase uses java Native APIs to construct the RPC mechanism. The RPC mechanism consists of two parts: client and server, this article briefly analyzes the Server Service Running Mechanism and workflow.
First, we will analyze a typical RPC server short processing process, as shown in:

You can clearly see that when the client sends a request to the server, it is initially listened to by the Listener in the RPCServer, as shown in the following code, several processing threads will be started when HBase RpcServer is started:

    responder.start();    listener.start();    scheduler.start();
Among them, the Responder thread is responsible for data request response, listener is responsible for listening to client requests, schedener is responsible for specific call Scheduling
      while (running) {        SelectionKey key = null;        try {          selector.select(); // FindBugs IS2_INCONSISTENT_SYNC          Iterator<SelectionKey> iter = selector.selectedKeys().iterator();          while (iter.hasNext()) {            key = iter.next();            iter.remove();            try {              if (key.isValid()) {                if (key.isAcceptable())                  doAccept(key);              }            } catch (IOException ignored) {              if (LOG.isTraceEnabled()) LOG.trace("ignored", ignored);            }            key = null;          }        }
Some features of java nio are used in the implementation of listener. each Listener thread manages the thread pool of the Reader, which reads data from the Socket Channel, parse related items in the data to construct the runable CallRunner:
      Call call = new Call(id, this.service, md, header, param, cellScanner, this, responder,              totalRequestSize,              traceInfo);      scheduler.dispatch(new CallRunner(RpcServer.this, call, userProvider));
Rpcschedtor calls the corresponding RpcExcutor for corresponding processing. RpcExcutor starts multiple processing threads that extract and execute tasks from the queue,
  protected void startHandlers(final String nameSuffix, final int numHandlers,      final List<BlockingQueue<CallRunner>> callQueues,      final int qindex, final int qsize, final int port) {    final String threadPrefix = name + Strings.nullToEmpty(nameSuffix);    for (int i = 0; i < numHandlers; i++) {      final int index = qindex + (i % qsize);      Thread t = new Thread(new Runnable() {        @Override        public void run() {          consumerLoop(callQueues.get(index));        }      });      t.setDaemon(true);      t.setName(threadPrefix + "RpcServer.handler=" + handlers.size() +        ",queue=" + index + ",port=" + port);      t.start();      LOG.debug(threadPrefix + " Start Handler index=" + handlers.size() + " queue=" + index);      handlers.add(t);    }  }
  protected void consumerLoop(final BlockingQueue<CallRunner> myQueue) {    boolean interrupted = false;    double handlerFailureThreshhold =        conf == null ? 1.0 : conf.getDouble(HConstants.REGION_SERVER_HANDLER_ABORT_ON_ERROR_PERCENT,          HConstants.DEFAULT_REGION_SERVER_HANDLER_ABORT_ON_ERROR_PERCENT);    try {      while (running) {        try {          CallRunner task = myQueue.take();          try {            activeHandlerCount.incrementAndGet();            task.run();

In fact, if you continue to follow up the code, you will find that the main actions of the CallRunner's run method are two: Get the operation result and return the operation result to the customer:
       resultPair = this.rpcServer.call(call.service, call.md, call.param, call.cellScanner,          call.timestamp, this.status);
  if (!call.isDelayed() || !call.isReturnValueDelayed()) {        Message param = resultPair != null ? resultPair.getFirst() : null;        CellScanner cells = resultPair != null ? resultPair.getSecond() : null;        call.setResponse(param, cells, errorThrowable, error);      }      call.sendResponseIfReady();
At this end, we will briefly introduce a complete server-side RPC processing process. The relationships between classes involved in this process are shown in:







Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.