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.mob.compactions;
20  
21  import java.io.IOException;
22  import java.util.Arrays;
23  import java.util.List;
24  import java.util.concurrent.ExecutorService;
25  
26  import org.apache.hadoop.conf.Configuration;
27  import org.apache.hadoop.fs.FileStatus;
28  import org.apache.hadoop.fs.FileSystem;
29  import org.apache.hadoop.fs.Path;
30  import org.apache.hadoop.hbase.HColumnDescriptor;
31  import org.apache.hadoop.hbase.TableName;
32  import org.apache.hadoop.hbase.classification.InterfaceAudience;
33  import org.apache.hadoop.hbase.mob.MobUtils;
34  import org.apache.hadoop.hbase.util.FSUtils;
35  
36  /**
37   * A mob compactor to directly compact the mob files.
38   */
39  @InterfaceAudience.Private
40  public abstract class MobCompactor {
41  
42    protected FileSystem fs;
43    protected Configuration conf;
44    protected TableName tableName;
45    protected HColumnDescriptor column;
46  
47    protected Path mobTableDir;
48    protected Path mobFamilyDir;
49    protected ExecutorService pool;
50  
51    public MobCompactor(Configuration conf, FileSystem fs, TableName tableName,
52      HColumnDescriptor column, ExecutorService pool) {
53      this.conf = conf;
54      this.fs = fs;
55      this.tableName = tableName;
56      this.column = column;
57      this.pool = pool;
58      mobTableDir = FSUtils.getTableDir(MobUtils.getMobHome(conf), tableName);
59      mobFamilyDir = MobUtils.getMobFamilyPath(conf, tableName, column.getNameAsString());
60    }
61  
62    /**
63     * Compacts the mob files for the current column family.
64     * @return The paths of new mob files generated in the compaction.
65     * @throws IOException
66     */
67    public List<Path> compact() throws IOException {
68      return compact(false);
69    }
70  
71    /**
72     * Compacts the mob files by compaction type for the current column family.
73     * @param allFiles Whether add all mob files into the compaction.
74     * @return The paths of new mob files generated in the compaction.
75     * @throws IOException
76     */
77    public List<Path> compact(boolean allFiles) throws IOException {
78      return compact(Arrays.asList(fs.listStatus(mobFamilyDir)), allFiles);
79    }
80  
81    /**
82     * Compacts the candidate mob files.
83     * @param files The candidate mob files.
84     * @param allFiles Whether add all mob files into the compaction.
85     * @return The paths of new mob files generated in the compaction.
86     * @throws IOException
87     */
88    public abstract List<Path> compact(List<FileStatus> files, boolean allFiles)
89      throws IOException;
90  }