From ed15aecab89d977bcb283b801d75cf041bb0bb35 Mon Sep 17 00:00:00 2001 From: mbertozzi Date: Tue, 3 Sep 2013 17:55:08 +0000 Subject: [PATCH] HBASE-9397 Snapshots with the same name are allowed to proceed concurrently (Jerry He) git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1519769 13f79535-47bb-0310-9956-ffa450edef68 --- .../master/snapshot/SnapshotManager.java | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/snapshot/SnapshotManager.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/snapshot/SnapshotManager.java index c4728424cae..33a3739f5e9 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/snapshot/SnapshotManager.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/snapshot/SnapshotManager.java @@ -376,6 +376,30 @@ public class SnapshotManager implements Stoppable { return false; } + /** + * 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) { + TableName snapshotTable = TableName.valueOf(snapshot.getTable()); + if (isTakingSnapshot(snapshotTable)) { + return true; + } + 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 false; + } + /** * 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. @@ -401,12 +425,14 @@ public class SnapshotManager implements Stoppable { TableName.valueOf(snapshot.getTable()); // make sure we aren't already running a snapshot - if (isTakingSnapshot(snapshotTable)) { + if (isTakingSnapshot(snapshot)) { SnapshotSentinel handler = this.snapshotHandlers.get(snapshotTable); throw new SnapshotCreationException("Rejected taking " + ClientSnapshotDescriptionUtils.toString(snapshot) + " because we are already running another snapshot " - + ClientSnapshotDescriptionUtils.toString(handler.getSnapshot()), snapshot); + + (handler != null ? ("on the same table " + + ClientSnapshotDescriptionUtils.toString(handler.getSnapshot())) + : "with the same name"), snapshot); } // make sure we aren't running a restore on the same table