hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apurt...@apache.org
Subject [3/4] hbase git commit: HBASE-16379 [replication] Minor improvement to replication/copy_tables_desc.rb
Date Thu, 25 Aug 2016 01:12:22 GMT
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/c2830638
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/c2830638
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/c2830638

Branch: refs/heads/0.98
Commit: c2830638709897fd53baece55f7a22848a932b93
Parents: 62690df
Author: Esteban Gutierrez <esteban@apache.org>
Authored: Mon Aug 8 16:10:29 2016 -0700
Committer: Andrew Purtell <apurtell@apache.org>
Committed: Wed Aug 24 17:54:36 2016 -0700

----------------------------------------------------------------------
 bin/replication/copy_tables_desc.rb | 41 +++++++++++++++++++++++++-------
 1 file changed, 33 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/c2830638/bin/replication/copy_tables_desc.rb
----------------------------------------------------------------------
diff --git a/bin/replication/copy_tables_desc.rb b/bin/replication/copy_tables_desc.rb
index bc70031..07b17a8 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
@@ -37,11 +36,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
 
@@ -51,6 +71,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])
@@ -65,9 +87,12 @@ c2.set(HConstants::ZOOKEEPER_ZNODE_PARENT, parts2[2])
 
 admin2 = HBaseAdmin.new(c2)
 
-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"


Mime
View raw message