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.policies;
019
020import java.io.IOException;
021import java.util.List;
022import org.apache.hadoop.fs.FileSystem;
023import org.apache.hadoop.hbase.client.Mutation;
024import org.apache.hadoop.hbase.quotas.SpaceLimitingException;
025import org.apache.hadoop.hbase.quotas.SpaceViolationPolicyEnforcement;
026import org.apache.yetus.audience.InterfaceAudience;
027
028/**
029 * A {@link SpaceViolationPolicyEnforcement} which can be treated as a singleton. When a quota is
030 * not defined on a table or we lack quota information, we want to avoid creating a policy, keeping
031 * this path fast.
032 */
033@InterfaceAudience.Private
034public final class MissingSnapshotViolationPolicyEnforcement
035  extends AbstractViolationPolicyEnforcement {
036  private static final MissingSnapshotViolationPolicyEnforcement SINGLETON =
037    new MissingSnapshotViolationPolicyEnforcement();
038
039  private MissingSnapshotViolationPolicyEnforcement() {
040  }
041
042  @edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "MS_EXPOSE_REP",
043      justification = "singleton pattern")
044  public static SpaceViolationPolicyEnforcement getInstance() {
045    return SINGLETON;
046  }
047
048  @Override
049  public boolean shouldCheckBulkLoads() {
050    return false;
051  }
052
053  @Override
054  public long computeBulkLoadSize(FileSystem fs, List<String> paths) throws SpaceLimitingException {
055    long size = 0;
056    for (String path : paths) {
057      size += getFileSize(fs, path);
058    }
059    return size;
060  }
061
062  @Override
063  public void enable() throws IOException {
064  }
065
066  @Override
067  public void disable() throws IOException {
068  }
069
070  @Override
071  public void check(Mutation m) throws SpaceLimitingException {
072  }
073
074  @Override
075  public String getPolicyName() {
076    return "NoQuota";
077  }
078}