001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.ipc;
019
020import org.apache.yetus.audience.InterfaceAudience;
021import org.apache.yetus.audience.InterfaceStability;
022import org.apache.hadoop.hbase.HBaseInterfaceAudience;
023
024import java.io.IOException;
025import java.net.InetSocketAddress;
026
027/**
028 * An interface for RPC request scheduling algorithm.
029 */
030@InterfaceAudience.LimitedPrivate({HBaseInterfaceAudience.COPROC, HBaseInterfaceAudience.PHOENIX})
031@InterfaceStability.Evolving
032public abstract class RpcScheduler {
033
034  public static final String IPC_SERVER_MAX_CALLQUEUE_LENGTH =
035      "hbase.ipc.server.max.callqueue.length";
036  public static final String IPC_SERVER_PRIORITY_MAX_CALLQUEUE_LENGTH =
037      "hbase.ipc.server.priority.max.callqueue.length";
038
039  /** Exposes runtime information of a {@code RpcServer} that a {@code RpcScheduler} may need. */
040  public static abstract class Context {
041    public abstract InetSocketAddress getListenerAddress();
042  }
043
044  /**
045   * Does some quick initialization. Heavy tasks (e.g. starting threads) should be
046   * done in {@link #start()}. This method is called before {@code start}.
047   *
048   * @param context provides methods to retrieve runtime information from
049   */
050  public abstract void init(Context context);
051
052  /**
053   * Prepares for request serving. An implementation may start some handler threads here.
054   */
055  public abstract void start();
056
057  /** Stops serving new requests. */
058  public abstract void stop();
059
060  /**
061   * Dispatches an RPC request asynchronously. An implementation is free to choose to process the
062   * request immediately or delay it for later processing.
063   *
064   * @param task the request to be dispatched
065   */
066  public abstract boolean dispatch(CallRunner task) throws IOException, InterruptedException;
067
068  /** Get call queue information **/
069  public abstract CallQueueInfo getCallQueueInfo();
070
071  /** Retrieves length of the general queue for metrics. */
072  public abstract int getGeneralQueueLength();
073
074  /** Retrieves length of the priority queue for metrics. */
075  public abstract int getPriorityQueueLength();
076
077  /** Retrieves length of the meta priority queue for metrics. */
078  public abstract int getMetaPriorityQueueLength();
079
080  /** Retrieves length of the replication queue for metrics. */
081  public abstract int getReplicationQueueLength();
082
083  /** Retrieves the total number of active handler. */
084  public abstract int getActiveRpcHandlerCount();
085
086  /** Retrieves the number of active general handler. */
087  public abstract int getActiveGeneralRpcHandlerCount();
088
089  /** Retrieves the number of active priority handler. */
090  public abstract int getActivePriorityRpcHandlerCount();
091
092  /** Retrieves the number of active meta priority handler. */
093  public abstract int getActiveMetaPriorityRpcHandlerCount();
094
095  /** Retrieves the number of active replication handler. */
096  public abstract int getActiveReplicationRpcHandlerCount();
097
098  /**
099   * If CoDel-based RPC executors are used, retrieves the number of Calls that were dropped
100   * from general queue because RPC executor is under high load; returns 0 otherwise.
101   */
102  public abstract long getNumGeneralCallsDropped();
103
104  /**
105   * If CoDel-based RPC executors are used, retrieves the number of Calls that were
106   * picked from the tail of the queue (indicating adaptive LIFO mode, when
107   * in the period of overloade we serve last requests first); returns 0 otherwise.
108   */
109  public abstract long getNumLifoModeSwitches();
110
111  /** Retrieves length of the write queue for metrics when use RWQueueRpcExecutor. */
112  public abstract int getWriteQueueLength();
113
114  /** Retrieves length of the read queue for metrics when use RWQueueRpcExecutor. */
115  public abstract int getReadQueueLength();
116
117  /** Retrieves length of the scan queue for metrics when use RWQueueRpcExecutor. */
118  public abstract int getScanQueueLength();
119
120  /** Retrieves the number of active write rpc handler when use RWQueueRpcExecutor. */
121  public abstract int getActiveWriteRpcHandlerCount();
122
123  /** Retrieves the number of active write rpc handler when use RWQueueRpcExecutor. */
124  public abstract int getActiveReadRpcHandlerCount();
125
126  /** Retrieves the number of active write rpc handler when use RWQueueRpcExecutor. */
127  public abstract int getActiveScanRpcHandlerCount();
128}