From 9a8821d77dfb98433eb82407e4e42d4f8ff8843c Mon Sep 17 00:00:00 2001 From: mbertozzi Date: Sun, 22 Sep 2013 12:22:08 +0000 Subject: [PATCH] HBASE-9607 Data loss after snapshot restore into cloned table git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1525352 13f79535-47bb-0310-9956-ffa450edef68 --- .../hbase/snapshot/RestoreSnapshotHelper.java | 14 +++++++------- .../client/TestRestoreSnapshotFromClient.java | 17 ++++++++++++++++- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/RestoreSnapshotHelper.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/RestoreSnapshotHelper.java index c4cf8feed72..34c277ab944 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/RestoreSnapshotHelper.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/RestoreSnapshotHelper.java @@ -389,13 +389,6 @@ public class RestoreSnapshotHelper { } } - // Restore Missing files - for (String hfileName: hfilesToAdd) { - LOG.trace("Adding HFileLink " + hfileName + - " to region=" + regionInfo.getEncodedName() + " table=" + tableName); - restoreStoreFile(familyDir, regionInfo, hfileName); - } - // Remove hfiles not present in the snapshot for (String hfileName: familyFiles) { Path hfile = new Path(familyDir, hfileName); @@ -403,6 +396,13 @@ public class RestoreSnapshotHelper { " from region=" + regionInfo.getEncodedName() + " table=" + tableName); HFileArchiver.archiveStoreFile(conf, fs, regionInfo, tableDir, family, hfile); } + + // Restore Missing files + for (String hfileName: hfilesToAdd) { + LOG.trace("Adding HFileLink " + hfileName + + " to region=" + regionInfo.getEncodedName() + " table=" + tableName); + restoreStoreFile(familyDir, regionInfo, hfileName); + } } else { // Family doesn't exists in the snapshot LOG.trace("Removing family=" + Bytes.toString(family) + diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRestoreSnapshotFromClient.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRestoreSnapshotFromClient.java index 86502e2ae86..e5a9da81915 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRestoreSnapshotFromClient.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRestoreSnapshotFromClient.java @@ -222,7 +222,7 @@ public class TestRestoreSnapshotFromClient { } @Test - public void testRestoreSnapshotOfCloned() throws IOException, InterruptedException { + public void testCloneSnapshotOfCloned() throws IOException, InterruptedException { TableName clonedTableName = TableName.valueOf("clonedtb-" + System.currentTimeMillis()); admin.cloneSnapshot(snapshotName0, clonedTableName); @@ -237,6 +237,21 @@ public class TestRestoreSnapshotFromClient { TEST_UTIL.deleteTable(clonedTableName); } + @Test + public void testCloneAndRestoreSnapshot() throws IOException, InterruptedException { + TEST_UTIL.deleteTable(tableName); + waitCleanerRun(); + + admin.cloneSnapshot(snapshotName0, tableName); + SnapshotTestingUtils.verifyRowCount(TEST_UTIL, tableName, snapshot0Rows); + waitCleanerRun(); + + admin.disableTable(tableName); + admin.restoreSnapshot(snapshotName0); + admin.enableTable(tableName); + SnapshotTestingUtils.verifyRowCount(TEST_UTIL, tableName, snapshot0Rows); + } + // ========================================================================== // Helpers // ==========================================================================