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.policies;
18  
19  import java.util.concurrent.atomic.AtomicBoolean;
20  
21  import org.apache.commons.logging.Log;
22  import org.apache.commons.logging.LogFactory;
23  import org.apache.hadoop.hbase.quotas.SpaceViolationPolicy;
24  import org.apache.hadoop.hbase.quotas.SpaceViolationPolicyEnforcement;
25  
26  /**
27   * A {@link SpaceViolationPolicyEnforcement} implementation which disables all updates and
28   * compactions. The enforcement counterpart to {@link SpaceViolationPolicy#NO_WRITES_COMPACTIONS}.
29   */
30  public class NoWritesCompactionsViolationPolicyEnforcement
31      extends NoWritesViolationPolicyEnforcement {
32    private static final Log LOG = LogFactory.getLog(
33        NoWritesCompactionsViolationPolicyEnforcement.class);
34  
35    private AtomicBoolean disableCompactions = new AtomicBoolean(false);
36  
37    @Override
38    public synchronized void enable() {
39      boolean ret = disableCompactions.compareAndSet(false, true);
40      if (!ret && LOG.isTraceEnabled()) {
41        LOG.trace("Compactions were already disabled upon enabling the policy");
42      }
43    }
44  
45    @Override
46    public synchronized void disable() {
47      boolean ret = disableCompactions.compareAndSet(true, false);
48      if (!ret && LOG.isTraceEnabled()) {
49        LOG.trace("Compactions were already enabled upon disabling the policy");
50      }
51    }
52  
53    @Override
54    public String getPolicyName() {
55      return SpaceViolationPolicy.NO_WRITES_COMPACTIONS.name();
56    }
57  
58    @Override
59    public boolean areCompactionsDisabled() {
60      return disableCompactions.get();
61    }
62  }