Skip to content

Commit

Permalink
HBASE-28585 copy_tables_desc.rb script should handle scenarios where …
Browse files Browse the repository at this point in the history
…the namespace does not exist in the target cluster

Co-authored-by: Peter Song (宋文豪) <[email protected]>
Signed-off-by: Nihal Jain <[email protected]>
  • Loading branch information
wh-song and Peter Song (宋文豪) authored Sep 27, 2024
1 parent fdd8fa5 commit 1ea4bf5
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion bin/replication/copy_tables_desc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ def usage
exit!
end

def create_namespace_if_not_exists(src, dst, namespace)
begin
dst.getNamespaceDescriptor(namespace)
puts format('Namespace "%s" already exists.', namespace)
rescue org.apache.hadoop.hbase.NamespaceNotFoundException
n = src.getNamespaceDescriptor(namespace)
dst.createNamespace(n)
puts format('Namespace "%s" was successfully created.', namespace)
end
end

def copy(src, dst, table)
# verify if table exists in source cluster
begin
Expand All @@ -48,6 +59,10 @@ def copy(src, dst, table)
return
end

# verify if namespace *doesn't* exists in the target cluster
namespace = TableName.valueOf(table).getNamespaceAsString
create_namespace_if_not_exists(src, dst, namespace)

# verify if table *doesn't* exists in the target cluster
begin
dst.createTable(t)
Expand All @@ -56,7 +71,7 @@ def copy(src, dst, table)
return
end

puts format('Schema for table "%s" was succesfully copied to remote cluster.', table)
puts format('Schema for table "%s" was successfully copied to remote cluster.', table)
end

# disable debug/info logging on this script for clarity
Expand Down

0 comments on commit 1ea4bf5

Please sign in to comment.