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  import org.apache.hadoop.hbase.quotas.OperationQuota.OperationType;
24  
25  /**
26   * Internal interface used to interact with the user/table quota.
27   */
28  @InterfaceAudience.Private
29  @InterfaceStability.Evolving
30  public interface QuotaLimiter {
31    /**
32     * Checks if it is possible to execute the specified operation.
33     *
34     * @param writeReqs the write requests that will be checked against the available quota
35     * @param estimateWriteSize the write size that will be checked against the available quota
36     * @param readReqs the read requests that will be checked against the available quota
37     * @param estimateReadSize the read size that will be checked against the available quota
38     * @throws ThrottlingException thrown if not enough avialable resources to perform operation.
39     */
40    void checkQuota(long writeReqs, long estimateWriteSize, long readReqs, long estimateReadSize)
41      throws ThrottlingException;
42  
43    /**
44     * Removes the specified write and read amount from the quota.
45     * At this point the write and read amount will be an estimate,
46     * that will be later adjusted with a consumeWrite()/consumeRead() call.
47     *
48     * @param writeReqs the write requests that will be removed from the current quota
49     * @param writeSize the write size that will be removed from the current quota
50     * @param readReqs the read requests that will be removed from the current quota
51     * @param readSize the read size that will be removed from the current quota
52     */
53    void grabQuota(long writeReqs, long writeSize, long readReqs, long readSize);
54  
55    /**
56     * Removes or add back some write amount to the quota.
57     * (called at the end of an operation in case the estimate quota was off)
58     */
59    void consumeWrite(long size);
60  
61    /**
62     * Removes or add back some read amount to the quota.
63     * (called at the end of an operation in case the estimate quota was off)
64     */
65    void consumeRead(long size);
66  
67    /** @return true if the limiter is a noop */
68    boolean isBypass();
69  
70      /** @return the number of bytes available to read to avoid exceeding the quota */
71    long getReadAvailable();
72  
73    /** @return the number of bytes available to write to avoid exceeding the quota */
74    long getWriteAvailable();
75  }