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 java.net.InetSocketAddress;
021import org.apache.hadoop.hbase.HBaseInterfaceAudience;
022import org.apache.yetus.audience.InterfaceAudience;
023import org.apache.yetus.audience.InterfaceStability;
024
025/**
026 * An interface for RPC request scheduling algorithm.
027 */
028@InterfaceAudience.LimitedPrivate({ HBaseInterfaceAudience.COPROC, HBaseInterfaceAudience.PHOENIX })
029@InterfaceStability.Evolving
030public abstract class RpcScheduler {
031
032  public static final String IPC_SERVER_MAX_CALLQUEUE_LENGTH =
033    "hbase.ipc.server.max.callqueue.length";
034  public static final String IPC_SERVER_PRIORITY_MAX_CALLQUEUE_LENGTH =
035    "hbase.ipc.server.priority.max.callqueue.length";
036  public static final String IPC_SERVER_REPLICATION_MAX_CALLQUEUE_LENGTH =
037    "hbase.ipc.server.replication.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 done in
046   * {@link #start()}. This method is called before {@code start}.
047   * @param context provides methods to retrieve runtime information from
048   */
049  public abstract void init(Context context);
050
051  /**
052   * Prepares for request serving. An implementation may start some handler threads here.
053   */
054  public abstract void start();
055
056  /** Stops serving new requests. */
057  public abstract void stop();
058
059  /**
060   * Dispatches an RPC request asynchronously. An implementation is free to choose to process the
061   * request immediately or delay it for later processing.
062   * @param task the request to be dispatched
063   */
064  public abstract boolean dispatch(CallRunner task);
065
066  /** Get call queue information **/
067  public abstract CallQueueInfo getCallQueueInfo();
068
069  /** Retrieves length of the general queue for metrics. */
070  public abstract int getGeneralQueueLength();
071
072  /** Retrieves length of the priority queue for metrics. */
073  public abstract int getPriorityQueueLength();
074
075  /** Retrieves length of the meta priority queue for metrics. */
076  public abstract int getMetaPriorityQueueLength();
077
078  /** Retrieves length of the replication queue for metrics. */
079  public abstract int getReplicationQueueLength();
080
081  /** Retrieves the total number of active handler. */
082  public abstract int getActiveRpcHandlerCount();
083
084  /** Retrieves the number of active general handler. */
085  public abstract int getActiveGeneralRpcHandlerCount();
086
087  /** Retrieves the number of active priority handler. */
088  public abstract int getActivePriorityRpcHandlerCount();
089
090  /** Retrieves the number of active meta priority handler. */
091  public abstract int getActiveMetaPriorityRpcHandlerCount();
092
093  /** Retrieves the number of active replication handler. */
094  public abstract int getActiveReplicationRpcHandlerCount();
095
096  /**
097   * If CoDel-based RPC executors are used, retrieves the number of Calls that were dropped from
098   * general queue because RPC executor is under high load; returns 0 otherwise.
099   */
100  public abstract long getNumGeneralCallsDropped();
101
102  /**
103   * If CoDel-based RPC executors are used, retrieves the number of Calls that were picked from the
104   * tail of the queue (indicating adaptive LIFO mode, when in the period of overloade we serve last
105   * requests first); returns 0 otherwise.
106   */
107  public abstract long getNumLifoModeSwitches();
108
109  /** Retrieves length of the write queue for metrics when use RWQueueRpcExecutor. */
110  public abstract int getWriteQueueLength();
111
112  /** Retrieves length of the read queue for metrics when use RWQueueRpcExecutor. */
113  public abstract int getReadQueueLength();
114
115  /** Retrieves length of the scan queue for metrics when use RWQueueRpcExecutor. */
116  public abstract int getScanQueueLength();
117
118  /** Retrieves the number of active write rpc handler when use RWQueueRpcExecutor. */
119  public abstract int getActiveWriteRpcHandlerCount();
120
121  /** Retrieves the number of active write rpc handler when use RWQueueRpcExecutor. */
122  public abstract int getActiveReadRpcHandlerCount();
123
124  /** Retrieves the number of active write rpc handler when use RWQueueRpcExecutor. */
125  public abstract int getActiveScanRpcHandlerCount();
126}