1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.ipc;
19
20 import java.util.Deque;
21 import java.util.concurrent.BlockingQueue;
22 import java.util.concurrent.ConcurrentLinkedDeque;
23 import java.util.concurrent.atomic.AtomicInteger;
24 import org.apache.hadoop.conf.Configuration;
25 import org.apache.hadoop.hbase.Abortable;
26 import org.apache.hadoop.hbase.HBaseInterfaceAudience;
27 import org.apache.hadoop.hbase.classification.InterfaceAudience;
28 import org.apache.hadoop.hbase.classification.InterfaceStability;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32
33
34
35
36 @InterfaceAudience.LimitedPrivate({ HBaseInterfaceAudience.COPROC, HBaseInterfaceAudience.PHOENIX})
37 @InterfaceStability.Evolving
38 public class FastPathRWQueueRpcExecutor extends RWQueueRpcExecutor {
39 private static final Logger LOG = LoggerFactory.getLogger(RWQueueRpcExecutor.class);
40
41 private final Deque<FastPathRpcHandler> readHandlerStack = new ConcurrentLinkedDeque<>();
42 private final Deque<FastPathRpcHandler> writeHandlerStack = new ConcurrentLinkedDeque<>();
43 private final Deque<FastPathRpcHandler> scanHandlerStack = new ConcurrentLinkedDeque<>();
44
45 public FastPathRWQueueRpcExecutor(String name, int handlerCount, int maxQueueLength,
46 PriorityFunction priority, Configuration conf, Abortable abortable) {
47 super(name, handlerCount, maxQueueLength, priority, conf, abortable);
48 }
49
50 @Override
51 protected RpcHandler getHandler(final String name, final double handlerFailureThreshhold,
52 final int handlerCount, final BlockingQueue<CallRunner> q,
53 final AtomicInteger activeHandlerCount, final AtomicInteger failedHandlerCount,
54 final Abortable abortable) {
55 Deque<FastPathRpcHandler> handlerStack = name.contains("read") ? readHandlerStack :
56 name.contains("write") ? writeHandlerStack : scanHandlerStack;
57 return new FastPathRpcHandler(name, handlerFailureThreshhold, handlerCount, q,
58 activeHandlerCount, failedHandlerCount, abortable, handlerStack);
59 }
60
61 @Override
62 public boolean dispatch(final CallRunner callTask) throws InterruptedException {
63 RpcServer.Call call = callTask.getCall();
64 boolean shouldDispatchToWriteQueue = isWriteRequest(call.getHeader(), call.param);
65 boolean shouldDispatchToScanQueue = shouldDispatchToScanQueue(callTask);
66 FastPathRpcHandler handler = shouldDispatchToWriteQueue ? writeHandlerStack.poll() :
67 shouldDispatchToScanQueue ? scanHandlerStack.poll() : readHandlerStack.poll();
68 return handler != null ? handler.loadCallRunner(callTask) :
69 dispatchTo(shouldDispatchToWriteQueue, shouldDispatchToScanQueue, callTask);
70 }
71 }