Skip to content

Commit

Permalink
HBASE-7240: Cleanup old snapshots on start
Browse files Browse the repository at this point in the history
  • Loading branch information
jyates committed Dec 18, 2012
1 parent 10c15d8 commit 5b06469
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,7 @@ private void initializeZKBasedSystemTrackers() throws IOException,
// create the snapshot monitor
// TODO should this be config based?
this.snapshotManager = new SnapshotManager(this, zooKeeper, this.executorService);
snapshotManager.start();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,23 @@ public SnapshotManager(final MasterServices master, final ZooKeeperWatcher watch
this.rootDir = master.getMasterFileSystem().getRootDir();
}

/**
* Start running the manager.
* <p>
* <ol>
* <li>Cleans up any snapshots in the snapshot/.tmp directory that were left from failed
* snapshot/export attempts</li>
* </ol>
* @throws IOException if we can't reach the filesystem
*/
public void start() throws IOException {
// cleanup any existing snapshots.
Path tmpdir = SnapshotDescriptionUtils.getWorkingSnapshotDir(rootDir);
if (master.getMasterFileSystem().getFileSystem().delete(tmpdir, true)) {
LOG.warn("Couldn't delete working snapshot directory: " + tmpdir);
}
}

/**
* @return <tt>true</tt> if there is a snapshot currently being taken, <tt>false</tt> otherwise
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,15 +232,24 @@ public static Path getCompletedSnapshotDir(final String snapshotName, final Path
return getCompletedSnapshotDir(getSnapshotsDir(rootDir), snapshotName);
}

/**
* Get the general working directory for snapshots - where they are built, where they are
* temporarily copied on export, etc.
* @param rootDir root directory of the HBase installation
* @return Path to the snapshot tmp directory, relative to the passed root directory
*/
public static Path getWorkingSnapshotDir(final Path rootDir) {
return new Path(getSnapshotsDir(rootDir), SNAPSHOT_TMP_DIR_NAME);
}

/**
* Get the directory to build a snapshot, before it is finalized
* @param snapshot snapshot that will be built
* @param rootDir root directory of the hbase installation
* @return {@link Path} where one can build a snapshot
*/
public static Path getWorkingSnapshotDir(SnapshotDescription snapshot, final Path rootDir) {
return getCompletedSnapshotDir(new Path(getSnapshotsDir(rootDir), SNAPSHOT_TMP_DIR_NAME),
snapshot.getName());
return getCompletedSnapshotDir(getWorkingSnapshotDir(rootDir), snapshot.getName());
}

/**
Expand All @@ -250,8 +259,7 @@ public static Path getWorkingSnapshotDir(SnapshotDescription snapshot, final Pat
* @return {@link Path} where one can build a snapshot
*/
public static Path getWorkingSnapshotDir(String snapshotName, final Path rootDir) {
return getCompletedSnapshotDir(new Path(getSnapshotsDir(rootDir), SNAPSHOT_TMP_DIR_NAME),
snapshotName);
return getCompletedSnapshotDir(getWorkingSnapshotDir(rootDir), snapshotName);
}

/**
Expand Down

0 comments on commit 5b06469

Please sign in to comment.