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