From 96e225345bf3a4d6ced958b2fe242601b8f5bb3a Mon Sep 17 00:00:00 2001 From: Guanghao Zhang Date: Wed, 5 Dec 2018 18:05:03 +0800 Subject: [PATCH] HBASE-21549 Add shell command for serial replication peer --- hbase-shell/src/main/ruby/hbase/replication_admin.rb | 5 +++++ hbase-shell/src/main/ruby/hbase_constants.rb | 1 + hbase-shell/src/main/ruby/shell/commands/add_peer.rb | 2 ++ .../src/main/ruby/shell/commands/set_peer_serial.rb | 14 +++++--------- .../src/test/ruby/hbase/replication_admin_test.rb | 20 ++++++++++++++++++++ 5 files changed, 33 insertions(+), 9 deletions(-) diff --git a/hbase-shell/src/main/ruby/hbase/replication_admin.rb b/hbase-shell/src/main/ruby/hbase/replication_admin.rb index 5f86365..c01b6ea 100644 --- a/hbase-shell/src/main/ruby/hbase/replication_admin.rb +++ b/hbase-shell/src/main/ruby/hbase/replication_admin.rb @@ -66,6 +66,7 @@ module Hbase namespaces = args.fetch(NAMESPACES, nil) peer_state = args.fetch(STATE, nil) remote_wal_dir = args.fetch(REMOTE_WAL_DIR, nil) + serial = args.fetch(SERIAL, nil) # Create and populate a ReplicationPeerConfig builder = ReplicationPeerConfig.newBuilder() @@ -79,6 +80,10 @@ module Hbase builder.setRemoteWALDir(remote_wal_dir) end + unless serial.nil? + builder.setSerial(serial) + end + unless config.nil? builder.putAllConfiguration(config) end diff --git a/hbase-shell/src/main/ruby/hbase_constants.rb b/hbase-shell/src/main/ruby/hbase_constants.rb index 2870dfb..4c1ad22 100644 --- a/hbase-shell/src/main/ruby/hbase_constants.rb +++ b/hbase-shell/src/main/ruby/hbase_constants.rb @@ -78,6 +78,7 @@ module HBaseConstants ENDPOINT_CLASSNAME = 'ENDPOINT_CLASSNAME'.freeze CLUSTER_KEY = 'CLUSTER_KEY'.freeze REMOTE_WAL_DIR = 'REMOTE_WAL_DIR'.freeze + SERIAL = 'SERIAL'.freeze TABLE_CFS = 'TABLE_CFS'.freeze NAMESPACES = 'NAMESPACES'.freeze STATE = 'STATE'.freeze diff --git a/hbase-shell/src/main/ruby/shell/commands/add_peer.rb b/hbase-shell/src/main/ruby/shell/commands/add_peer.rb index 4b6f294..1013521 100644 --- a/hbase-shell/src/main/ruby/shell/commands/add_peer.rb +++ b/hbase-shell/src/main/ruby/shell/commands/add_peer.rb @@ -50,6 +50,8 @@ Examples: NAMESPACES => ["ns1", "ns2", "ns3"] hbase> add_peer '2', CLUSTER_KEY => "zk1,zk2,zk3:2182:/hbase-prod", NAMESPACES => ["ns1", "ns2"], TABLE_CFS => { "ns3:table1" => [], "ns3:table2" => ["cf1"] } + hbase> add_peer '3', CLUSTER_KEY => "zk1,zk2,zk3:2182:/hbase-prod", + NAMESPACES => ["ns1", "ns2", "ns3"], SERIAL => true For a custom replication endpoint, the ENDPOINT_CLASSNAME can be provided. Two optional arguments are DATA and CONFIG which can be specified to set different either the peer_data or configuration diff --git a/hbase-shell/src/main/ruby/shell/commands/set_peer_serial.rb b/hbase-shell/src/main/ruby/shell/commands/set_peer_serial.rb index d556077..e16875a 100644 --- a/hbase-shell/src/main/ruby/shell/commands/set_peer_serial.rb +++ b/hbase-shell/src/main/ruby/shell/commands/set_peer_serial.rb @@ -25,12 +25,8 @@ module Shell <<-EOF Set the serial flag to true or false for the specified peer. - If serial flag is true, then all logs of user tables (REPLICATION_SCOPE != 0) will be - replicated to peer cluster serially, which means that each segment of log for replicated - table will be pushed to peer cluster in order of their log sequence id. - - If serial flag is false, then the source cluster won't ensure that the logs of replicated - table will be pushed to peer cluster serially. + If serial flag is true, then all user tables (REPLICATION_SCOPE != 0) + will be replicate serially to peer cluster. Examples: @@ -38,11 +34,11 @@ module Shell hbase> set_peer_serial '1', true # set serial flag to false hbase> set_peer_serial '1', false - EOF +EOF end - def command(id, peer_serial) - replication_admin.set_peer_serial(id, peer_serial) + def command(id, serial) + replication_admin.set_peer_serial(id, serial) end end end diff --git a/hbase-shell/src/test/ruby/hbase/replication_admin_test.rb b/hbase-shell/src/test/ruby/hbase/replication_admin_test.rb index f44fd8c..3d7b3a1 100644 --- a/hbase-shell/src/test/ruby/hbase/replication_admin_test.rb +++ b/hbase-shell/src/test/ruby/hbase/replication_admin_test.rb @@ -100,6 +100,26 @@ module Hbase command(:remove_peer, @peer_id) end + define_test "add_peer: serial" do + cluster_key = "server1.cie.com:2181:/hbase" + remote_wal_dir = "hdfs://srv1:9999/hbase" + table_cfs = { "ns3:table1" => [], "ns3:table2" => [], + "ns3:table3" => [] } + args = { CLUSTER_KEY => cluster_key, SERIAL => true, + TABLE_CFS => table_cfs} + command(:add_peer, @peer_id, args) + + assert_equal(1, command(:list_peers).length) + peer = command(:list_peers).get(0) + assert_equal(@peer_id, peer.getPeerId) + assert_equal(cluster_key, peer.getPeerConfig.getClusterKey) + assert_equal(true, peer.getPeerConfig.isSerial) + assert_tablecfs_equal(table_cfs, peer.getPeerConfig.getTableCFsMap()) + + # cleanup for future tests + command(:remove_peer, @peer_id) + end + define_test "add_peer: remote wal dir" do cluster_key = "server1.cie.com:2181:/hbase" remote_wal_dir = "hdfs://srv1:9999/hbase" -- 2.7.4