Skip to content

Commit a76969c

Browse files
author
Jarryd Lee
committed
HBASE-27541 Add support for defining restore hfile output path
1 parent 222ec68 commit a76969c

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ public Builder withBackupRootDir(String backupRootDir) {
3737
return this;
3838
}
3939

40+
public Builder withTargetRootDir(String targetRootDir) {
41+
request.setTargetRootDir(targetRootDir);
42+
return this;
43+
}
44+
4045
public Builder withBackupId(String backupId) {
4146
request.setBackupId(backupId);
4247
return this;
@@ -68,6 +73,7 @@ public RestoreRequest build() {
6873
}
6974

7075
private String backupRootDir;
76+
private String targetRootDir;
7177
private String backupId;
7278
private boolean check = false;
7379
private TableName[] fromTables;
@@ -86,6 +92,15 @@ private RestoreRequest setBackupRootDir(String backupRootDir) {
8692
return this;
8793
}
8894

95+
public String getTargetRootDir() {
96+
return targetRootDir;
97+
}
98+
99+
public RestoreRequest setTargetRootDir(String targetRootDir) {
100+
this.targetRootDir = targetRootDir;
101+
return this;
102+
}
103+
89104
public String getBackupId() {
90105
return backupId;
91106
}

hbase-backup/src/main/java/org/apache/hadoop/hbase/backup/impl/RestoreTablesClient.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.apache.hadoop.hbase.backup.HBackupFileSystem;
3636
import org.apache.hadoop.hbase.backup.RestoreRequest;
3737
import org.apache.hadoop.hbase.backup.impl.BackupManifest.BackupImage;
38+
import org.apache.hadoop.hbase.backup.mapreduce.MapReduceHFileSplitterJob;
3839
import org.apache.hadoop.hbase.backup.util.RestoreTool;
3940
import org.apache.hadoop.hbase.client.Admin;
4041
import org.apache.hadoop.hbase.client.Connection;
@@ -55,11 +56,11 @@ public class RestoreTablesClient {
5556
private String backupId;
5657
private TableName[] sTableArray;
5758
private TableName[] tTableArray;
58-
private String targetRootDir;
59+
private String backupRootDir;
5960
private boolean isOverwrite;
6061

6162
public RestoreTablesClient(Connection conn, RestoreRequest request) {
62-
this.targetRootDir = request.getBackupRootDir();
63+
this.backupRootDir = request.getBackupRootDir();
6364
this.backupId = request.getBackupId();
6465
this.sTableArray = request.getFromTables();
6566
this.tTableArray = request.getToTables();
@@ -69,6 +70,9 @@ public RestoreTablesClient(Connection conn, RestoreRequest request) {
6970
this.isOverwrite = request.isOverwrite();
7071
this.conn = conn;
7172
this.conf = conn.getConfiguration();
73+
if (request.getTargetRootDir() != null) {
74+
conf.set(MapReduceHFileSplitterJob.BULK_OUTPUT_ROOT_DIR,request.getTargetRootDir());
75+
}
7276
}
7377

7478
/**
@@ -249,7 +253,7 @@ public void execute() throws IOException {
249253
// case RESTORE_IMAGES:
250254
HashMap<TableName, BackupManifest> backupManifestMap = new HashMap<>();
251255
// check and load backup image manifest for the tables
252-
Path rootPath = new Path(targetRootDir);
256+
Path rootPath = new Path(backupRootDir);
253257
HBackupFileSystem.checkImageManifestExist(backupManifestMap, sTableArray, conf, rootPath,
254258
backupId);
255259

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public class MapReduceHFileSplitterJob extends Configured implements Tool {
5656
private static final Logger LOG = LoggerFactory.getLogger(MapReduceHFileSplitterJob.class);
5757
final static String NAME = "HFileSplitterJob";
5858
public final static String BULK_OUTPUT_CONF_KEY = "hfile.bulk.output";
59+
public static final String BULK_OUTPUT_ROOT_DIR = "hfile.bulk.output.root.dir";
5960
public final static String TABLES_KEY = "hfile.input.tables";
6061
public final static String TABLE_MAP_KEY = "hfile.input.tablesmap";
6162
private final static String JOB_NAME_CONF_KEY = "mapreduce.job.name";

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import org.apache.hadoop.hbase.backup.RestoreRequest;
5050
import org.apache.hadoop.hbase.backup.impl.BackupManifest;
5151
import org.apache.hadoop.hbase.backup.impl.BackupManifest.BackupImage;
52+
import org.apache.hadoop.hbase.backup.mapreduce.MapReduceHFileSplitterJob;
5253
import org.apache.hadoop.hbase.client.Admin;
5354
import org.apache.hadoop.hbase.client.Connection;
5455
import org.apache.hadoop.hbase.client.RegionInfo;
@@ -687,7 +688,14 @@ public static boolean validate(HashMap<TableName, BackupManifest> backupManifest
687688

688689
public static Path getBulkOutputDir(String tableName, Configuration conf, boolean deleteOnExit)
689690
throws IOException {
690-
FileSystem fs = FileSystem.get(conf);
691+
FileSystem fs;
692+
String bulkOutputRootDir = conf.get(MapReduceHFileSplitterJob.BULK_OUTPUT_ROOT_DIR);
693+
if (bulkOutputRootDir != null) {
694+
Path rootDir = new Path(bulkOutputRootDir);
695+
fs = FileSystem.get(rootDir.toUri(), conf);
696+
} else {
697+
fs = FileSystem.get(conf);
698+
}
691699
String tmp =
692700
conf.get(HConstants.TEMPORARY_FS_DIRECTORY_KEY, fs.getHomeDirectory() + "/hbase-staging");
693701
Path path = new Path(tmp + Path.SEPARATOR + "bulk_output-" + tableName + "-"

0 commit comments

Comments
 (0)