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 */ 019package org.apache.hadoop.hbase.regionserver.compactions; 020 021import java.io.IOException; 022import java.util.List; 023 024import org.apache.hadoop.fs.Path; 025import org.apache.hadoop.hbase.regionserver.HStoreFile; 026import org.apache.hadoop.hbase.regionserver.throttle.ThroughputController; 027import org.apache.hadoop.hbase.security.User; 028import org.apache.yetus.audience.InterfaceAudience; 029 030 031/** 032 * This class holds all "physical" details necessary to run a compaction, 033 * and abstracts away the details specific to a particular compaction. 034 * It also has compaction request with all the logical details. 035 * Hence, this class is basically the compaction. 036 */ 037@InterfaceAudience.Private 038public abstract class CompactionContext { 039 protected CompactionRequestImpl request = null; 040 041 /** 042 * Called before coprocessor preCompactSelection and should filter the candidates 043 * for coprocessor; i.e. exclude the files that definitely cannot be compacted at this time. 044 * @param filesCompacting files currently compacting 045 * @return the list of files that can theoretically be compacted. 046 */ 047 public abstract List<HStoreFile> preSelect(List<HStoreFile> filesCompacting); 048 049 /** 050 * Called to select files for compaction. Must fill in the request field if successful. 051 * @param filesCompacting Files currently being compacted by other compactions. 052 * @param isUserCompaction Whether this is a user compaction. 053 * @param mayUseOffPeak Whether the underlying policy may assume it's off-peak hours. 054 * @param forceMajor Whether to force major compaction. 055 * @return Whether the selection succeeded. Selection may be empty and lead to no compaction. 056 */ 057 public abstract boolean select(List<HStoreFile> filesCompacting, boolean isUserCompaction, 058 boolean mayUseOffPeak, boolean forceMajor) throws IOException; 059 060 /** 061 * Forces external selection to be applied for this compaction. 062 * @param request The pre-cooked request with selection and other settings. 063 */ 064 public void forceSelect(CompactionRequestImpl request) { 065 this.request = request; 066 } 067 068 public abstract List<Path> compact(ThroughputController throughputController, User user) 069 throws IOException; 070 071 public CompactionRequestImpl getRequest() { 072 assert hasSelection(); 073 return this.request; 074 } 075 076 public boolean hasSelection() { 077 return this.request != null; 078 } 079}