From 26f1f8925a3dd622facbdf050cae1188bd0f3367 Mon Sep 17 00:00:00 2001 From: Esteban Gutierrez Date: Mon, 8 Aug 2016 16:10:29 -0700 Subject: [PATCH] HBASE-16379: [replication] Minor improvement to replication/copy_tables_desc.rb --- bin/replication/copy_tables_desc.rb | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/bin/replication/copy_tables_desc.rb b/bin/replication/copy_tables_desc.rb index 8a6c670..d7f4aad 100644 --- a/bin/replication/copy_tables_desc.rb +++ b/bin/replication/copy_tables_desc.rb @@ -27,7 +27,6 @@ include Java import org.apache.commons.logging.LogFactory import org.apache.hadoop.hbase.HBaseConfiguration import org.apache.hadoop.hbase.HConstants -import org.apache.hadoop.hbase.EmptyWatcher import org.apache.hadoop.hbase.client.HBaseAdmin import org.apache.hadoop.hbase.HTableDescriptor import org.apache.hadoop.conf.Configuration @@ -38,11 +37,20 @@ NAME = "copy_tables_desc" # Print usage for this script def usage - puts 'Usage: %s.rb master_zookeeper.quorum.peers:clientport:znode_parent slave_zookeeper.quorum.peers:clientport:znode_parent' % NAME + puts 'Usage: %s.rb master_zookeeper.quorum.peers:clientport:znode_parent slave_zookeeper.quorum.peers:clientport:znode_parent [table1,table2,table3,...]' % NAME exit! end -if ARGV.size != 2 +def copy (admin1, admin2, table) + if not admin2.tableExists(table.getTableName()) + puts "Copying schema from %s" % table + admin2.createTable(table) + else + puts "Skipping schema from %s since table already exists in remote cluster" % table + end +end + +if ARGV.size < 2 || ARGV.size > 3 usage end @@ -52,6 +60,8 @@ parts1 = ARGV[0].split(":") parts2 = ARGV[1].split(":") +parts3 = ARGV[2].split(",") unless ARGV[2].nil? + c1 = HBaseConfiguration.create() c1.set(HConstants::ZOOKEEPER_QUORUM, parts1[0]) c1.set("hbase.zookeeper.property.clientPort", parts1[1]) @@ -68,11 +78,22 @@ c2.set(HConstants::ZOOKEEPER_ZNODE_PARENT, parts2[2]) connection2 = ConnectionFactory.createConnection(c2) admin2 = connection2.getAdmin() -for t in admin1.listTables() - admin2.createTable(t) +if parts3.nil? + for t in admin1.listTables() + copy(admin1, admin2, t) + end +else + parts3.each do |src| + begin + t = admin1.getTableDescriptor(src.to_java_bytes) + rescue org.apache.hadoop.hbase.TableNotFoundException + puts "Source table %s doesn't exist, skipping" % src + next + end + copy(admin1, admin2, t) + end end -puts "All descriptions were copied" admin1.close() admin2.close() connection1.close() -- 2.9.2