1 /** 2 * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 3 * agreements. See the NOTICE file distributed with this work for additional information regarding 4 * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the 5 * "License"); you may not use this file except in compliance with the License. You may obtain a 6 * copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable 7 * law or agreed to in writing, software distributed under the License is distributed on an "AS IS" 8 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License 9 * for the specific language governing permissions and limitations under the License. 10 */ 11 12 package org.apache.hadoop.hbase.quotas; 13 14 import java.util.List; 15 16 import org.apache.hadoop.hbase.classification.InterfaceAudience; 17 import org.apache.hadoop.hbase.classification.InterfaceStability; 18 import org.apache.hadoop.hbase.client.Mutation; 19 import org.apache.hadoop.hbase.client.Result; 20 21 /** 22 * Interface that allows to check the quota available for an operation. 23 */ 24 @InterfaceAudience.Private 25 @InterfaceStability.Evolving 26 public interface OperationQuota { 27 public enum OperationType { 28 MUTATE, GET, SCAN 29 } 30 31 /** 32 * Checks if it is possible to execute the specified operation. The quota will be estimated based 33 * on the number of operations to perform and the average size accumulated during time. 34 * @param numWrites number of write operation that will be performed 35 * @param numReads number of small-read operation that will be performed 36 * @param numScans number of long-read operation that will be performed 37 * @throws ThrottlingException if the operation cannot be performed 38 */ 39 void checkQuota(int numWrites, int numReads, int numScans) throws ThrottlingException; 40 41 /** Cleanup method on operation completion */ 42 void close(); 43 44 /** 45 * Add a get result. This will be used to calculate the exact quota and have a better short-read 46 * average size for the next time. 47 */ 48 void addGetResult(Result result); 49 50 /** 51 * Add a scan result. This will be used to calculate the exact quota and have a better long-read 52 * average size for the next time. 53 */ 54 void addScanResult(List<Result> results); 55 56 /** 57 * Add a mutation result. This will be used to calculate the exact quota and have a better 58 * mutation average size for the next time. 59 */ 60 void addMutation(Mutation mutation); 61 62 /** @return the number of bytes available to read to avoid exceeding the quota */ 63 long getReadAvailable(); 64 65 /** @return the number of bytes available to write to avoid exceeding the quota */ 66 long getWriteAvailable(); 67 }