Skip to content

Commit 1ea4bf5

Browse files
wh-songPeter Song (宋文豪)
and
Peter Song (宋文豪)
authored
HBASE-28585 copy_tables_desc.rb script should handle scenarios where the namespace does not exist in the target cluster
Co-authored-by: Peter Song (宋文豪) <[email protected]> Signed-off-by: Nihal Jain <[email protected]>
1 parent fdd8fa5 commit 1ea4bf5

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

bin/replication/copy_tables_desc.rb

+16-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ def usage
3939
exit!
4040
end
4141

42+
def create_namespace_if_not_exists(src, dst, namespace)
43+
begin
44+
dst.getNamespaceDescriptor(namespace)
45+
puts format('Namespace "%s" already exists.', namespace)
46+
rescue org.apache.hadoop.hbase.NamespaceNotFoundException
47+
n = src.getNamespaceDescriptor(namespace)
48+
dst.createNamespace(n)
49+
puts format('Namespace "%s" was successfully created.', namespace)
50+
end
51+
end
52+
4253
def copy(src, dst, table)
4354
# verify if table exists in source cluster
4455
begin
@@ -48,6 +59,10 @@ def copy(src, dst, table)
4859
return
4960
end
5061

62+
# verify if namespace *doesn't* exists in the target cluster
63+
namespace = TableName.valueOf(table).getNamespaceAsString
64+
create_namespace_if_not_exists(src, dst, namespace)
65+
5166
# verify if table *doesn't* exists in the target cluster
5267
begin
5368
dst.createTable(t)
@@ -56,7 +71,7 @@ def copy(src, dst, table)
5671
return
5772
end
5873

59-
puts format('Schema for table "%s" was succesfully copied to remote cluster.', table)
74+
puts format('Schema for table "%s" was successfully copied to remote cluster.', table)
6075
end
6176

6277
# disable debug/info logging on this script for clarity

0 commit comments

Comments
 (0)