gvprathyusha6 commented on code in PR #7063:
URL: https://github.com/apache/hbase/pull/7063#discussion_r2138068979


##########
hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/TestRestoreSnapshotHelper.java:
##########
@@ -218,6 +230,104 @@ public void testCopyExpiredSnapshotForScanner() throws 
IOException, InterruptedE
       .copySnapshotForScanner(conf, fs, rootDir, restoreDir, snapshotName));
   }
 
+  /**
+   * Test scenario for HBASE-29346, which addresses the issue where restoring 
snapshots after region
+   * merge operations could lead to missing store file references, potentially 
resulting in data
+   * loss.
+   * <p>
+   * This test performs the following steps:
+   * </p>
+   * <ol>
+   * <li>Creates a table with multiple regions.</li>
+   * <li>Inserts data into each region and flushes to create store files.</li>
+   * <li>Takes snapshot of the table and performs restore.</li>
+   * <li>Disable compactions, merge regions, create a new snapshot, and 
restore that snapshot on the
+   * same restore path.</li>
+   * <li>Verifies data integrity by creating another snapshot.</li>
+   * </ol>
+   */
+  @Test
+  public void testMultiSnapshotRestoreWithMerge() throws IOException, 
InterruptedException {
+    rootDir = TEST_UTIL.getDefaultRootDirPath();
+    CommonFSUtils.setRootDir(conf, rootDir);
+    TableName tableName = 
TableName.valueOf("testMultiSnapshotRestoreWithMerge");
+    Path restoreDir = new Path("/hbase/.tmp-snapshot/restore-snapshot-dest");
+
+    byte[] columnFamily = Bytes.toBytes("A");
+    Table table = TEST_UTIL.createTable(tableName, new byte[][] { columnFamily 
},
+      new byte[][] { new byte[] { 'b' }, new byte[] { 'd' } });
+    Put put1 = new Put(Bytes.toBytes("a")); // Region 1: [-∞, b)
+    put1.addColumn(columnFamily, Bytes.toBytes("q"), Bytes.toBytes("val1"));
+    table.put(put1);
+    Put put2 = new Put(Bytes.toBytes("b")); // Region 2: [b, d)
+    put2.addColumn(columnFamily, Bytes.toBytes("q"), Bytes.toBytes("val2"));
+    table.put(put2);
+    Put put3 = new Put(Bytes.toBytes("d")); // Region 3: [d, +∞)
+    put3.addColumn(columnFamily, Bytes.toBytes("q"), Bytes.toBytes("val3"));
+    table.put(put3);
+
+    TEST_UTIL.getAdmin().flush(tableName);
+
+    String snapshotOne = tableName.getNameAsString() + "-snapshot-one";
+    createAndAssertSnapshot(tableName, snapshotOne);
+    RestoreSnapshotHelper.copySnapshotForScanner(conf, fs, rootDir, 
restoreDir, snapshotOne);
+    flipComactions(false);
+    mergeRegions(tableName, 2);
+    String snapshotTwo = tableName.getNameAsString() + "-snapshot-two";
+    createAndAssertSnapshot(tableName, snapshotTwo);
+    RestoreSnapshotHelper.copySnapshotForScanner(conf, fs, rootDir, 
restoreDir, snapshotTwo);
+    flipComactions(true);
+    String snapshotThree = tableName.getNameAsString() + "-snapshot-three";
+    createAndAssertSnapshot(tableName, snapshotThree);

Review Comment:
   @d-c-manning  this looks good, I was also struggling on how to make it error 
out, this disable, enable + scan should be better



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to