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_HANDLER_FACTOR = 0.5f;
039  public static final float DEFAULT_META_CALL_QUEUE_READ_SHARE = 0.8f;
040  private static final float DEFAULT_META_CALL_QUEUE_SCAN_SHARE = 0.2f;
041
042  public MetaRWQueueRpcExecutor(final String name, final int handlerCount, final int maxQueueLength,
043    final PriorityFunction priority, final Configuration conf, final Abortable abortable) {
044    super(name, handlerCount, maxQueueLength, priority, conf, abortable);
045  }
046
047  @Override
048  protected float getReadShare(final Configuration conf) {
049    return conf.getFloat(META_CALL_QUEUE_READ_SHARE_CONF_KEY, DEFAULT_META_CALL_QUEUE_READ_SHARE);
050  }
051
052  @Override
053  protected float getScanShare(final Configuration conf) {
054    return conf.getFloat(META_CALL_QUEUE_SCAN_SHARE_CONF_KEY, DEFAULT_META_CALL_QUEUE_SCAN_SHARE);
055  }
056
057  @Override
058  public boolean dispatch(CallRunner callTask) {
059    RpcCall call = callTask.getRpcCall();
060    int level = call.getHeader().getPriority();
061    final boolean toWriteQueue = isWriteRequest(call.getHeader(), call.getParam());
062    // dispatch client system read request to read handlers
063    // dispatch internal system read request to scan handlers
064    final boolean toScanQueue =
065      getNumScanQueues() > 0 && level == RSAnnotationReadingPriorityFunction.INTERNAL_READ_QOS;
066    return dispatchTo(toWriteQueue, toScanQueue, callTask);
067  }
068
069  @Override
070  protected float getCallQueueHandlerFactor(Configuration conf) {
071    return conf.getFloat(META_CALL_QUEUE_HANDLER_FACTOR_CONF_KEY,
072      DEFAULT_META_CALL_QUEUE_HANDLER_FACTOR);
073  }
074}