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 package org.apache.hadoop.hbase.regionserver.compactions; 20 21 import java.io.IOException; 22 import java.util.List; 23 24 import org.apache.hadoop.hbase.classification.InterfaceAudience; 25 import org.apache.hadoop.fs.Path; 26 import org.apache.hadoop.hbase.regionserver.StoreFile; 27 import org.apache.hadoop.hbase.security.User; 28 29 30 /** 31 * This class holds all "physical" details necessary to run a compaction, 32 * and abstracts away the details specific to a particular compaction. 33 * It also has compaction request with all the logical details. 34 * Hence, this class is basically the compaction. 35 */ 36 @InterfaceAudience.Private 37 public abstract class CompactionContext { 38 protected CompactionRequest request = null; 39 40 /** 41 * Called before coprocessor preCompactSelection and should filter the candidates 42 * for coprocessor; i.e. exclude the files that definitely cannot be compacted at this time. 43 * @param filesCompacting files currently compacting 44 * @return the list of files that can theoretically be compacted. 45 */ 46 public abstract List<StoreFile> preSelect(final List<StoreFile> filesCompacting); 47 48 /** 49 * Called to select files for compaction. Must fill in the request field if successful. 50 * @param filesCompacting Files currently being compacted by other compactions. 51 * @param isUserCompaction Whether this is a user compaction. 52 * @param mayUseOffPeak Whether the underlying policy may assume it's off-peak hours. 53 * @param forceMajor Whether to force major compaction. 54 * @return Whether the selection succeeded. Selection may be empty and lead to no compaction. 55 */ 56 public abstract boolean select( 57 final List<StoreFile> filesCompacting, final boolean isUserCompaction, 58 final boolean mayUseOffPeak, final boolean forceMajor) throws IOException; 59 60 /** 61 * Forces external selection to be applied for this compaction. 62 * @param request The pre-cooked request with selection and other settings. 63 */ 64 public void forceSelect(CompactionRequest request) { 65 this.request = request; 66 } 67 68 /** 69 * Runs the compaction based on current selection. select/forceSelect must have been called. 70 * @return The new file paths resulting from compaction. 71 */ 72 public abstract List<Path> compact(CompactionThroughputController throughputController) 73 throws IOException; 74 75 public abstract List<Path> compact(CompactionThroughputController throughputController, User user) 76 throws IOException; 77 78 public CompactionRequest getRequest() { 79 assert hasSelection(); 80 return this.request; 81 } 82 83 public boolean hasSelection() { 84 return this.request != null; 85 } 86 }