Repository: hbase
Updated Branches:
  refs/heads/branch-1.3 c23ede48a -> 1197ecaa3


HBASE-19343 Restore snapshot makes split parent region online


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/1197ecaa
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/1197ecaa
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/1197ecaa

Branch: refs/heads/branch-1.3
Commit: 1197ecaa3a809a96dc55b3d3543f4d0eb5c04e24
Parents: c23ede4
Author: Pankaj Kumar <pankaj...@huawei.com>
Authored: Mon Apr 9 10:05:51 2018 -0700
Committer: tedyu <yuzhih...@gmail.com>
Committed: Mon Apr 9 10:05:51 2018 -0700

----------------------------------------------------------------------
 .../hbase/snapshot/RestoreSnapshotHelper.java   |  4 +-
 .../client/TestRestoreSnapshotFromClient.java   | 68 +++++++++++++++++++-
 2 files changed, 69 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/1197ecaa/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/RestoreSnapshotHelper.java
----------------------------------------------------------------------
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 0c2e2ab..c34f899 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
@@ -198,7 +198,9 @@ public class RestoreSnapshotHelper {
         if (regionNames.contains(regionName)) {
           LOG.info("region to restore: " + regionName);
           regionNames.remove(regionName);
-          metaChanges.addRegionToRestore(regionInfo);
+          // Add the regionInfo from snapshot manifest, so that will not miss 
parent region details
+          metaChanges.addRegionToRestore(
+            
HRegionInfo.convert(regionManifests.get(regionName).getRegionInfo()));
         } else {
           LOG.info("region to remove: " + regionName);
           metaChanges.addRegionToRemove(regionInfo);

http://git-wip-us.apache.org/repos/asf/hbase/blob/1197ecaa/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestRestoreSnapshotFromClient.java
----------------------------------------------------------------------
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 b0f07bb..5421a3b 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
@@ -31,12 +31,17 @@ import org.apache.hadoop.hbase.HBaseTestingUtility;
 import org.apache.hadoop.hbase.HColumnDescriptor;
 import org.apache.hadoop.hbase.HConstants;
 import org.apache.hadoop.hbase.HTableDescriptor;
+import org.apache.hadoop.hbase.MetaTableAccessor;
 import org.apache.hadoop.hbase.testclassification.LargeTests;
 import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.Waiter;
+import org.apache.hadoop.hbase.master.AssignmentManager;
 import org.apache.hadoop.hbase.master.MasterFileSystem;
+import org.apache.hadoop.hbase.master.RegionState;
 import org.apache.hadoop.hbase.master.snapshot.SnapshotManager;
 import org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException;
 import org.apache.hadoop.hbase.snapshot.CorruptedSnapshotException;
+import org.apache.hadoop.hbase.snapshot.SnapshotDoesNotExistException;
 import org.apache.hadoop.hbase.snapshot.SnapshotTestingUtils;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.FSUtils;
@@ -80,8 +85,9 @@ public class TestRestoreSnapshotFromClient {
     TEST_UTIL.getConfiguration().setInt("hbase.regionserver.msginterval", 100);
     TEST_UTIL.getConfiguration().setInt("hbase.client.pause", 250);
     
TEST_UTIL.getConfiguration().setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 6);
-    TEST_UTIL.getConfiguration().setBoolean(
-        "hbase.master.enabletable.roundrobin", true);
+    
TEST_UTIL.getConfiguration().setBoolean("hbase.master.enabletable.roundrobin", 
true);
+    // Setting bigger value to avoid catalog janitor execution (parent region 
cleanup)
+    TEST_UTIL.getConfiguration().setLong("hbase.catalogjanitor.interval", 
1800000);
     TEST_UTIL.startMiniCluster(3);
   }
 
@@ -281,6 +287,64 @@ public class TestRestoreSnapshotFromClient {
     }
   }
 
+  @Test(timeout = 300000)
+  public void testRestoreSnapshotAfterSplit() throws Exception {
+    Admin admin = null;
+    try {
+      admin = TEST_UTIL.getHBaseAdmin();
+      final int regionReplication = 
admin.getTableDescriptor(tableName).getRegionReplication();
+      // Region count before split
+      final int primaryRegionCountBeforeSplit = MetaTableAccessor
+          .getTableRegions(TEST_UTIL.getZooKeeperWatcher(), 
TEST_UTIL.getConnection(), tableName)
+          .size() / regionReplication;
+
+      admin.split(tableName, "m".getBytes());
+      final AssignmentManager am = 
TEST_UTIL.getHBaseCluster().getMaster().getAssignmentManager();
+      // Wait for replica region to become online
+      TEST_UTIL.waitFor(60000, 500, new Waiter.Predicate<IOException>() {
+        @Override
+        public boolean evaluate() throws IOException {
+          return 
am.getRegionStates().getRegionByStateOfTable(tableName).get(RegionState.State.OPEN)
+              .size() == ((primaryRegionCountBeforeSplit + 1) * 
regionReplication);
+        }
+      });
+
+      int regionCountAfterSplit = MetaTableAccessor
+          .getTableRegions(TEST_UTIL.getZooKeeperWatcher(), 
TEST_UTIL.getConnection(), tableName)
+          .size() / regionReplication;
+      // regionCountAfterSplit will contain parent region, so 
primaryregionCountBeforeSplit + 2
+      assertEquals(primaryRegionCountBeforeSplit + 2, regionCountAfterSplit);
+
+      String snapshotName = "testRestoreSnapshotAfterSplit-snap";
+      // Create snapshot after table split
+      admin.snapshot(snapshotName, tableName);
+      assertEquals(1,
+        admin.listTableSnapshots("testtb-.*", 
"testRestoreSnapshotAfterSplit-snap*").size());
+      // Restore snapshot
+      admin.disableTable(tableName);
+      admin.restoreSnapshot(snapshotName);
+
+      int regionCountAfterRestoreSnapshot = MetaTableAccessor
+          .getTableRegions(TEST_UTIL.getZooKeeperWatcher(), 
TEST_UTIL.getConnection(), tableName)
+          .size();
+      assertEquals(primaryRegionCountBeforeSplit + 2, 
regionCountAfterRestoreSnapshot);
+
+      // Enable the table
+      admin.enableTable(tableName);
+      assertEquals((primaryRegionCountBeforeSplit + 1) * regionReplication,
+        
am.getRegionStates().getRegionByStateOfTable(tableName).get(RegionState.State.OPEN).size());
+
+    } finally {
+      if (admin != null) {
+        try {
+          admin.deleteTableSnapshots("testtb-.*", 
"testRestoreSnapshotAfterSplit-snap*");
+        } catch (SnapshotDoesNotExistException ignore) {
+        }
+        admin.close();
+      }
+    }
+  }
+
   // ==========================================================================
   //  Helpers
   // ==========================================================================

Reply via email to