View Javadoc

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.util.ArrayList;
22  import java.util.List;
23  
24  import org.apache.commons.logging.Log;
25  import org.apache.commons.logging.LogFactory;
26  import org.apache.hadoop.classification.InterfaceAudience;
27  import org.apache.hadoop.hbase.regionserver.StoreFile;
28  import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
29  
30  @InterfaceAudience.Private
31  public class CompactSelection {
32    private static final long serialVersionUID = 1L;
33    static final Log LOG = LogFactory.getLog(CompactSelection.class);
34    // the actual list - this is needed to handle methods like "sublist" correctly
35    List<StoreFile> filesToCompact = new ArrayList<StoreFile>();
36    // was this compaction promoted to an off-peak
37    boolean isOffPeakCompaction = false;
38    // CompactSelection object creation time.
39    private final long selectionTime;
40  
41    public CompactSelection(List<StoreFile> filesToCompact) {
42      this.selectionTime = EnvironmentEdgeManager.currentTimeMillis();
43      this.filesToCompact = filesToCompact;
44      this.isOffPeakCompaction = false;
45    }
46  
47    public List<StoreFile> getFilesToCompact() {
48      return filesToCompact;
49    }
50  
51    /**
52     * Removes all files from the current compaction list, and resets off peak
53     * compactions is set.
54     */
55    public void emptyFileList() {
56      filesToCompact.clear();
57    }
58  
59    public boolean isOffPeakCompaction() {
60      return this.isOffPeakCompaction;
61    }
62  
63    public void setOffPeak(boolean value) {
64      this.isOffPeakCompaction = value;
65    }
66  
67    public long getSelectionTime() {
68      return selectionTime;
69    }
70  
71    public CompactSelection getSubList(int start, int end) {
72      filesToCompact = filesToCompact.subList(start, end);
73      return this;
74    }
75  
76    public void clearSubList(int start, int end) {
77      filesToCompact.subList(start, end).clear();
78    }
79  }