Java Code Examples for org.apache.hadoop.hbase.snapshot.SnapshotDescriptionUtils#getWorkingSnapshotDir()

The following examples show how to use org.apache.hadoop.hbase.snapshot.SnapshotDescriptionUtils#getWorkingSnapshotDir() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SnapshotManager.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Take a snapshot using the specified handler.
 * On failure the snapshot temporary working directory is removed.
 * NOTE: prepareToTakeSnapshot() called before this one takes care of the rejecting the
 *       snapshot request if the table is busy with another snapshot/restore operation.
 * @param snapshot the snapshot description
 * @param handler the snapshot handler
 */
private synchronized void snapshotTable(SnapshotDescription snapshot,
    final TakeSnapshotHandler handler) throws IOException {
  try {
    handler.prepare();
    this.executorService.submit(handler);
    this.snapshotHandlers.put(TableName.valueOf(snapshot.getTable()), handler);
  } catch (Exception e) {
    // cleanup the working directory by trying to delete it from the fs.
    Path workingDir = SnapshotDescriptionUtils.getWorkingSnapshotDir(snapshot, rootDir,
        master.getConfiguration());
    FileSystem workingDirFs = workingDir.getFileSystem(master.getConfiguration());
    try {
      if (!workingDirFs.delete(workingDir, true)) {
        LOG.error("Couldn't delete working directory (" + workingDir + " for snapshot:" +
            ClientSnapshotDescriptionUtils.toString(snapshot));
      }
    } catch (IOException e1) {
      LOG.error("Couldn't delete working directory (" + workingDir + " for snapshot:" +
          ClientSnapshotDescriptionUtils.toString(snapshot));
    }
    // fail the snapshot
    throw new SnapshotCreationException("Could not build snapshot handler", e,
      ProtobufUtil.createSnapshotDesc(snapshot));
  }
}
 
Example 2
Source File: SnapshotHFileCleaner.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
public void setConf(final Configuration conf) {
  super.setConf(conf);
  try {
    long cacheRefreshPeriod = conf.getLong(HFILE_CACHE_REFRESH_PERIOD_CONF_KEY,
      DEFAULT_HFILE_CACHE_REFRESH_PERIOD);
    final FileSystem fs = CommonFSUtils.getCurrentFileSystem(conf);
    Path rootDir = CommonFSUtils.getRootDir(conf);
    Path workingDir = SnapshotDescriptionUtils.getWorkingSnapshotDir(rootDir, conf);
    FileSystem workingFs = workingDir.getFileSystem(conf);

    cache = new SnapshotFileCache(fs, rootDir, workingFs, workingDir, cacheRefreshPeriod,
      cacheRefreshPeriod, "snapshot-hfile-cleaner-cache-refresher",
      new SnapshotFileCache.SnapshotFileInspector() {
          @Override
          public Collection<String> filesUnderSnapshot(final FileSystem fs,
            final Path snapshotDir)
              throws IOException {
            return SnapshotReferenceUtil.getHFileNames(conf, fs, snapshotDir);
          }
        });
  } catch (IOException e) {
    LOG.error("Failed to create cleaner util", e);
  }
}
 
Example 3
Source File: SnapshotManager.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Cleans up any snapshots in the snapshot/.tmp directory that were left from failed
 * snapshot attempts.
 *
 * @throws IOException if we can't reach the filesystem
 */
private void resetTempDir() throws IOException {
  // cleanup any existing snapshots.
  Path tmpdir = SnapshotDescriptionUtils.getWorkingSnapshotDir(rootDir,
      master.getConfiguration());
  FileSystem tmpFs = tmpdir.getFileSystem(master.getConfiguration());
  if (!tmpFs.delete(tmpdir, true)) {
    LOG.warn("Couldn't delete working snapshot directory: " + tmpdir);
  }
}
 
Example 4
Source File: TestSnapshotFileCacheWithDifferentWorkingDir.java    From hbase with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void startCluster() throws Exception {
  initCommon();

  // Set the snapshot working directory to be on another filesystem.
  conf.set(SnapshotDescriptionUtils.SNAPSHOT_WORKING_DIR,
    "file://" + new Path(TEMP_DIR, ".tmpDir").toUri());
  workingDir = SnapshotDescriptionUtils.getWorkingSnapshotDir(rootDir, conf);
  workingFs = workingDir.getFileSystem(conf);
}
 
Example 5
Source File: TestSnapshotFileCache.java    From hbase with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void startCluster() throws Exception {
  initCommon();
  workingDir = SnapshotDescriptionUtils.getWorkingSnapshotDir(rootDir, conf);
  workingFs = workingDir.getFileSystem(conf);
}
 
Example 6
Source File: SnapshotFileCache.java    From hbase with Apache License 2.0 3 votes vote down vote up
/**
 * Create a snapshot file cache for all snapshots under the specified [root]/.snapshot on the
 * filesystem.
 * <p>
 * Immediately loads the file cache.
 * @param conf to extract the configured {@link FileSystem} where the snapshots are stored and
 *          hbase root directory
 * @param cacheRefreshPeriod frequency (ms) with which the cache should be refreshed
 * @param cacheRefreshDelay amount of time to wait for the cache to be refreshed
 * @param refreshThreadName name of the cache refresh thread
 * @param inspectSnapshotFiles Filter to apply to each snapshot to extract the files.
 * @throws IOException if the {@link FileSystem} or root directory cannot be loaded
 */
public SnapshotFileCache(Configuration conf, long cacheRefreshPeriod, long cacheRefreshDelay,
  String refreshThreadName, SnapshotFileInspector inspectSnapshotFiles) throws IOException {
  this(CommonFSUtils.getCurrentFileSystem(conf), CommonFSUtils.getRootDir(conf),
    SnapshotDescriptionUtils.getWorkingSnapshotDir(CommonFSUtils.getRootDir(conf), conf).
      getFileSystem(conf),
    SnapshotDescriptionUtils.getWorkingSnapshotDir(CommonFSUtils.getRootDir(conf), conf),
    cacheRefreshPeriod, cacheRefreshDelay, refreshThreadName, inspectSnapshotFiles);
}