View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to you under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    * http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.hadoop.hbase.quotas;
18  
19  import java.io.IOException;
20  import java.util.Map;
21  import java.util.Map.Entry;
22  
23  import org.apache.hadoop.hbase.HRegionInfo;
24  import org.apache.hadoop.hbase.protobuf.generated.QuotaProtos.SpaceQuota;
25  import org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshot.SpaceQuotaStatus;
26  
27  /**
28   * A common interface for computing quota observance/violation for tables or namespaces. 
29   */
30  public interface QuotaSnapshotStore<T> {
31  
32    /**
33     * The current state of a table with respect to the policy set forth by a quota.
34     */
35    public enum ViolationState {
36      IN_VIOLATION,
37      IN_OBSERVANCE,
38    }
39  
40    /**
41     * Singleton to represent a table without a quota defined. It is never in violation.
42     */
43    public static final SpaceQuotaSnapshot NO_QUOTA = new SpaceQuotaSnapshot(SpaceQuotaStatus.notInViolation(), -1, -1);
44  
45    /**
46     * Fetch the Quota for the given table. May be null.
47     */
48    SpaceQuota getSpaceQuota(T subject) throws IOException;
49  
50    /**
51     * Returns the current {@link ViolationState} for the given <code>subject</code>.
52     */
53    SpaceQuotaSnapshot getCurrentState(T subject);
54  
55    /**
56     * Computes the target {@link ViolationState} for the given <code>subject</code>.
57     */
58    SpaceQuotaSnapshot getTargetState(T subject, SpaceQuota spaceQuota);
59  
60    /**
61     * Filters the provided <code>regions</code>, returning those which match the given
62     * <code>subject</code>.
63     *
64     * @param subject The filter criteria.
65     */
66    Iterable<Entry<HRegionInfo,Long>> filterBySubject(T subject);
67  
68    /**
69     * Sets the current {@link ViolationState} for the <code>subject</code>.
70     */
71    void setCurrentState(T subject, SpaceQuotaSnapshot state);
72  
73    /**
74     * Updates {@code this} with the latest snapshot of filesystem use by region.
75     *
76     * @param regionUsage A map of {@code HRegionInfo} objects to their filesystem usage in bytes
77     */
78    void setRegionUsage(Map<HRegionInfo,Long> regionUsage);
79  }