001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019package org.apache.hadoop.hbase.master.procedure;
020
021import java.io.IOException;
022import java.util.List;
023
024import org.apache.hadoop.fs.Path;
025import org.apache.hadoop.hbase.TableName;
026import org.apache.hadoop.hbase.client.RegionInfo;
027import org.apache.hadoop.hbase.master.MasterFileSystem;
028import org.apache.hadoop.hbase.mob.MobConstants;
029import org.apache.hadoop.hbase.mob.MobUtils;
030import org.apache.hadoop.hbase.util.Bytes;
031import org.apache.yetus.audience.InterfaceAudience;
032import org.slf4j.Logger;
033import org.slf4j.LoggerFactory;
034
035/**
036 * Helper class for schema change procedures
037 */
038@InterfaceAudience.Private
039public final class MasterDDLOperationHelper {
040  private static final Logger LOG = LoggerFactory.getLogger(MasterDDLOperationHelper.class);
041
042  private MasterDDLOperationHelper() {}
043
044  /**
045   * Remove the column family from the file system
046   **/
047  public static void deleteColumnFamilyFromFileSystem(
048      final MasterProcedureEnv env,
049      final TableName tableName,
050      final List<RegionInfo> regionInfoList,
051      final byte[] familyName,
052      final boolean hasMob) throws IOException {
053    final MasterFileSystem mfs = env.getMasterServices().getMasterFileSystem();
054    if (LOG.isDebugEnabled()) {
055      LOG.debug("Removing family=" + Bytes.toString(familyName) + " from table=" + tableName);
056    }
057    for (RegionInfo hri : regionInfoList) {
058      // Delete the family directory in FS for all the regions one by one
059      mfs.deleteFamilyFromFS(hri, familyName);
060    }
061    if (hasMob) {
062      // Delete the mob region
063      Path mobRootDir = new Path(mfs.getRootDir(), MobConstants.MOB_DIR_NAME);
064      RegionInfo mobRegionInfo = MobUtils.getMobRegionInfo(tableName);
065      mfs.deleteFamilyFromFS(mobRootDir, mobRegionInfo, familyName);
066    }
067  }
068}