/** Remove specified regions from the file-system, using the archiver. */
 private void removeHdfsRegions(final List<HRegionInfo> regions) throws IOException {
   if (regions != null && regions.size() > 0) {
     for (HRegionInfo hri : regions) {
       HFileArchiver.archiveRegion(conf, fs, hri);
     }
   }
 }
Esempio n. 2
0
  /**
   * Remove the region from the table directory, archiving the region's hfiles.
   *
   * @param conf the {@link Configuration} to use
   * @param fs {@link FileSystem} from which to remove the region
   * @param tableDir {@link Path} to where the table is being stored
   * @param regionInfo {@link HRegionInfo} for region to be deleted
   * @throws IOException if the request cannot be completed
   */
  public static void deleteRegionFromFileSystem(
      final Configuration conf,
      final FileSystem fs,
      final Path tableDir,
      final HRegionInfo regionInfo)
      throws IOException {
    HRegionFileSystem regionFs = new HRegionFileSystem(conf, fs, tableDir, regionInfo);
    Path regionDir = regionFs.getRegionDir();

    if (!fs.exists(regionDir)) {
      LOG.warn("Trying to delete a region that do not exists on disk: " + regionDir);
      return;
    }

    if (LOG.isDebugEnabled()) {
      LOG.debug("DELETING region " + regionDir);
    }

    // Archive region
    Path rootDir = FSUtils.getRootDir(conf);
    HFileArchiver.archiveRegion(fs, rootDir, tableDir, regionDir);

    // Delete empty region dir
    if (!fs.delete(regionDir, true)) {
      LOG.warn("Failed delete of " + regionDir);
    }
  }
  /**
   * Make sure the hbase temp directory exists and is empty.
   * NOTE that this method is only executed once just after the master becomes the active one.
   */
  private void checkTempDir(final Path tmpdir, final Configuration c, final FileSystem fs)
      throws IOException {
    // If the temp directory exists, clear the content (left over, from the previous run)
    if (fs.exists(tmpdir)) {
      // Archive table in temp, maybe left over from failed deletion,
      // if not the cleaner will take care of them.
      for (Path tabledir: FSUtils.getTableDirs(fs, tmpdir)) {
        for (Path regiondir: FSUtils.getRegionDirs(fs, tabledir)) {
          HFileArchiver.archiveRegion(fs, this.rootdir, tabledir, regiondir);
        }
      }
      if (!fs.delete(tmpdir, true)) {
        throw new IOException("Unable to clean the temp directory: " + tmpdir);
      }
    }

    // Create the temp directory
    if (!fs.mkdirs(tmpdir)) {
      throw new IOException("HBase temp directory '" + tmpdir + "' creation failure.");
    }
  }
Esempio n. 4
0
  /** Removes the table from hbase:meta and archives the HDFS files. */
  protected void removeTableData(final List<HRegionInfo> regions)
      throws IOException, CoordinatedStateException {
    try {
      // 1. Remove regions from META
      LOG.debug("Deleting regions from META");
      MetaTableAccessor.deleteRegions(this.server.getConnection(), regions);

      // -----------------------------------------------------------------------
      // NOTE: At this point we still have data on disk, but nothing in hbase:meta
      //       if the rename below fails, hbck will report an inconsistency.
      // -----------------------------------------------------------------------

      // 2. Move the table in /hbase/.tmp
      MasterFileSystem mfs = this.masterServices.getMasterFileSystem();
      Path tempTableDir = mfs.moveTableToTemp(tableName);

      // 3. Archive regions from FS (temp directory)
      FileSystem fs = mfs.getFileSystem();
      for (HRegionInfo hri : regions) {
        LOG.debug("Archiving region " + hri.getRegionNameAsString() + " from FS");
        HFileArchiver.archiveRegion(
            fs,
            mfs.getRootDir(),
            tempTableDir,
            HRegion.getRegionDir(tempTableDir, hri.getEncodedName()));
      }

      // 4. Delete table directory from FS (temp directory)
      if (!fs.delete(tempTableDir, true)) {
        LOG.error("Couldn't delete " + tempTableDir);
      }

      LOG.debug("Table '" + tableName + "' archived!");
    } finally {
      cleanupTableState();
    }
  }
 public void deleteRegion(HRegionInfo region) throws IOException {
   HFileArchiver.archiveRegion(conf, fs, region);
 }