HBASE-21549 Add shell command for serial replication peer

This commit is contained in:
Guanghao Zhang 2018-12-07 12:12:39 +08:00
parent f86d311f76
commit 868821f499
6 changed files with 56 additions and 3 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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.