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.quotas; 019 020import java.io.IOException; 021import org.apache.hadoop.hbase.exceptions.DeserializationException; 022import org.apache.hadoop.hbase.master.BooleanStateStore; 023import org.apache.hadoop.hbase.master.region.MasterRegion; 024import org.apache.hadoop.hbase.util.Bytes; 025import org.apache.hadoop.hbase.zookeeper.ZKWatcher; 026import org.apache.yetus.audience.InterfaceAudience; 027import org.apache.zookeeper.KeeperException; 028 029/** 030 * Store whether rpc throttle is enabled. 031 * <p> 032 * Notice that, this is stored in master local region so only master can read it. For region 033 * servers, we will publish the change through 034 * {@link org.apache.hadoop.hbase.master.procedure.SwitchRpcThrottleProcedure} and region servers 035 * can also query the flag through rpc request to master. 036 */ 037@InterfaceAudience.Private 038public class RpcThrottleStateStore extends BooleanStateStore { 039 040 public static final String RPC_THROTTLE_ZNODE = "zookeeper.znode.quota.rpc.throttle"; 041 public static final String RPC_THROTTLE_ZNODE_DEFAULT = "rpc-throttle"; 042 043 public static final String STATE_NAME = "rpc-throttle"; 044 045 public RpcThrottleStateStore(MasterRegion masterRegion, ZKWatcher watcher, String zkPath) 046 throws IOException, KeeperException, DeserializationException { 047 super(masterRegion, STATE_NAME, watcher, zkPath); 048 } 049 050 @Override 051 protected byte[] toByteArray(boolean on) { 052 return Bytes.toBytes(on); 053 } 054 055 @Override 056 protected boolean parseFrom(byte[] bytes) throws DeserializationException { 057 return Bytes.toBoolean(bytes); 058 } 059 060}