HBASE-21549 Add shell command for serial replication peer
Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/1e65bd5c Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/1e65bd5c Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/1e65bd5c Branch: refs/heads/HBASE-20952 Commit: 1e65bd5cf96cf5affd446596ef10b1034e2e0a88 Parents: dfb9ae8 Author: Guanghao Zhang <zg...@apache.org> Authored: Wed Dec 5 18:05:03 2018 +0800 Committer: Guanghao Zhang <zg...@apache.org> Committed: Fri Dec 7 10:10:13 2018 +0800 ---------------------------------------------------------------------- .../src/main/ruby/hbase/replication_admin.rb | 5 +++++ hbase-shell/src/main/ruby/hbase_constants.rb | 1 + .../src/main/ruby/shell/commands/add_peer.rb | 4 ++++ .../main/ruby/shell/commands/set_peer_serial.rb | 4 ++-- .../test/ruby/hbase/replication_admin_test.rb | 22 +++++++++++++++++++ src/main/asciidoc/_chapters/ops_mgt.adoc | 23 +++++++++++++++++++- 6 files changed, 56 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/1e65bd5c/hbase-shell/src/main/ruby/hbase/replication_admin.rb ---------------------------------------------------------------------- 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 http://git-wip-us.apache.org/repos/asf/hbase/blob/1e65bd5c/hbase-shell/src/main/ruby/hbase_constants.rb ---------------------------------------------------------------------- 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 http://git-wip-us.apache.org/repos/asf/hbase/blob/1e65bd5c/hbase-shell/src/main/ruby/shell/commands/add_peer.rb ---------------------------------------------------------------------- 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..9be42ac 100644 --- a/hbase-shell/src/main/ruby/shell/commands/add_peer.rb +++ b/hbase-shell/src/main/ruby/shell/commands/add_peer.rb @@ -34,6 +34,8 @@ An optional parameter for namespaces identifies which namespace's tables will be to the peer cluster. An optional parameter for table column families identifies which tables and/or column families will be replicated to the peer cluster. +An optional parameter for serial flag identifies whether or not the replication peer is a serial +replication peer. The default serial flag is false. Note: Set a namespace in the peer config means that all tables in this namespace will be replicated to the peer cluster. So if you already have set a namespace in peer config, @@ -50,6 +52,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 http://git-wip-us.apache.org/repos/asf/hbase/blob/1e65bd5c/hbase-shell/src/main/ruby/shell/commands/set_peer_serial.rb ---------------------------------------------------------------------- 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..a6484cd 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 @@ -41,8 +41,8 @@ module Shell 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 http://git-wip-us.apache.org/repos/asf/hbase/blob/1e65bd5c/hbase-shell/src/test/ruby/hbase/replication_admin_test.rb ---------------------------------------------------------------------- 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..f4c771e 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,27 @@ 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" => [] } + # add a new replication peer which serial flag is true + 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" @@ -490,6 +511,7 @@ module Hbase assert_equal(1, command(:list_peers).length) peer_config = command(:list_peers).get(0).getPeerConfig + # the default serial flag is false assert_equal(false, peer_config.isSerial) command(:set_peer_serial, @peer_id, true) http://git-wip-us.apache.org/repos/asf/hbase/blob/1e65bd5c/src/main/asciidoc/_chapters/ops_mgt.adoc ---------------------------------------------------------------------- diff --git a/src/main/asciidoc/_chapters/ops_mgt.adoc b/src/main/asciidoc/_chapters/ops_mgt.adoc index f2ee1cc..db85b45 100644 --- a/src/main/asciidoc/_chapters/ops_mgt.adoc +++ b/src/main/asciidoc/_chapters/ops_mgt.adoc @@ -1898,7 +1898,28 @@ This treatment can possibly lead to data inconsistency between source and destin .Serial replication configuration -. Set the serial flag to true for a repliation peer. You can either set it to true when creating a replication peer, or change it to true later. +Set the serial flag to true for a repliation peer. And the default serial flag is false. + +* Add a new replication peer which serial flag is true + +[source,ruby] +---- +hbase> add_peer '1', CLUSTER_KEY => "server1.cie.com:2181:/hbase", SERIAL => true +---- + +* Set a replication peer's serial flag to false + +[source,ruby] +---- +hbase> set_peer_serial '1', false +---- + +* Set a replication peer's serial flag to true + +[source,ruby] +---- +hbase> set_peer_serial '1', true +---- The serial replication feature had been done firstly in link:https://issues.apache.org/jira/browse/HBASE-9465[HBASE-9465] and then reverted and redone in link:https://issues.apache.org/jira/browse/HBASE-20046[HBASE-20046]. You can find more details in these issues.