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