diff --git a/src/main/java/org/apache/hadoop/hbase/master/snapshot/SnapshotManager.java b/src/main/java/org/apache/hadoop/hbase/master/snapshot/SnapshotManager.java index fbca2c3..aff8691 100644 --- a/src/main/java/org/apache/hadoop/hbase/master/snapshot/SnapshotManager.java +++ b/src/main/java/org/apache/hadoop/hbase/master/snapshot/SnapshotManager.java @@ -373,6 +373,25 @@ public class SnapshotManager implements Stoppable { } /** + * Check to see if there is a snapshot in progress with the same name or on the same table. + * Currently we have a limitation only allowing a single snapshot per table at a time. Also we + * don't allow snapshot with the same name. + * @param snapshot description of the snapshot being checked. + * @return true if there is a snapshot in progress with the same name or on the same + * table. + */ + synchronized boolean isTakingSnapshot(final SnapshotDescription snapshot) { + Iterator> it = this.snapshotHandlers.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry entry = it.next(); + SnapshotSentinel sentinel = entry.getValue(); + if (snapshot.getName().equals(sentinel.getSnapshot().getName()) && !sentinel.isFinished()) + return true; + } + return isTakingSnapshot(snapshot.getTable()); + } + + /** * Check to see if the specified table has a snapshot in progress. Currently we have a * limitation only allowing a single snapshot per table at a time. * @param tableName name of the table being snapshotted. @@ -393,14 +412,14 @@ public class SnapshotManager implements Stoppable { throws HBaseSnapshotException { FileSystem fs = master.getMasterFileSystem().getFileSystem(); Path workingDir = SnapshotDescriptionUtils.getWorkingSnapshotDir(snapshot, rootDir); - // make sure we aren't already running a snapshot - if (isTakingSnapshot(snapshot.getTable())) { + if (isTakingSnapshot(snapshot)) { SnapshotSentinel handler = this.snapshotHandlers.get(snapshot.getTable()); throw new SnapshotCreationException("Rejected taking " + SnapshotDescriptionUtils.toString(snapshot) + " because we are already running another snapshot " - + SnapshotDescriptionUtils.toString(handler.getSnapshot()), snapshot); + + (handler != null ? ("on the same table " + SnapshotDescriptionUtils.toString(handler.getSnapshot())) + : "with the same name"), snapshot); } // make sure we aren't running a restore on the same table