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.io.IOException;
020import java.util.List;
021
022import org.apache.hadoop.fs.FileSystem;
023import org.apache.hadoop.hbase.TableName;
024import org.apache.yetus.audience.InterfaceAudience;
025import org.apache.yetus.audience.InterfaceStability;
026import org.apache.hadoop.hbase.client.Mutation;
027import org.apache.hadoop.hbase.regionserver.RegionServerServices;
028
029/**
030 * RegionServer implementation of {@link SpaceViolationPolicy}.
031 *
032 * Implementations must have a public, no-args constructor.
033 */
034@InterfaceAudience.Private
035@InterfaceStability.Evolving
036public interface SpaceViolationPolicyEnforcement {
037
038  /**
039   * Initializes this policy instance.
040   */
041  void initialize(RegionServerServices rss, TableName tableName, SpaceQuotaSnapshot snapshot);
042
043  /**
044   * Enables this policy. Not all policies have enable actions.
045   */
046  void enable() throws IOException;
047
048  /**
049   * Disables this policy. Not all policies have disable actions.
050   */
051  void disable() throws IOException;
052
053  /**
054   * Checks the given {@link Mutation} against <code>this</code> policy. If the
055   * {@link Mutation} violates the policy, this policy should throw a
056   * {@link SpaceLimitingException}.
057   *
058   * @throws SpaceLimitingException When the given mutation violates this policy.
059   */
060  void check(Mutation m) throws SpaceLimitingException;
061
062  /**
063   * Returns a logical name for the {@link SpaceViolationPolicy} that this enforcement is for.
064   */
065  String getPolicyName();
066
067  /**
068   * Returns whether or not compactions on this table should be disabled for this policy.
069   */
070  boolean areCompactionsDisabled();
071
072  /**
073   * Returns the {@link SpaceQuotaSnapshot} <code>this</code> was initialized with.
074   */
075  SpaceQuotaSnapshot getQuotaSnapshot();
076
077  /**
078   * Returns whether thet caller should verify any bulk loads against <code>this</code>.
079   */
080  boolean shouldCheckBulkLoads();
081
082  /**
083   * Checks the file at the given path against <code>this</code> policy and the current
084   * {@link SpaceQuotaSnapshot}. If the file would violate the policy, a
085   * {@link SpaceLimitingException} will be thrown.
086   *
087   * @param paths The paths in HDFS to files to be bulk loaded.
088   */
089  void checkBulkLoad(FileSystem fs, List<String> paths) throws SpaceLimitingException;
090
091}