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 estimateWriteSize the write size that will be checked against the available quota
35     * @param estimateReadSize the read size that will be checked against the available quota
36     * @throws ThrottlingException thrown if not enough avialable resources to perform operation.
37     */
38    void checkQuota(long estimateWriteSize, long estimateReadSize)
39      throws ThrottlingException;
40  
41    /**
42     * Removes the specified write and read amount from the quota.
43     * At this point the write and read amount will be an estimate,
44     * that will be later adjusted with a consumeWrite()/consumeRead() call.
45     *
46     * @param writeSize the write size that will be removed from the current quota
47     * @param readSize the read size that will be removed from the current quota
48     */
49    void grabQuota(long writeSize, long readSize);
50  
51    /**
52     * Removes or add back some write amount to the quota.
53     * (called at the end of an operation in case the estimate quota was off)
54     */
55    void consumeWrite(long size);
56  
57    /**
58     * Removes or add back some read amount to the quota.
59     * (called at the end of an operation in case the estimate quota was off)
60     */
61    void consumeRead(long size);
62  
63    /** @return true if the limiter is a noop */
64    boolean isBypass();
65  
66      /** @return the number of bytes available to read to avoid exceeding the quota */
67    long getReadAvailable();
68  
69    /** @return the number of bytes available to write to avoid exceeding the quota */
70    long getWriteAvailable();
71  }