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.regionserver.compactions;
019
020import java.io.IOException;
021import java.util.Collection;
022import org.apache.hadoop.conf.Configuration;
023import org.apache.hadoop.hbase.regionserver.HStoreFile;
024import org.apache.hadoop.hbase.regionserver.StoreConfigInformation;
025import org.apache.yetus.audience.InterfaceAudience;
026
027/**
028 * A compaction policy determines how to select files for compaction, how to compact them, and how
029 * to generate the compacted files.
030 */
031@InterfaceAudience.Private
032public abstract class CompactionPolicy {
033  protected CompactionConfiguration comConf;
034  protected StoreConfigInformation storeConfigInfo;
035
036  public CompactionPolicy(Configuration conf, StoreConfigInformation storeConfigInfo) {
037    this.storeConfigInfo = storeConfigInfo;
038    this.comConf = new CompactionConfiguration(conf, this.storeConfigInfo);
039  }
040
041  /**
042   * @param filesToCompact Files to compact. Can be null.
043   * @return True if we should run a major compaction.
044   */
045  public abstract boolean shouldPerformMajorCompaction(Collection<HStoreFile> filesToCompact)
046    throws IOException;
047
048  /**
049   * @param compactionSize Total size of some compaction
050   * @return whether this should be a large or small compaction
051   */
052  public abstract boolean throttleCompaction(long compactionSize);
053
054  /**
055   * Inform the policy that some configuration has been change, so cached value should be updated it
056   * any.
057   */
058  public void setConf(Configuration conf) {
059    this.comConf = new CompactionConfiguration(conf, this.storeConfigInfo);
060  }
061
062  /** Returns The current compaction configuration settings. */
063  public CompactionConfiguration getConf() {
064    return this.comConf;
065  }
066}