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.List;
21
22 import org.apache.hadoop.fs.FileSystem;
23 import org.apache.hadoop.hbase.TableName;
24 import org.apache.hadoop.hbase.client.Mutation;
25 import org.apache.hadoop.hbase.quotas.SpaceViolationPolicy;
26 import org.apache.hadoop.hbase.regionserver.RegionServerServices;
27
28 /**
29 * RegionServer implementation of {@link SpaceViolationPolicy}.
30 *
31 * Implementations must have a public, no-args constructor.
32 */
33 public interface SpaceViolationPolicyEnforcement {
34
35 /**
36 * Initializes this policy instance.
37 */
38 void initialize(RegionServerServices rss, TableName tableName, SpaceQuotaSnapshot snapshot);
39
40 /**
41 * Enables this policy. Not all policies have enable actions.
42 */
43 void enable() throws IOException;
44
45 /**
46 * Disables this policy. Not all policies have disable actions.
47 */
48 void disable() throws IOException;
49
50 /**
51 * Checks the given {@link Mutation} against <code>this</code> policy. If the
52 * {@link Mutation} violates the policy, this policy should throw a
53 * {@link SpaceLimitingException}.
54 *
55 * @throws SpaceLimitingException When the given mutation violates this policy.
56 */
57 void check(Mutation m) throws SpaceLimitingException;
58
59 /**
60 * Returns a logical name for the {@link SpaceViolationPolicy} that this enforcement is for.
61 */
62 String getPolicyName();
63
64 /**
65 * Returns whether or not compactions on this table should be disabled for this policy.
66 */
67 boolean areCompactionsDisabled();
68
69 /**
70 * Returns the {@link SpaceQuotaSnapshot} <code>this</code> was initialized with.
71 */
72 SpaceQuotaSnapshot getQuotaSnapshot();
73
74 /**
75 * Returns whether the caller should verify any bulk loads against <code>this</code>.
76 */
77 boolean shouldCheckBulkLoads();
78
79 /**
80 * Checks the file at the given path against <code>this</code> policy and the current
81 * {@link SpaceQuotaSnapshot}. If the file would violate the policy, a
82 * {@link SpaceLimitingException} will be thrown.
83 *
84 * @param paths The paths in HDFS to files to be bulk loaded.
85 */
86 void checkBulkLoad(FileSystem fs, List<String> paths) throws SpaceLimitingException;
87
88 }