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  public static final String IPC_SERVER_REPLICATION_MAX_CALLQUEUE_LENGTH =
039      "hbase.ipc.server.replication.max.callqueue.length";
040
041  /** Exposes runtime information of a {@code RpcServer} that a {@code RpcScheduler} may need. */
042  public static abstract class Context {
043    public abstract InetSocketAddress getListenerAddress();
044  }
045
046  /**
047   * Does some quick initialization. Heavy tasks (e.g. starting threads) should be
048   * done in {@link #start()}. This method is called before {@code start}.
049   *
050   * @param context provides methods to retrieve runtime information from
051   */
052  public abstract void init(Context context);
053
054  /**
055   * Prepares for request serving. An implementation may start some handler threads here.
056   */
057  public abstract void start();
058
059  /** Stops serving new requests. */
060  public abstract void stop();
061
062  /**
063   * Dispatches an RPC request asynchronously. An implementation is free to choose to process the
064   * request immediately or delay it for later processing.
065   *
066   * @param task the request to be dispatched
067   */
068  public abstract boolean dispatch(CallRunner task) throws IOException, InterruptedException;
069
070  /** Get call queue information **/
071  public abstract CallQueueInfo getCallQueueInfo();
072
073  /** Retrieves length of the general queue for metrics. */
074  public abstract int getGeneralQueueLength();
075
076  /** Retrieves length of the priority queue for metrics. */
077  public abstract int getPriorityQueueLength();
078
079  /** Retrieves length of the meta priority queue for metrics. */
080  public abstract int getMetaPriorityQueueLength();
081
082  /** Retrieves length of the replication queue for metrics. */
083  public abstract int getReplicationQueueLength();
084
085  /** Retrieves the total number of active handler. */
086  public abstract int getActiveRpcHandlerCount();
087
088  /** Retrieves the number of active general handler. */
089  public abstract int getActiveGeneralRpcHandlerCount();
090
091  /** Retrieves the number of active priority handler. */
092  public abstract int getActivePriorityRpcHandlerCount();
093
094  /** Retrieves the number of active meta priority handler. */
095  public abstract int getActiveMetaPriorityRpcHandlerCount();
096
097  /** Retrieves the number of active replication handler. */
098  public abstract int getActiveReplicationRpcHandlerCount();
099
100  /**
101   * If CoDel-based RPC executors are used, retrieves the number of Calls that were dropped
102   * from general queue because RPC executor is under high load; returns 0 otherwise.
103   */
104  public abstract long getNumGeneralCallsDropped();
105
106  /**
107   * If CoDel-based RPC executors are used, retrieves the number of Calls that were
108   * picked from the tail of the queue (indicating adaptive LIFO mode, when
109   * in the period of overloade we serve last requests first); returns 0 otherwise.
110   */
111  public abstract long getNumLifoModeSwitches();
112
113  /** Retrieves length of the write queue for metrics when use RWQueueRpcExecutor. */
114  public abstract int getWriteQueueLength();
115
116  /** Retrieves length of the read queue for metrics when use RWQueueRpcExecutor. */
117  public abstract int getReadQueueLength();
118
119  /** Retrieves length of the scan queue for metrics when use RWQueueRpcExecutor. */
120  public abstract int getScanQueueLength();
121
122  /** Retrieves the number of active write rpc handler when use RWQueueRpcExecutor. */
123  public abstract int getActiveWriteRpcHandlerCount();
124
125  /** Retrieves the number of active write rpc handler when use RWQueueRpcExecutor. */
126  public abstract int getActiveReadRpcHandlerCount();
127
128  /** Retrieves the number of active write rpc handler when use RWQueueRpcExecutor. */
129  public abstract int getActiveScanRpcHandlerCount();
130}