View Javadoc

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  
34    public static final String IPC_SERVER_MAX_CALLQUEUE_LENGTH =
35        "hbase.ipc.server.max.callqueue.length";
36    public static final String IPC_SERVER_PRIORITY_MAX_CALLQUEUE_LENGTH =
37        "hbase.ipc.server.priority.max.callqueue.length";
38  
39    /** Exposes runtime information of a {@code RpcServer} that a {@code RpcScheduler} may need. */
40    public static abstract class Context {
41      public abstract InetSocketAddress getListenerAddress();
42    }
43  
44    /**
45     * Does some quick initialization. Heavy tasks (e.g. starting threads) should be
46     * done in {@link #start()}. This method is called before {@code start}.
47     *
48     * @param context provides methods to retrieve runtime information from
49     */
50    public abstract void init(Context context);
51  
52    /**
53     * Prepares for request serving. An implementation may start some handler threads here.
54     */
55    public abstract void start();
56  
57    /** Stops serving new requests. */
58    public abstract void stop();
59  
60    /**
61     * Dispatches an RPC request asynchronously. An implementation is free to choose to process the
62     * request immediately or delay it for later processing.
63     *
64     * @param task the request to be dispatched
65     */
66    public abstract boolean dispatch(CallRunner task) throws IOException, InterruptedException;
67  
68    /** Retrieves length of the general queue for metrics. */
69    public abstract int getGeneralQueueLength();
70  
71    /** Retrieves length of the priority queue for metrics. */
72    public abstract int getPriorityQueueLength();
73  
74    /** Retrieves length of the replication queue for metrics. */
75    public abstract int getReplicationQueueLength();
76  
77    /** Retrieves the total number of active handler. */
78    public abstract int getActiveRpcHandlerCount();
79  
80    /** Retrieves the number of active general handler. */
81    public abstract int getActiveGeneralRpcHandlerCount();
82  
83    /** Retrieves the number of active priority handler. */
84    public abstract int getActivePriorityRpcHandlerCount();
85  
86    /** Retrieves the number of active replication handler. */
87    public abstract int getActiveReplicationRpcHandlerCount();
88  
89    /**
90     * If CoDel-based RPC executors are used, retrieves the number of Calls that were dropped
91     * from general queue because RPC executor is under high load; returns 0 otherwise.
92     */
93    public abstract long getNumGeneralCallsDropped();
94  
95    /**
96     * If CoDel-based RPC executors are used, retrieves the number of Calls that were
97     * picked from the tail of the queue (indicating adaptive LIFO mode, when
98     * in the period of overloade we serve last requests first); returns 0 otherwise.
99     */
100   public abstract long getNumLifoModeSwitches();
101 
102   /** Retrieves length of the write queue for metrics when use RWQueueRpcExecutor. */
103   public abstract int getWriteQueueLength();
104 
105   /** Retrieves length of the read queue for metrics when use RWQueueRpcExecutor. */
106   public abstract int getReadQueueLength();
107 
108   /** Retrieves length of the scan queue for metrics when use RWQueueRpcExecutor. */
109   public abstract int getScanQueueLength();
110 
111   /** Retrieves the number of active write rpc handler when use RWQueueRpcExecutor. */
112   public abstract int getActiveWriteRpcHandlerCount();
113 
114   /** Retrieves the number of active write rpc handler when use RWQueueRpcExecutor. */
115   public abstract int getActiveReadRpcHandlerCount();
116 
117   /** Retrieves the number of active write rpc handler when use RWQueueRpcExecutor. */
118   public abstract int getActiveScanRpcHandlerCount();
119 }