diff --git src/main/java/org/apache/hadoop/hbase/master/snapshot/SnapshotManager.java src/main/java/org/apache/hadoop/hbase/master/snapshot/SnapshotManager.java index 30f7125..e43d888 100644 --- src/main/java/org/apache/hadoop/hbase/master/snapshot/SnapshotManager.java +++ src/main/java/org/apache/hadoop/hbase/master/snapshot/SnapshotManager.java @@ -74,7 +74,7 @@ import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; import org.apache.hadoop.hbase.util.FSTableDescriptors; import org.apache.hadoop.hbase.util.FSUtils; import org.apache.zookeeper.KeeperException; -import org.joda.time.Days; +import org.joda.time.Hours; /** * This class manages the procedure of taking and restoring snapshots. There is only one @@ -134,17 +134,17 @@ public class SnapshotManager implements Stoppable { private static final int SNAPSHOT_POOL_THREADS_DEFAULT = 1; /** - * Conf key to ensure that # of ms have elapsed before deleting the tmp directory if it is present - * during initialization + * Conf key to ensure that # of hours have elapsed before deleting + * the snapshots in tmp directory if it is present during initialization */ - private static final String SNAPSHOT_INPROGRESS_EXPIRATION_MILLIS_KEY = - "hbase.snapshot.inProgress.expiration.timeMillis"; + private static final String SNAPSHOT_INPROGRESS_EXPIRATION_HOURS_KEY = + "hbase.snapshot.inProgress.expiration.timeHours"; /** - * By default, wait for (ms) before deleting the tmp directory on initialization (if exists) + * By default, wait for (hours) before deleting the snapshots in the tmp directory + * on initialization (if exists) */ - private static final long SNAPSHOT_INPROGRESS_EXPIRATION_MILLIS_DEFAULT = - Days.days(30).toStandardDuration().getMillis(); + private static final int SNAPSHOT_INPROGRESS_EXPIRATION_HOURS_DEFAULT = 720; // 30 days private boolean stopped; private final MasterServices master; // Needed by TableEventHandlers @@ -280,22 +280,28 @@ public class SnapshotManager implements Stoppable { // cleanup any existing snapshots. Path tmpdir = SnapshotDescriptionUtils.getWorkingSnapshotDir(rootDir); FileSystem fileSystem = master.getMasterFileSystem().getFileSystem(); - long timeout = master.getConfiguration().getLong( - SNAPSHOT_INPROGRESS_EXPIRATION_MILLIS_KEY, SNAPSHOT_INPROGRESS_EXPIRATION_MILLIS_DEFAULT + int timeoutHours = master.getConfiguration().getInt( + SNAPSHOT_INPROGRESS_EXPIRATION_HOURS_KEY, SNAPSHOT_INPROGRESS_EXPIRATION_HOURS_DEFAULT ); + long timeoutMillis = Hours.hours(timeoutHours).toStandardDuration().getMillis(); FileStatus[] snapshotsInProgress = FSUtils.listStatus(fileSystem, tmpdir); if (snapshotsInProgress == null) { return; } for (FileStatus snapshot : snapshotsInProgress) { long lastModified = snapshot.getModificationTime(); - if (EnvironmentEdgeManager.currentTimeMillis() > (lastModified + timeout)) { + if (EnvironmentEdgeManager.currentTimeMillis() > (lastModified + timeoutMillis)) { if (!fileSystem.delete(snapshot.getPath(), true)) { LOG.warn("Couldn't delete working snapshot directory: " + tmpdir); + } else { + LOG.warn("A working snapshot directory exists: " + snapshot.getPath() + + " which was last modified: " + lastModified + " deleting expired snapshot " + + "directory as threshold is: " + timeoutHours + " hours."); } } else { LOG.warn("A working snapshot directory exists: " + snapshot.getPath() + - " which was modified: " + lastModified + " not deleting as threshold is: " + timeout + "(ms)"); + " which was last modified: " + lastModified + " not deleting snapshot directory " + + "as threshold is: " + timeoutHours + " hours."); } } }