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.hadoop.conf.Configuration; 021import org.apache.hadoop.hbase.Abortable; 022import org.apache.hadoop.hbase.regionserver.RSAnnotationReadingPriorityFunction; 023import org.apache.yetus.audience.InterfaceAudience; 024import org.apache.yetus.audience.InterfaceStability; 025 026/** 027 * RPC Executor that uses different queues for reads and writes for meta. 028 */ 029@InterfaceAudience.Private 030@InterfaceStability.Evolving 031public class MetaRWQueueRpcExecutor extends RWQueueRpcExecutor { 032 public static final String META_CALL_QUEUE_READ_SHARE_CONF_KEY = 033 "hbase.ipc.server.metacallqueue.read.ratio"; 034 public static final String META_CALL_QUEUE_SCAN_SHARE_CONF_KEY = 035 "hbase.ipc.server.metacallqueue.scan.ratio"; 036 public static final String META_CALL_QUEUE_HANDLER_FACTOR_CONF_KEY = 037 "hbase.ipc.server.metacallqueue.handler.factor"; 038 public static final float DEFAULT_META_CALL_QUEUE_READ_SHARE = 0.8f; 039 private static final float DEFAULT_META_CALL_QUEUE_SCAN_SHARE = 0.2f; 040 041 public MetaRWQueueRpcExecutor(final String name, final int handlerCount, final int maxQueueLength, 042 final PriorityFunction priority, final Configuration conf, final Abortable abortable) { 043 super(name, handlerCount, maxQueueLength, priority, conf, abortable); 044 } 045 046 @Override 047 protected float getReadShare(final Configuration conf) { 048 return conf.getFloat(META_CALL_QUEUE_READ_SHARE_CONF_KEY, DEFAULT_META_CALL_QUEUE_READ_SHARE); 049 } 050 051 @Override 052 protected float getScanShare(final Configuration conf) { 053 return conf.getFloat(META_CALL_QUEUE_SCAN_SHARE_CONF_KEY, DEFAULT_META_CALL_QUEUE_SCAN_SHARE); 054 } 055 056 @Override 057 public boolean dispatch(CallRunner callTask) { 058 RpcCall call = callTask.getRpcCall(); 059 int level = call.getHeader().getPriority(); 060 final boolean toWriteQueue = isWriteRequest(call.getHeader(), call.getParam()); 061 // dispatch client system read request to read handlers 062 // dispatch internal system read request to scan handlers 063 final boolean toScanQueue = 064 getNumScanQueues() > 0 && level == RSAnnotationReadingPriorityFunction.INTERNAL_READ_QOS; 065 return dispatchTo(toWriteQueue, toScanQueue, callTask); 066 } 067 068 @Override 069 protected float getCallQueueHandlerFactor(Configuration conf) { 070 return conf.getFloat(META_CALL_QUEUE_HANDLER_FACTOR_CONF_KEY, 0.5f); 071 } 072}