You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by es...@apache.org on 2016/08/10 18:02:52 UTC
hbase git commit: HBASE-16379 [replication] Minor improvement to
replication/copy_tables_desc.rb
Repository: hbase
Updated Branches:
refs/heads/master 45bb6180a -> b3888eadf
HBASE-16379 [replication] Minor improvement to replication/copy_tables_desc.rb
Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/b3888ead
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/b3888ead
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/b3888ead
Branch: refs/heads/master
Commit: b3888eadf8ac081729385b434f8da626d02d031a
Parents: 45bb618
Author: Esteban Gutierrez <es...@apache.org>
Authored: Mon Aug 8 16:10:29 2016 -0700
Committer: Esteban Gutierrez <es...@apache.org>
Committed: Wed Aug 10 11:00:23 2016 -0700
----------------------------------------------------------------------
bin/replication/copy_tables_desc.rb | 39 +++++++++++++++++++++++++++-----
1 file changed, 33 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hbase/blob/b3888ead/bin/replication/copy_tables_desc.rb
----------------------------------------------------------------------
diff --git a/bin/replication/copy_tables_desc.rb b/bin/replication/copy_tables_desc.rb
index 8a6c670..a7cc3a3 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,32 @@ 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 (src, dst, table)
+ # verify if table exists in source cluster
+ begin
+ t = src.getTableDescriptor(table.to_java_bytes)
+ rescue org.apache.hadoop.hbase.TableNotFoundException
+ puts "Source table \"%s\" doesn't exist, skipping." % table
+ return
+ end
+
+ # verify if table *doesn't* exists in the target cluster
+ begin
+ dst.createTable(t)
+ rescue org.apache.hadoop.hbase.TableExistsException
+ puts "Destination table \"%s\" exists in remote cluster, skipping." % table
+ return
+ end
+
+ puts "Schema for table \"%s\" was succesfully copied to remote cluster." % table
+end
+
+
+if ARGV.size < 2 || ARGV.size > 3
usage
end
@@ -52,6 +72,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 +90,16 @@ 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?
+ admin1.listTableNames().each do |t|
+ copy(admin1, admin2, t.nameAsString())
+ end
+else
+ parts3.each do |t|
+ copy(admin1, admin2, t)
+ end
end
-puts "All descriptions were copied"
admin1.close()
admin2.close()
connection1.close()