From c7919f23a6111adbde7184a5bb8f7f8202666093 Mon Sep 17 00:00:00 2001 From: openinx Date: Sat, 10 Mar 2018 19:36:43 +0800 Subject: [PATCH] HBASE-20165 Shell command to make a normal peer to be a serial replication peer --- .../src/main/ruby/hbase/replication_admin.rb | 8 ++++ hbase-shell/src/main/ruby/shell.rb | 1 + .../main/ruby/shell/commands/set_peer_serial.rb | 49 ++++++++++++++++++++++ .../src/test/ruby/hbase/replication_admin_test.rb | 23 ++++++++++ 4 files changed, 81 insertions(+) create mode 100644 hbase-shell/src/main/ruby/shell/commands/set_peer_serial.rb diff --git a/hbase-shell/src/main/ruby/hbase/replication_admin.rb b/hbase-shell/src/main/ruby/hbase/replication_admin.rb index b9d4a0c..33b4391 100644 --- a/hbase-shell/src/main/ruby/hbase/replication_admin.rb +++ b/hbase-shell/src/main/ruby/hbase/replication_admin.rb @@ -284,6 +284,14 @@ module Hbase @admin.updateReplicationPeerConfig(id, rpc) end + def set_peer_serial(id, peer_serial) + rpc = get_peer_config(id) + return if rpc.nil? + rpcBuilder = org.apache.hadoop.hbase.replication.ReplicationPeerConfig.newBuilder(rpc) + new_rpc = rpcBuilder.setSerial(peer_serial).build() + @admin.updateReplicationPeerConfig(id, new_rpc) + end + # Set exclude namespaces config for the specified peer def set_peer_exclude_namespaces(id, exclude_namespaces) return if exclude_namespaces.nil? diff --git a/hbase-shell/src/main/ruby/shell.rb b/hbase-shell/src/main/ruby/shell.rb index 507c0a9..5e563df 100644 --- a/hbase-shell/src/main/ruby/shell.rb +++ b/hbase-shell/src/main/ruby/shell.rb @@ -379,6 +379,7 @@ Shell.load_command_group( enable_peer disable_peer set_peer_replicate_all + set_peer_serial set_peer_namespaces append_peer_namespaces remove_peer_namespaces 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 new file mode 100644 index 0000000..875ce8e --- /dev/null +++ b/hbase-shell/src/main/ruby/shell/commands/set_peer_serial.rb @@ -0,0 +1,49 @@ +# +# Copyright The Apache Software Foundation +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +module Shell + module Commands + class SetPeerSerial < Command + def help + <<-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. + + Examples: + + # set serial flag to true + hbase> set_peer_serial '1', true + # set serial flag to false + hbase> set_peer_serial '1', false +EOF + end + + def command(id, peer_serial) + replication_admin.set_peer_serial(id, peer_serial) + end + 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 0f84396..fe99e00 100644 --- a/hbase-shell/src/test/ruby/hbase/replication_admin_test.rb +++ b/hbase-shell/src/test/ruby/hbase/replication_admin_test.rb @@ -459,6 +459,29 @@ module Hbase replication_admin.remove_peer(@peer_id) end + define_test 'set_peer_serial' do + cluster_key = 'zk4,zk5,zk6:11000:/hbase-test' + + args = {CLUSTER_KEY => cluster_key} + command(:add_peer, @peer_id, args) + + assert_equal(1, command(:list_peers).length) + peer_config = command(:list_peers).get(0).getPeerConfig + assert_equal(false, peer_config.isSerial) + + command(:set_peer_serial, @peer_id, true) + peer_config = command(:list_peers).get(0).getPeerConfig + assert_equal(true, peer_config.isSerial) + + command(:set_peer_serial, @peer_id, false) + peer_config = command(:list_peers).get(0).getPeerConfig + assert_equal(false, peer_config.isSerial) + + # cleanup for future tests + replication_admin.remove_peer(@peer_id) + assert_equal(0, command(:list_peers).length) + end + define_test "set_peer_bandwidth: works with peer bandwidth upper limit" do cluster_key = "localhost:2181:/hbase-test" args = { CLUSTER_KEY => cluster_key } -- 2.3.2 (Apple Git-55)