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.FileUtil;
|
||||||
import org.apache.hadoop.fs.Path;
|
import org.apache.hadoop.fs.Path;
|
||||||
import org.apache.hadoop.hbase.HConstants;
|
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.TableName;
|
||||||
import org.apache.hadoop.hbase.backup.BackupRestoreFactory;
|
import org.apache.hadoop.hbase.backup.BackupRestoreFactory;
|
||||||
import org.apache.hadoop.hbase.backup.HBackupFileSystem;
|
import org.apache.hadoop.hbase.backup.HBackupFileSystem;
|
||||||
|
@ -486,13 +488,25 @@ public class RestoreTool {
|
||||||
}
|
}
|
||||||
if (createNew) {
|
if (createNew) {
|
||||||
LOG.info("Creating target table '" + targetTableName + "'");
|
LOG.info("Creating target table '" + targetTableName + "'");
|
||||||
byte[][] keys;
|
byte[][] keys = null;
|
||||||
if (regionDirList == null || regionDirList.size() == 0) {
|
try {
|
||||||
admin.createTable(htd);
|
if (regionDirList == null || regionDirList.size() == 0) {
|
||||||
} else {
|
admin.createTable(htd);
|
||||||
keys = generateBoundaryKeys(regionDirList);
|
} else {
|
||||||
// create table using table descriptor and region boundaries
|
keys = generateBoundaryKeys(regionDirList);
|
||||||
admin.createTable(htd, keys);
|
// 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue