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 java.util.List; 022import org.apache.hadoop.hbase.HBaseInterfaceAudience; 023import org.apache.hadoop.hbase.regionserver.Region; 024import org.apache.yetus.audience.InterfaceAudience; 025import org.apache.yetus.audience.InterfaceStability; 026 027import org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos; 028 029@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC) 030@InterfaceStability.Evolving 031public interface RpcQuotaManager { 032 033 /** 034 * Check the quota for the current (rpc-context) user. Returns the OperationQuota used to get the 035 * available quota and to report the data/usage of the operation. This method is specific to scans 036 * because estimating a scan's workload is more complicated than estimating the workload of a 037 * get/put. 038 * @param region the region where the operation will be performed 039 * @param scanRequest the scan to be estimated against the quota 040 * @param maxScannerResultSize the maximum bytes to be returned by the scanner 041 * @param maxBlockBytesScanned the maximum bytes scanned in a single RPC call by the 042 * scanner 043 * @param prevBlockBytesScannedDifference the difference between BBS of the previous two next 044 * calls 045 * @return the OperationQuota 046 * @throws RpcThrottlingException if the operation cannot be executed due to quota exceeded. 047 */ 048 OperationQuota checkScanQuota(final Region region, final ClientProtos.ScanRequest scanRequest, 049 long maxScannerResultSize, long maxBlockBytesScanned, long prevBlockBytesScannedDifference) 050 throws IOException, RpcThrottlingException; 051 052 /** 053 * Check the quota for the current (rpc-context) user. Returns the OperationQuota used to get the 054 * available quota and to report the data/usage of the operation. This method does not support 055 * scans because estimating a scan's workload is more complicated than estimating the workload of 056 * a get/put. 057 * @param region the region where the operation will be performed 058 * @param type the operation type 059 * @return the OperationQuota 060 * @throws RpcThrottlingException if the operation cannot be executed due to quota exceeded. 061 */ 062 OperationQuota checkBatchQuota(final Region region, final OperationQuota.OperationType type) 063 throws IOException, RpcThrottlingException; 064 065 /** 066 * Check the quota for the current (rpc-context) user. Returns the OperationQuota used to get the 067 * available quota and to report the data/usage of the operation. This method does not support 068 * scans because estimating a scan's workload is more complicated than estimating the workload of 069 * a get/put. 070 * @param region the region where the operation will be performed 071 * @param actions the "multi" actions to perform 072 * @param hasCondition whether the RegionAction has a condition 073 * @return the OperationQuota 074 * @throws RpcThrottlingException if the operation cannot be executed due to quota exceeded. 075 */ 076 OperationQuota checkBatchQuota(final Region region, final List<ClientProtos.Action> actions, 077 boolean hasCondition) throws IOException, RpcThrottlingException; 078 079 /** 080 * Check the quota for the current (rpc-context) user. Returns the OperationQuota used to get the 081 * available quota and to report the data/usage of the operation. This method does not support 082 * scans because estimating a scan's workload is more complicated than estimating the workload of 083 * a get/put. 084 * @param region the region where the operation will be performed 085 * @param numWrites number of writes to count against quota 086 * @param numReads number of reads to count against quota 087 * @return the OperationQuota 088 * @throws RpcThrottlingException if the operation cannot be executed due to quota exceeded. 089 */ 090 OperationQuota checkBatchQuota(final Region region, int numWrites, int numReads) 091 throws IOException, RpcThrottlingException; 092}