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
25 import org.apache.hadoop.hbase.classification.InterfaceAudience;
26 import org.apache.hadoop.conf.Configuration;
27 import org.apache.hadoop.hbase.regionserver.StoreConfigInformation;
28 import org.apache.hadoop.hbase.regionserver.StoreFile;
29
30 /**
31 * A compaction policy determines how to select files for compaction,
32 * how to compact them, and how to generate the compacted files.
33 */
34 @InterfaceAudience.Private
35 public abstract class CompactionPolicy {
36 protected CompactionConfiguration comConf;
37 protected StoreConfigInformation storeConfigInfo;
38
39 public CompactionPolicy(Configuration conf, StoreConfigInformation storeConfigInfo) {
40 this.storeConfigInfo = storeConfigInfo;
41 this.comConf = new CompactionConfiguration(conf, this.storeConfigInfo);
42 }
43
44 /**
45 * @param filesToCompact Files to compact. Can be null.
46 * @return True if we should run a major compaction.
47 */
48 public abstract boolean shouldPerformMajorCompaction(
49 final Collection<StoreFile> filesToCompact) throws IOException;
50
51 /**
52 * @param compactionSize Total size of some compaction
53 * @return whether this should be a large or small compaction
54 */
55 public abstract boolean throttleCompaction(long compactionSize);
56
57 /**
58 * Inform the policy that some configuration has been change,
59 * so cached value should be updated it any.
60 */
61 public void setConf(Configuration conf) {
62 this.comConf = new CompactionConfiguration(conf, this.storeConfigInfo);
63 }
64
65
66
67 /**
68 * @return The current compaction configuration settings.
69 */
70 public CompactionConfiguration getConf() {
71 return this.comConf;
72 }
73 }