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 number of active handler. */ 084 public abstract int getActiveRpcHandlerCount(); 085 086 /** 087 * If CoDel-based RPC executors are used, retrieves the number of Calls that were dropped 088 * from general queue because RPC executor is under high load; returns 0 otherwise. 089 */ 090 public abstract long getNumGeneralCallsDropped(); 091 092 /** 093 * If CoDel-based RPC executors are used, retrieves the number of Calls that were 094 * picked from the tail of the queue (indicating adaptive LIFO mode, when 095 * in the period of overloade we serve last requests first); returns 0 otherwise. 096 */ 097 public abstract long getNumLifoModeSwitches(); 098 099 /** Retrieves length of the write queue for metrics when use RWQueueRpcExecutor. */ 100 public abstract int getWriteQueueLength(); 101 102 /** Retrieves length of the read queue for metrics when use RWQueueRpcExecutor. */ 103 public abstract int getReadQueueLength(); 104 105 /** Retrieves length of the scan queue for metrics when use RWQueueRpcExecutor. */ 106 public abstract int getScanQueueLength(); 107 108 /** Retrieves the number of active write rpc handler when use RWQueueRpcExecutor. */ 109 public abstract int getActiveWriteRpcHandlerCount(); 110 111 /** Retrieves the number of active write rpc handler when use RWQueueRpcExecutor. */ 112 public abstract int getActiveReadRpcHandlerCount(); 113 114 /** Retrieves the number of active write rpc handler when use RWQueueRpcExecutor. */ 115 public abstract int getActiveScanRpcHandlerCount(); 116}