View Javadoc

1   /**
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  
20  package org.apache.hadoop.hbase.regionserver.compactions;
21  
22  import java.io.IOException;
23  import java.util.Collection;
24  import java.util.List;
25  
26  import org.apache.hadoop.classification.InterfaceAudience;
27  import org.apache.hadoop.conf.Configuration;
28  import org.apache.hadoop.hbase.regionserver.StoreConfigInformation;
29  import org.apache.hadoop.hbase.regionserver.StoreFile;
30  
31  /**
32   * A compaction policy determines how to select files for compaction,
33   * how to compact them, and how to generate the compacted files.
34   */
35  @InterfaceAudience.Private
36  public abstract class CompactionPolicy {
37    protected CompactionConfiguration comConf;
38    protected StoreConfigInformation storeConfigInfo;
39  
40    public CompactionPolicy(Configuration conf, StoreConfigInformation storeConfigInfo) {
41      this.storeConfigInfo = storeConfigInfo;
42      this.comConf = new CompactionConfiguration(conf, this.storeConfigInfo);
43    }
44  
45    /**
46     * @param filesToCompact Files to compact. Can be null.
47     * @return True if we should run a major compaction.
48     */
49    public abstract boolean isMajorCompaction(
50      final Collection<StoreFile> filesToCompact) throws IOException;
51  
52    /**
53     * @param compactionSize Total size of some compaction
54     * @return whether this should be a large or small compaction
55     */
56    public abstract boolean throttleCompaction(long compactionSize);
57  
58    /**
59     * Inform the policy that some configuration has been change,
60     * so cached value should be updated it any.
61     */
62    public void setConf(Configuration conf) {
63      this.comConf = new CompactionConfiguration(conf, this.storeConfigInfo);
64    }
65  }