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.mob.compactions;
020
021import java.io.IOException;
022import java.util.Arrays;
023import java.util.List;
024import java.util.concurrent.ExecutorService;
025
026import org.apache.hadoop.conf.Configuration;
027import org.apache.hadoop.fs.FileStatus;
028import org.apache.hadoop.fs.FileSystem;
029import org.apache.hadoop.fs.Path;
030import org.apache.hadoop.hbase.TableName;
031import org.apache.yetus.audience.InterfaceAudience;
032import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor;
033import org.apache.hadoop.hbase.mob.MobUtils;
034import org.apache.hadoop.hbase.util.FSUtils;
035
036/**
037 * A mob compactor to directly compact the mob files.
038 */
039@InterfaceAudience.Private
040public abstract class MobCompactor {
041
042  protected FileSystem fs;
043  protected Configuration conf;
044  protected TableName tableName;
045  protected ColumnFamilyDescriptor column;
046
047  protected Path mobTableDir;
048  protected Path mobFamilyDir;
049  protected ExecutorService pool;
050
051  public MobCompactor(Configuration conf, FileSystem fs, TableName tableName,
052                      ColumnFamilyDescriptor column, ExecutorService pool) {
053    this.conf = conf;
054    this.fs = fs;
055    this.tableName = tableName;
056    this.column = column;
057    this.pool = pool;
058    mobTableDir = FSUtils.getTableDir(MobUtils.getMobHome(conf), tableName);
059    mobFamilyDir = MobUtils.getMobFamilyPath(conf, tableName, column.getNameAsString());
060  }
061
062  /**
063   * Compacts the mob files for the current column family.
064   * @return The paths of new mob files generated in the compaction.
065   * @throws IOException
066   */
067  public List<Path> compact() throws IOException {
068    return compact(false);
069  }
070
071  /**
072   * Compacts the mob files by compaction type for the current column family.
073   * @param allFiles Whether add all mob files into the compaction.
074   * @return The paths of new mob files generated in the compaction.
075   * @throws IOException
076   */
077  public List<Path> compact(boolean allFiles) throws IOException {
078    return compact(Arrays.asList(fs.listStatus(mobFamilyDir)), allFiles);
079  }
080
081  /**
082   * Compacts the candidate mob files.
083   * @param files The candidate mob files.
084   * @param allFiles Whether add all mob files into the compaction.
085   * @return The paths of new mob files generated in the compaction.
086   * @throws IOException
087   */
088  public abstract List<Path> compact(List<FileStatus> files, boolean allFiles)
089    throws IOException;
090}