View Javadoc

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.
33     * The quota will be estimated based on the number of operations to perform
34     * and the average size accumulated during time.
35     *
36     * @param numWrites number of write operation that will be performed
37     * @param numReads number of small-read operation that will be performed
38     * @param numScans number of long-read operation that will be performed
39     * @throws ThrottlingException if the operation cannot be performed
40     */
41    void checkQuota(int numWrites, int numReads, int numScans) throws ThrottlingException;
42  
43    /** Cleanup method on operation completion */
44    void close();
45  
46    /**
47     * Add a get result. This will be used to calculate the exact quota and have a better short-read
48     * average size for the next time.
49     */
50    void addGetResult(Result result);
51  
52    /**
53     * Add a scan result. This will be used to calculate the exact quota and have a better long-read
54     * average size for the next time.
55     */
56    void addScanResult(List<Result> results);
57  
58    /**
59     * Add a mutation result. This will be used to calculate the exact quota and have a better
60     * mutation average size for the next time.
61     */
62    void addMutation(Mutation mutation);
63  
64    /** @return the number of bytes available to read to avoid exceeding the quota */
65    long getReadAvailable();
66  
67    /** @return the number of bytes available to write to avoid exceeding the quota */
68    long getWriteAvailable();
69  }