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