HBASE-25707 When restoring a table, create a namespace if it does not exist (#3100)

Signed-off-by: Wellington Chevreuil <wchevreuil@apache.org>
This commit is contained in:
申胜利 2021-03-30 03:06:43 +08:00 committed by GitHub
parent 60dde9a433
commit 71417ca14e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 7 deletions

View File

@ -31,6 +31,8 @@ import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.FileUtil;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.NamespaceDescriptor;
import org.apache.hadoop.hbase.NamespaceNotFoundException;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.backup.BackupRestoreFactory;
import org.apache.hadoop.hbase.backup.HBackupFileSystem;
@ -486,13 +488,25 @@ public class RestoreTool {
}
if (createNew) {
LOG.info("Creating target table '" + targetTableName + "'");
byte[][] keys;
if (regionDirList == null || regionDirList.size() == 0) {
admin.createTable(htd);
} else {
keys = generateBoundaryKeys(regionDirList);
// create table using table descriptor and region boundaries
admin.createTable(htd, keys);
byte[][] keys = null;
try {
if (regionDirList == null || regionDirList.size() == 0) {
admin.createTable(htd);
} else {
keys = generateBoundaryKeys(regionDirList);
// create table using table descriptor and region boundaries
admin.createTable(htd, keys);
}
} catch (NamespaceNotFoundException e){
LOG.warn("There was no namespace and the same will be created");
String namespaceAsString = targetTableName.getNamespaceAsString();
LOG.info("Creating target namespace '" + namespaceAsString + "'");
admin.createNamespace(NamespaceDescriptor.create(namespaceAsString).build());
if (null == keys) {
admin.createTable(htd);
} else {
admin.createTable(htd, keys);
}
}
}