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:
parent
60dde9a433
commit
71417ca14e
|
@ -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,7 +488,8 @@ public class RestoreTool {
|
|||
}
|
||||
if (createNew) {
|
||||
LOG.info("Creating target table '" + targetTableName + "'");
|
||||
byte[][] keys;
|
||||
byte[][] keys = null;
|
||||
try {
|
||||
if (regionDirList == null || regionDirList.size() == 0) {
|
||||
admin.createTable(htd);
|
||||
} else {
|
||||
|
@ -494,6 +497,17 @@ public class RestoreTool {
|
|||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
long startTime = EnvironmentEdgeManager.currentTime();
|
||||
|
|
Loading…
Reference in New Issue