001/** 002 * 003 * Licensed to the Apache Software Foundation (ASF) under one 004 * or more contributor license agreements. See the NOTICE file 005 * distributed with this work for additional information 006 * regarding copyright ownership. The ASF licenses this file 007 * to you under the Apache License, Version 2.0 (the 008 * "License"); you may not use this file except in compliance 009 * with the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 */ 019 020package org.apache.hadoop.hbase.regionserver.compactions; 021 022import java.io.IOException; 023import java.util.Collection; 024 025import org.apache.hadoop.conf.Configuration; 026import org.apache.hadoop.hbase.regionserver.HStoreFile; 027import org.apache.hadoop.hbase.regionserver.StoreConfigInformation; 028import org.apache.yetus.audience.InterfaceAudience; 029 030/** 031 * A compaction policy determines how to select files for compaction, 032 * how to compact them, and how to generate the compacted files. 033 */ 034@InterfaceAudience.Private 035public abstract class CompactionPolicy { 036 protected CompactionConfiguration comConf; 037 protected StoreConfigInformation storeConfigInfo; 038 039 public CompactionPolicy(Configuration conf, StoreConfigInformation storeConfigInfo) { 040 this.storeConfigInfo = storeConfigInfo; 041 this.comConf = new CompactionConfiguration(conf, this.storeConfigInfo); 042 } 043 044 /** 045 * @param filesToCompact Files to compact. Can be null. 046 * @return True if we should run a major compaction. 047 */ 048 public abstract boolean shouldPerformMajorCompaction(Collection<HStoreFile> filesToCompact) 049 throws IOException; 050 051 /** 052 * @param compactionSize Total size of some compaction 053 * @return whether this should be a large or small compaction 054 */ 055 public abstract boolean throttleCompaction(long compactionSize); 056 057 /** 058 * Inform the policy that some configuration has been change, 059 * so cached value should be updated it any. 060 */ 061 public void setConf(Configuration conf) { 062 this.comConf = new CompactionConfiguration(conf, this.storeConfigInfo); 063 } 064 065 /** 066 * @return The current compaction configuration settings. 067 */ 068 public CompactionConfiguration getConf() { 069 return this.comConf; 070 } 071}