001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to you under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.hadoop.hbase.quotas;
018
019import java.util.Map.Entry;
020
021import org.apache.hadoop.hbase.client.RegionInfo;
022import org.apache.hadoop.hbase.io.HeapSize;
023import org.apache.yetus.audience.InterfaceAudience;
024
025/**
026 * An interface for concurrently storing and updating the size of a Region.
027 */
028@InterfaceAudience.Private
029public interface RegionSizeStore extends Iterable<Entry<RegionInfo,RegionSize>>, HeapSize {
030
031  /**
032   * Returns the size for the give region if one exists. If no size exists, {@code null} is
033   * returned.
034   *
035   * @param regionInfo The region whose size is being fetched.
036   * @return The size in bytes of the region or null if no size is stored.
037   */
038  RegionSize getRegionSize(RegionInfo regionInfo);
039
040  /**
041   * Atomically sets the given {@code size} for a region.
042   *
043   * @param regionInfo An identifier for a region.
044   * @param size The size in bytes of the region.
045   */
046  void put(RegionInfo regionInfo, long size);
047
048  /**
049   * Atomically alter the size of a region.
050   *
051   * @param regionInfo The region to update.
052   * @param delta The change in size for the region, positive or negative.
053   */
054  void incrementRegionSize(RegionInfo regionInfo, long delta);
055
056  /**
057   * Removes the mapping for the given key, returning the value if one exists in the store.
058   *
059   * @param regionInfo The key to remove from the store
060   * @return The value removed from the store if one exists, otherwise null.
061   */
062  RegionSize remove(RegionInfo regionInfo);
063
064  /**
065   * Returns the number of entries in the store.
066   *
067   * @return The number of entries in the store.
068   */
069  int size();
070
071  /**
072   * Returns if the store is empty.
073   *
074   * @return true if there are no entries in the store, otherwise false.
075   */
076  boolean isEmpty();
077
078  /**
079   * Removes all entries from the store.
080   */
081  void clear();
082}