diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java index a3f873f4d63..924236d3dcc 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java @@ -3034,6 +3034,14 @@ MasterServices, Server { throw new ServiceException(e); } + // ensure namespace exists + try { + TableName dstTable = TableName.valueOf(request.getSnapshot().getTable()); + getNamespaceDescriptor(dstTable.getNamespaceAsString()); + } catch (IOException ioe) { + throw new ServiceException(ioe); + } + try { SnapshotDescription reqSnapshot = request.getSnapshot(); snapshotManager.restoreSnapshot(reqSnapshot); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestCloneSnapshotFromClient.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestCloneSnapshotFromClient.java index e5cbf352f2c..ccf4c7ec0ed 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestCloneSnapshotFromClient.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestCloneSnapshotFromClient.java @@ -30,6 +30,7 @@ import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.LargeTests; import org.apache.hadoop.hbase.NamespaceDescriptor; +import org.apache.hadoop.hbase.NamespaceNotFoundException; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.master.MasterFileSystem; import org.apache.hadoop.hbase.master.snapshot.SnapshotManager; @@ -147,6 +148,12 @@ public class TestCloneSnapshotFromClient { admin.cloneSnapshot(snapshotName, tableName); } + @Test(expected = NamespaceNotFoundException.class) + public void testCloneOnMissingNamespace() throws IOException, InterruptedException { + TableName clonedTableName = TableName.valueOf("unknownNS:clonetb"); + admin.cloneSnapshot(snapshotName1, clonedTableName); + } + @Test public void testCloneSnapshot() throws IOException, InterruptedException { TableName clonedTableName = TableName.valueOf("clonedtb-" + System.currentTimeMillis());