1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18 package org.apache.hadoop.hbase.ipc;
19
20 import org.apache.hadoop.hbase.classification.InterfaceAudience;
21 import org.apache.hadoop.hbase.classification.InterfaceStability;
22 import org.apache.hadoop.hbase.HBaseInterfaceAudience;
23
24 import java.io.IOException;
25 import java.net.InetSocketAddress;
26
27 /**
28 * An interface for RPC request scheduling algorithm.
29 */
30 @InterfaceAudience.LimitedPrivate({HBaseInterfaceAudience.COPROC, HBaseInterfaceAudience.PHOENIX})
31 @InterfaceStability.Evolving
32 public abstract class RpcScheduler {
33 public static final String IPC_SERVER_MAX_CALLQUEUE_LENGTH =
34 "hbase.ipc.server.max.callqueue.length";
35 public static final String IPC_SERVER_PRIORITY_MAX_CALLQUEUE_LENGTH =
36 "hbase.ipc.server.priority.max.callqueue.length";
37
38 /** Exposes runtime information of a {@code RpcServer} that a {@code RpcScheduler} may need. */
39 public static abstract class Context {
40 public abstract InetSocketAddress getListenerAddress();
41 }
42
43 /**
44 * Does some quick initialization. Heavy tasks (e.g. starting threads) should be
45 * done in {@link #start()}. This method is called before {@code start}.
46 *
47 * @param context provides methods to retrieve runtime information from
48 */
49 public abstract void init(Context context);
50
51 /**
52 * Prepares for request serving. An implementation may start some handler threads here.
53 */
54 public abstract void start();
55
56 /** Stops serving new requests. */
57 public abstract void stop();
58
59 /**
60 * Dispatches an RPC request asynchronously. An implementation is free to choose to process the
61 * request immediately or delay it for later processing.
62 *
63 * @param task the request to be dispatched
64 */
65 public abstract boolean dispatch(CallRunner task) throws IOException, InterruptedException;
66
67 /** Retrieves length of the general queue for metrics. */
68 public abstract int getGeneralQueueLength();
69
70 /** Retrieves length of the priority queue for metrics. */
71 public abstract int getPriorityQueueLength();
72
73 /** Retrieves length of the replication queue for metrics. */
74 public abstract int getReplicationQueueLength();
75
76 /** Retrieves the number of active handler. */
77 public abstract int getActiveRpcHandlerCount();
78
79 /**
80 * If CoDel-based RPC executors are used, retrieves the number of Calls that were dropped
81 * from general queue because RPC executor is under high load; returns 0 otherwise.
82 */
83 public abstract long getNumGeneralCallsDropped();
84
85 /**
86 * If CoDel-based RPC executors are used, retrieves the number of Calls that were
87 * picked from the tail of the queue (indicating adaptive LIFO mode, when
88 * in the period of overloade we serve last requests first); returns 0 otherwise.
89 */
90 public abstract long getNumLifoModeSwitches();
91 }