Skip to content

Commit 035be4d

Browse files
hgromerHernan Gelaf-Romer
and
Hernan Gelaf-Romer
authored
HBASE-29114 Restoring to original splits fails if backups are on separate FileSystem (#6667)
Co-authored-by: Hernan Gelaf-Romer <[email protected]> Signed-off-by: Ray Mattingly <[email protected]>
1 parent 5b66a53 commit 035be4d

File tree

4 files changed

+64
-4
lines changed

4 files changed

+64
-4
lines changed

hbase-backup/src/main/java/org/apache/hadoop/hbase/backup/RestoreJob.java

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
public interface RestoreJob extends Configurable {
3333

3434
String KEEP_ORIGINAL_SPLITS_KEY = "hbase.backup.restorejob.keep.original.splits";
35+
String BACKUP_ROOT_PATH_KEY = "hbase.backup.root.path";
3536
boolean KEEP_ORIGINAL_SPLITS_DEFAULT = false;
3637

3738
/**

hbase-backup/src/main/java/org/apache/hadoop/hbase/backup/mapreduce/MapReduceRestoreToOriginalSplitsJob.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ public void run(Path[] dirPaths, TableName[] fromTables, Path restoreRootDir,
4545
// We are using the files from the snapshot. We should copy them rather than move them over
4646
conf.setBoolean(BulkLoadHFiles.ALWAYS_COPY_FILES, true);
4747

48-
FileSystem fs = FileSystem.get(conf);
48+
Path backupRootDir = new Path(conf.get(RestoreJob.BACKUP_ROOT_PATH_KEY));
49+
50+
FileSystem fs = backupRootDir.getFileSystem(conf);
4951
Map<byte[], List<Path>> family2Files = buildFamily2Files(fs, dirPaths, fullBackupRestore);
5052

5153
BulkLoadHFiles bulkLoad = BulkLoadHFiles.create(conf);

hbase-backup/src/main/java/org/apache/hadoop/hbase/backup/util/RestoreTool.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public void incrementalRestoreTable(Connection conn, Path tableBackupPath, Path[
203203
LOG.info("Changed " + newTableDescriptor.getTableName() + " to: " + newTableDescriptor);
204204
}
205205
}
206-
conf.setBoolean(RestoreJob.KEEP_ORIGINAL_SPLITS_KEY, keepOriginalSplits);
206+
configureForRestoreJob(keepOriginalSplits);
207207
RestoreJob restoreService = BackupRestoreFactory.getRestoreJob(conf);
208208

209209
restoreService.run(logDirs, tableNames, restoreRootDir, newTableNames, false);
@@ -355,7 +355,7 @@ private void createAndRestoreTable(Connection conn, TableName tableName, TableNa
355355
// should only try to create the table with all region informations, so we could pre-split
356356
// the regions in fine grain
357357
checkAndCreateTable(conn, newTableName, regionPathList, tableDescriptor, truncateIfExists);
358-
conf.setBoolean(RestoreJob.KEEP_ORIGINAL_SPLITS_KEY, isKeepOriginalSplits);
358+
configureForRestoreJob(isKeepOriginalSplits);
359359
RestoreJob restoreService = BackupRestoreFactory.getRestoreJob(conf);
360360
Path[] paths = new Path[regionPathList.size()];
361361
regionPathList.toArray(paths);
@@ -536,4 +536,9 @@ private void checkAndCreateTable(Connection conn, TableName targetTableName,
536536
}
537537
}
538538
}
539+
540+
private void configureForRestoreJob(boolean keepOriginalSplits) {
541+
conf.setBoolean(RestoreJob.KEEP_ORIGINAL_SPLITS_KEY, keepOriginalSplits);
542+
conf.set(RestoreJob.BACKUP_ROOT_PATH_KEY, backupRootPath.toString());
543+
}
539544
}

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

+53-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import static org.junit.Assert.assertThrows;
2424
import static org.junit.Assert.assertTrue;
2525

26+
import java.io.File;
2627
import java.io.IOException;
2728
import java.nio.ByteBuffer;
2829
import java.util.ArrayList;
@@ -378,6 +379,51 @@ public void TestIncBackupRestoreWithOriginalSplits() throws Exception {
378379
}
379380
}
380381

382+
@Test
383+
public void TestIncBackupRestoreWithOriginalSplitsSeperateFs() throws Exception {
384+
String originalBackupRoot = BACKUP_ROOT_DIR;
385+
// prepare BACKUP_ROOT_DIR on a different filesystem from HBase.
386+
try (Connection conn = ConnectionFactory.createConnection(conf1);
387+
BackupAdminImpl admin = new BackupAdminImpl(conn)) {
388+
String backupTargetDir = TEST_UTIL.getDataTestDir("backupTarget").toString();
389+
BACKUP_ROOT_DIR = new File(backupTargetDir).toURI().toString();
390+
391+
List<TableName> tables = Lists.newArrayList(table1);
392+
393+
insertIntoTable(conn, table1, famName, 3, 100);
394+
String fullBackupId = takeFullBackup(tables, admin, true);
395+
assertTrue(checkSucceeded(fullBackupId));
396+
397+
insertIntoTable(conn, table1, famName, 4, 100);
398+
BackupRequest request =
399+
createBackupRequest(BackupType.INCREMENTAL, tables, BACKUP_ROOT_DIR, true);
400+
String incrementalBackupId = admin.backupTables(request);
401+
assertTrue(checkSucceeded(incrementalBackupId));
402+
403+
TableName[] fromTable = new TableName[] { table1 };
404+
TableName[] toTable = new TableName[] { table1_restore };
405+
406+
// Using original splits
407+
admin.restore(BackupUtils.createRestoreRequest(BACKUP_ROOT_DIR, incrementalBackupId, false,
408+
fromTable, toTable, true, true));
409+
410+
int actualRowCount = TEST_UTIL.countRows(table1_restore);
411+
int expectedRowCount = TEST_UTIL.countRows(table1);
412+
assertEquals(expectedRowCount, actualRowCount);
413+
414+
// Using new splits
415+
admin.restore(BackupUtils.createRestoreRequest(BACKUP_ROOT_DIR, incrementalBackupId, false,
416+
fromTable, toTable, true, false));
417+
418+
expectedRowCount = TEST_UTIL.countRows(table1);
419+
assertEquals(expectedRowCount, actualRowCount);
420+
421+
} finally {
422+
BACKUP_ROOT_DIR = originalBackupRoot;
423+
}
424+
425+
}
426+
381427
private void checkThrowsCFMismatch(IOException ex, List<TableName> tables) {
382428
Throwable cause = Throwables.getRootCause(ex);
383429
assertEquals(cause.getClass(), ColumnFamilyMismatchException.class);
@@ -387,7 +433,13 @@ private void checkThrowsCFMismatch(IOException ex, List<TableName> tables) {
387433

388434
private String takeFullBackup(List<TableName> tables, BackupAdminImpl backupAdmin)
389435
throws IOException {
390-
BackupRequest req = createBackupRequest(BackupType.FULL, tables, BACKUP_ROOT_DIR);
436+
return takeFullBackup(tables, backupAdmin, false);
437+
}
438+
439+
private String takeFullBackup(List<TableName> tables, BackupAdminImpl backupAdmin,
440+
boolean noChecksumVerify) throws IOException {
441+
BackupRequest req =
442+
createBackupRequest(BackupType.FULL, tables, BACKUP_ROOT_DIR, noChecksumVerify);
391443
String backupId = backupAdmin.backupTables(req);
392444
checkSucceeded(backupId);
393445
return backupId;

0 commit comments

Comments
 (0)