View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  package org.apache.hadoop.hbase.quotas;
20  
21  import org.apache.hadoop.hbase.classification.InterfaceAudience;
22  import org.apache.hadoop.hbase.classification.InterfaceStability;
23  
24  /**
25   * Internal interface used to interact with the user/table quota.
26   */
27  @InterfaceAudience.Private
28  @InterfaceStability.Evolving
29  public interface QuotaLimiter {
30    /**
31     * Checks if it is possible to execute the specified operation.
32     *
33     * @param writeReqs the write requests that will be checked against the available quota
34     * @param estimateWriteSize the write size that will be checked against the available quota
35     * @param readReqs the read requests that will be checked against the available quota
36     * @param estimateReadSize the read size that will be checked against the available quota
37     * @param estimateWriteCapacityUnit the write capacity unit that will be checked against the
38     *          available quota
39     * @param estimateReadCapacityUnit the read capacity unit that will be checked against the
40     *          available quota
41     * @throws RpcThrottlingException thrown if not enough available resources to perform operation.
42     */
43    void checkQuota(long writeReqs, long estimateWriteSize, long readReqs, long estimateReadSize,
44        long estimateWriteCapacityUnit, long estimateReadCapacityUnit) throws RpcThrottlingException;
45  
46    /**
47     * Removes the specified write and read amount from the quota.
48     * At this point the write and read amount will be an estimate,
49     * that will be later adjusted with a consumeWrite()/consumeRead() call.
50     *
51     * @param writeReqs the write requests that will be removed from the current quota
52     * @param writeSize the write size that will be removed from the current quota
53     * @param readReqs the read requests that will be removed from the current quota
54     * @param readSize the read size that will be removed from the current quota
55     * @param writeCapacityUnit the write capacity unit that will be removed from the current quota
56     * @param readCapacityUnit the read capacity unit num that will be removed from the current quota
57     */
58    void grabQuota(long writeReqs, long writeSize, long readReqs, long readSize,
59        long writeCapacityUnit, long readCapacityUnit);
60  
61    /**
62     * Removes or add back some write amount to the quota.
63     * (called at the end of an operation in case the estimate quota was off)
64     */
65    void consumeWrite(long size, long capacityUnit);
66  
67    /**
68     * Removes or add back some read amount to the quota.
69     * (called at the end of an operation in case the estimate quota was off)
70     */
71    void consumeRead(long size, long capacityUnit);
72  
73    /** @return true if the limiter is a noop */
74    boolean isBypass();
75  
76      /** @return the number of bytes available to read to avoid exceeding the quota */
77    long getReadAvailable();
78  
79    /** @return the number of bytes available to write to avoid exceeding the quota */
80    long getWriteAvailable();
81  }