HBASE-7240 Cleanup old snapshots on start (Jesse Yates)
git-svn-id: https://svn.apache.org/repos/asf/hbase/branches/hbase-7290@1445788 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
378e6f62b5
commit
914cf71b6a
|
@ -595,6 +595,7 @@ Server {
|
|||
// create the snapshot monitor
|
||||
// TODO should this be config based?
|
||||
this.snapshotManager = new SnapshotManager(this, zooKeeper, this.executorService);
|
||||
snapshotManager.start();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -80,6 +80,23 @@ public class SnapshotManager implements Stoppable {
|
|||
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
|
||||
*/
|
||||
|
|
|
@ -232,6 +232,16 @@ public class SnapshotDescriptionUtils {
|
|||
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
|
||||
|
@ -239,8 +249,7 @@ public class SnapshotDescriptionUtils {
|
|||
* @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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -250,8 +259,7 @@ public class SnapshotDescriptionUtils {
|
|||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue