Skip to content

Commit f9ce472

Browse files
committed
HBASE-29641 Simpler incremental backup test for archived files
Integrates the test TestIncrementalBackup#TestIncBackupRestoreHandlesArchivedFiles into the existing test TestIncrementalBackupWithBulkLoad#testIncBackupWithBulkLoads.
1 parent 82e36a2 commit f9ce472

File tree

2 files changed

+22
-71
lines changed

2 files changed

+22
-71
lines changed

hbase-backup/src/test/java/org/apache/hadoop/hbase/backup/TestIncrementalBackup.java

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
import org.apache.hadoop.hbase.util.Bytes;
6060
import org.apache.hadoop.hbase.util.CommonFSUtils;
6161
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
62-
import org.apache.hadoop.hbase.util.HFileArchiveUtil;
6362
import org.apache.hadoop.hbase.util.HFileTestUtil;
6463
import org.junit.After;
6564
import org.junit.Assert;
@@ -433,73 +432,6 @@ public void TestIncBackupRestoreWithOriginalSplitsSeperateFs() throws Exception
433432

434433
}
435434

436-
@Test
437-
public void TestIncBackupRestoreHandlesArchivedFiles() throws Exception {
438-
byte[] fam2 = Bytes.toBytes("f2");
439-
TableDescriptor newTable1Desc = TableDescriptorBuilder.newBuilder(table1Desc)
440-
.setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(fam2).build()).build();
441-
TEST_UTIL.getAdmin().modifyTable(newTable1Desc);
442-
try (Connection conn = ConnectionFactory.createConnection(conf1);
443-
BackupAdminImpl admin = new BackupAdminImpl(conn)) {
444-
String backupTargetDir = TEST_UTIL.getDataTestDir("backupTarget").toString();
445-
BACKUP_ROOT_DIR = new File(backupTargetDir).toURI().toString();
446-
447-
List<TableName> tables = Lists.newArrayList(table1);
448-
449-
insertIntoTable(conn, table1, famName, 3, 100);
450-
String fullBackupId = takeFullBackup(tables, admin, true);
451-
assertTrue(checkSucceeded(fullBackupId));
452-
453-
insertIntoTable(conn, table1, famName, 4, 100);
454-
455-
HRegion regionToBulkload = TEST_UTIL.getHBaseCluster().getRegions(table1).get(0);
456-
String regionName = regionToBulkload.getRegionInfo().getEncodedName();
457-
// Requires a mult-fam bulkload to ensure we're appropriately handling
458-
// multi-file bulkloads
459-
Path regionDir = doBulkload(table1, regionName, famName, fam2);
460-
461-
// archive the files in the region directory
462-
Path archiveDir =
463-
HFileArchiveUtil.getStoreArchivePath(conf1, table1, regionName, Bytes.toString(famName));
464-
TEST_UTIL.getTestFileSystem().mkdirs(archiveDir);
465-
RemoteIterator<LocatedFileStatus> iter =
466-
TEST_UTIL.getTestFileSystem().listFiles(regionDir, true);
467-
List<Path> paths = new ArrayList<>();
468-
while (iter.hasNext()) {
469-
Path path = iter.next().getPath();
470-
if (path.toString().contains("_SeqId_")) {
471-
paths.add(path);
472-
}
473-
}
474-
assertTrue(paths.size() > 1);
475-
Path path = paths.get(0);
476-
String name = path.toString();
477-
int startIdx = name.lastIndexOf(Path.SEPARATOR);
478-
String filename = name.substring(startIdx + 1);
479-
Path archiveFile = new Path(archiveDir, filename);
480-
// archive 1 of the files
481-
boolean success = TEST_UTIL.getTestFileSystem().rename(path, archiveFile);
482-
assertTrue(success);
483-
assertTrue(TEST_UTIL.getTestFileSystem().exists(archiveFile));
484-
assertFalse(TEST_UTIL.getTestFileSystem().exists(path));
485-
486-
BackupRequest request =
487-
createBackupRequest(BackupType.INCREMENTAL, tables, BACKUP_ROOT_DIR, true);
488-
String incrementalBackupId = admin.backupTables(request);
489-
assertTrue(checkSucceeded(incrementalBackupId));
490-
491-
TableName[] fromTable = new TableName[] { table1 };
492-
TableName[] toTable = new TableName[] { table1_restore };
493-
494-
admin.restore(BackupUtils.createRestoreRequest(BACKUP_ROOT_DIR, incrementalBackupId, false,
495-
fromTable, toTable, true));
496-
497-
int actualRowCount = TEST_UTIL.countRows(table1_restore);
498-
int expectedRowCount = TEST_UTIL.countRows(table1);
499-
assertEquals(expectedRowCount, actualRowCount);
500-
}
501-
}
502-
503435
private void checkThrowsCFMismatch(IOException ex, List<TableName> tables) {
504436
Throwable cause = Throwables.getRootCause(ex);
505437
assertEquals(cause.getClass(), ColumnFamilyMismatchException.class);

hbase-backup/src/test/java/org/apache/hadoop/hbase/backup/TestIncrementalBackupWithBulkLoad.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public class TestIncrementalBackupWithBulkLoad extends TestBackupBase {
6262

6363
// implement all test cases in 1 test since incremental backup/restore has dependencies
6464
@Test
65-
public void TestIncBackupDeleteTable() throws Exception {
65+
public void testIncBackupWithBulkLoads() throws Exception {
6666
try (BackupSystemTable systemTable = new BackupSystemTable(TEST_UTIL.getConnection())) {
6767
// The test starts with some data, and no bulk loaded rows.
6868
int expectedRowCount = NB_ROWS_IN_BATCH;
@@ -99,13 +99,19 @@ public void TestIncBackupDeleteTable() throws Exception {
9999
assertEquals(expectedRowCount, TEST_UTIL.countRows(table1));
100100
assertEquals(0, systemTable.readBulkloadRows(List.of(table1)).size());
101101

102-
// Creating an incremental backup clears the bulk loads
102+
// Create bulk loads that will end up in the incremental backup.
103103
performBulkLoad("bulk4");
104104
performBulkLoad("bulk5");
105105
performBulkLoad("bulk6");
106106
expectedRowCount += 3 * ROWS_IN_BULK_LOAD;
107107
assertEquals(expectedRowCount, TEST_UTIL.countRows(table1));
108-
assertEquals(3, systemTable.readBulkloadRows(List.of(table1)).size());
108+
List<BulkLoad> bulkLoadsForIncrBackup = systemTable.readBulkloadRows(List.of(table1));
109+
assertEquals(3, bulkLoadsForIncrBackup.size());
110+
111+
// Manually move one bulk loaded file to simulate archival
112+
simulateArchival(bulkLoadsForIncrBackup.get(0));
113+
114+
// Creating an incremental backup clears the bulk loads
109115
String backup3 = backupTables(BackupType.INCREMENTAL, List.of(table1), BACKUP_ROOT_DIR);
110116
assertTrue(checkSucceeded(backup3));
111117
assertEquals(expectedRowCount, TEST_UTIL.countRows(table1));
@@ -256,4 +262,17 @@ private void performBulkLoad(String keyPrefix) throws IOException {
256262
BulkLoadHFiles.create(TEST_UTIL.getConfiguration()).bulkLoad(table1, baseDirectory);
257263
assertFalse(result.isEmpty());
258264
}
265+
266+
private void simulateArchival(BulkLoad bulkLoad) throws IOException {
267+
FileSystem fs = TEST_UTIL.getTestFileSystem();
268+
Path rootDir = CommonFSUtils.getRootDir(TEST_UTIL.getConfiguration());
269+
Path archiveRoot = HFileArchiveUtil.getArchivePath(TEST_UTIL.getConfiguration());
270+
271+
Path srcPath = new Path(bulkLoad.getHfilePath());
272+
String relativePath = rootDir.toUri().relativize(srcPath.toUri()).getPath();
273+
Path tgtPath = new Path(archiveRoot, relativePath);
274+
275+
fs.mkdirs(tgtPath.getParent());
276+
assertTrue("Renaming HFile to simulate archival failed", fs.rename(srcPath, tgtPath));
277+
}
259278
}

0 commit comments

Comments
 (0)