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 public static final String IPC_SERVER_BULKLOAD_MAX_CALLQUEUE_LENGTH = 039 "hbase.ipc.server.bulkload.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 done in 048 * {@link #start()}. This method is called before {@code start}. 049 * @param context provides methods to retrieve runtime information from 050 */ 051 public abstract void init(Context context); 052 053 /** 054 * Prepares for request serving. An implementation may start some handler threads here. 055 */ 056 public abstract void start(); 057 058 /** Stops serving new requests. */ 059 public abstract void stop(); 060 061 /** 062 * Dispatches an RPC request asynchronously. An implementation is free to choose to process the 063 * request immediately or delay it for later processing. 064 * @param task the request to be dispatched 065 */ 066 public abstract boolean dispatch(CallRunner task); 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 length of the bulkload queue for metrics. */ 084 public abstract int getBulkLoadQueueLength(); 085 086 /** Retrieves the total number of active handler. */ 087 public abstract int getActiveRpcHandlerCount(); 088 089 /** Retrieves the number of active general handler. */ 090 public abstract int getActiveGeneralRpcHandlerCount(); 091 092 /** Retrieves the number of active priority handler. */ 093 public abstract int getActivePriorityRpcHandlerCount(); 094 095 /** Retrieves the number of active meta priority handler. */ 096 public abstract int getActiveMetaPriorityRpcHandlerCount(); 097 098 /** Retrieves the number of active replication handler. */ 099 public abstract int getActiveReplicationRpcHandlerCount(); 100 101 /** Retrieves the number of active bulkload handler. */ 102 public abstract int getActiveBulkLoadRpcHandlerCount(); 103 104 /** 105 * If CoDel-based RPC executors are used, retrieves the number of Calls that were dropped from 106 * general queue because RPC executor is under high load; returns 0 otherwise. 107 */ 108 public abstract long getNumGeneralCallsDropped(); 109 110 /** 111 * If CoDel-based RPC executors are used, retrieves the number of Calls that were picked from the 112 * tail of the queue (indicating adaptive LIFO mode, when in the period of overloade we serve last 113 * requests first); returns 0 otherwise. 114 */ 115 public abstract long getNumLifoModeSwitches(); 116 117 /** Retrieves length of the write queue for metrics when use RWQueueRpcExecutor. */ 118 public abstract int getWriteQueueLength(); 119 120 /** Retrieves length of the read queue for metrics when use RWQueueRpcExecutor. */ 121 public abstract int getReadQueueLength(); 122 123 /** Retrieves length of the scan queue for metrics when use RWQueueRpcExecutor. */ 124 public abstract int getScanQueueLength(); 125 126 /** Retrieves the number of active write rpc handler when use RWQueueRpcExecutor. */ 127 public abstract int getActiveWriteRpcHandlerCount(); 128 129 /** Retrieves the number of active write rpc handler when use RWQueueRpcExecutor. */ 130 public abstract int getActiveReadRpcHandlerCount(); 131 132 /** Retrieves the number of active write rpc handler when use RWQueueRpcExecutor. */ 133 public abstract int getActiveScanRpcHandlerCount(); 134}