Repository: hbase
Updated Branches:
  refs/heads/branch-2 f86d311f7 -> 7b5b99e24


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/868821f4
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/868821f4
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/868821f4

Branch: refs/heads/branch-2
Commit: 868821f49912c4224d8e35ef1802bba9e244a0c2
Parents: f86d311
Author: Guanghao Zhang <zg...@apache.org>
Authored: Fri Dec 7 12:12:39 2018 +0800
Committer: Guanghao Zhang <zg...@apache.org>
Committed: Fri Dec 7 16:57:24 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/868821f4/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 5b87595..d46b468 100644
--- a/hbase-shell/src/main/ruby/hbase/replication_admin.rb
+++ b/hbase-shell/src/main/ruby/hbase/replication_admin.rb
@@ -64,6 +64,7 @@ module Hbase
         table_cfs = args.fetch(TABLE_CFS, nil)
         namespaces = args.fetch(NAMESPACES, nil)
         peer_state = args.fetch(STATE, nil)
+        serial = args.fetch(SERIAL, nil)
 
         # Create and populate a ReplicationPeerConfig
         builder = org.apache.hadoop.hbase.replication.ReplicationPeerConfig
@@ -74,6 +75,10 @@ module Hbase
           builder.set_replication_endpoint_impl(endpoint_classname)
         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/868821f4/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 28484cb..1a2c732 100644
--- a/hbase-shell/src/main/ruby/hbase_constants.rb
+++ b/hbase-shell/src/main/ruby/hbase_constants.rb
@@ -77,6 +77,7 @@ module HBaseConstants
   VALUE = 'VALUE'.freeze
   ENDPOINT_CLASSNAME = 'ENDPOINT_CLASSNAME'.freeze
   CLUSTER_KEY = 'CLUSTER_KEY'.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/868821f4/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 eb2da83..bfa50a6 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.
 
 Notice: 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/868821f4/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/868821f4/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 29de710..072aab2 100644
--- a/hbase-shell/src/test/ruby/hbase/replication_admin_test.rb
+++ b/hbase-shell/src/test/ruby/hbase/replication_admin_test.rb
@@ -233,6 +233,27 @@ module Hbase
       end
     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 "set_peer_tableCFs: works with table-cfs map" do
       cluster_key = "zk4,zk5,zk6:11000:/hbase-test"
       args = { CLUSTER_KEY => cluster_key}
@@ -467,6 +488,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/868821f4/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 b78bdfe..4da4a67 100644
--- a/src/main/asciidoc/_chapters/ops_mgt.adoc
+++ b/src/main/asciidoc/_chapters/ops_mgt.adoc
@@ -1743,7 +1743,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.
 

Reply via email to