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 */ 018 019package org.apache.hadoop.hbase.quotas; 020 021import java.util.List; 022 023import org.apache.yetus.audience.InterfaceAudience; 024import org.apache.yetus.audience.InterfaceStability; 025import org.apache.hadoop.hbase.client.Mutation; 026import org.apache.hadoop.hbase.client.Result; 027 028/** 029 * Interface that allows to check the quota available for an operation. 030 */ 031@InterfaceAudience.Private 032@InterfaceStability.Evolving 033public interface OperationQuota { 034 public enum OperationType { MUTATE, GET, SCAN } 035 036 /** 037 * Checks if it is possible to execute the specified operation. 038 * The quota will be estimated based on the number of operations to perform 039 * and the average size accumulated during time. 040 * 041 * @param numWrites number of write operation that will be performed 042 * @param numReads number of small-read operation that will be performed 043 * @param numScans number of long-read operation that will be performed 044 * @throws RpcThrottlingException if the operation cannot be performed because 045 * RPC quota is exceeded. 046 */ 047 void checkQuota(int numWrites, int numReads, int numScans) 048 throws RpcThrottlingException; 049 050 /** Cleanup method on operation completion */ 051 void close(); 052 053 /** 054 * Add a get result. This will be used to calculate the exact quota and 055 * have a better short-read average size for the next time. 056 */ 057 void addGetResult(Result result); 058 059 /** 060 * Add a scan result. This will be used to calculate the exact quota and 061 * have a better long-read average size for the next time. 062 */ 063 void addScanResult(List<Result> results); 064 065 /** 066 * Add a mutation result. This will be used to calculate the exact quota and 067 * have a better mutation average size for the next time. 068 */ 069 void addMutation(Mutation mutation); 070 071 /** @return the number of bytes available to read to avoid exceeding the quota */ 072 long getReadAvailable(); 073 074 /** @return the number of bytes available to write to avoid exceeding the quota */ 075 long getWriteAvailable(); 076}