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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 package org
.apache
.hadoop
.hbase
.quotas
;
21 import org
.apache
.yetus
.audience
.InterfaceAudience
;
22 import org
.apache
.yetus
.audience
.InterfaceStability
;
25 * Internal interface used to interact with the user/table quota.
27 @InterfaceAudience.Private
28 @InterfaceStability.Evolving
29 public interface QuotaLimiter
{
31 * Checks if it is possible to execute the specified operation.
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
39 * @param estimateReadCapacityUnit the read capacity unit that will be checked against the
41 * @throws RpcThrottlingException thrown if not enough available resources to perform operation.
43 void checkQuota(long writeReqs
, long estimateWriteSize
, long readReqs
, long estimateReadSize
,
44 long estimateWriteCapacityUnit
, long estimateReadCapacityUnit
) throws RpcThrottlingException
;
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.
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
58 void grabQuota(long writeReqs
, long writeSize
, long readReqs
, long readSize
,
59 long writeCapacityUnit
, long readCapacityUnit
);
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)
65 void consumeWrite(long size
, long capacityUnit
);
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)
71 void consumeRead(long size
, long capacityUnit
);
73 /** @return true if the limiter is a noop */
76 /** @return the number of bytes available to read to avoid exceeding the quota */
77 long getReadAvailable();
79 /** @return the number of bytes available to write to avoid exceeding the quota */
80 long getWriteAvailable();