001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019package org.apache.hadoop.hbase.quotas;
020
021import org.apache.yetus.audience.InterfaceAudience;
022import org.apache.yetus.audience.InterfaceStability;
023import org.apache.hadoop.hbase.quotas.OperationQuota.OperationType;
024
025/**
026 * Internal interface used to interact with the user/table quota.
027 */
028@InterfaceAudience.Private
029@InterfaceStability.Evolving
030public interface QuotaLimiter {
031  /**
032   * Checks if it is possible to execute the specified operation.
033   *
034   * @param writeReqs the write requests that will be checked against the available quota
035   * @param estimateWriteSize the write size that will be checked against the available quota
036   * @param readReqs the read requests that will be checked against the available quota
037   * @param estimateReadSize the read size that will be checked against the available quota
038   * @throws RpcThrottlingException thrown if not enough available resources to perform operation.
039   */
040  void checkQuota(long writeReqs, long estimateWriteSize, long readReqs, long estimateReadSize)
041      throws RpcThrottlingException;
042
043  /**
044   * Removes the specified write and read amount from the quota.
045   * At this point the write and read amount will be an estimate,
046   * that will be later adjusted with a consumeWrite()/consumeRead() call.
047   *
048   * @param writeReqs the write requests that will be removed from the current quota
049   * @param writeSize the write size that will be removed from the current quota
050   * @param readReqs the read requests that will be removed from the current quota
051   * @param readSize the read size that will be removed from the current quota
052   */
053  void grabQuota(long writeReqs, long writeSize, long readReqs, long readSize);
054
055  /**
056   * Removes or add back some write amount to the quota.
057   * (called at the end of an operation in case the estimate quota was off)
058   */
059  void consumeWrite(long size);
060
061  /**
062   * Removes or add back some read amount to the quota.
063   * (called at the end of an operation in case the estimate quota was off)
064   */
065  void consumeRead(long size);
066
067  /** @return true if the limiter is a noop */
068  boolean isBypass();
069
070    /** @return the number of bytes available to read to avoid exceeding the quota */
071  long getReadAvailable();
072
073  /** @return the number of bytes available to write to avoid exceeding the quota */
074  long getWriteAvailable();
075}