http://git-wip-us.apache.org/repos/asf/hbase/blob/409e8017/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsckReplication.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsckReplication.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsckReplication.java index 8911982..f5eca39 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsckReplication.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsckReplication.java @@ -28,6 +28,7 @@ import org.apache.hadoop.hbase.replication.ReplicationPeerConfig; import org.apache.hadoop.hbase.replication.ReplicationPeerStorage; import org.apache.hadoop.hbase.replication.ReplicationQueueStorage; import org.apache.hadoop.hbase.replication.ReplicationStorageFactory; +import org.apache.hadoop.hbase.replication.SyncReplicationState; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.testclassification.ReplicationTests; import org.apache.hadoop.hbase.util.HBaseFsck.ErrorReporter.ERROR_CODE; @@ -67,9 +68,9 @@ public class TestHBaseFsckReplication { String peerId1 = "1"; String peerId2 = "2"; peerStorage.addPeer(peerId1, ReplicationPeerConfig.newBuilder().setClusterKey("key").build(), - true); + true, SyncReplicationState.NONE); peerStorage.addPeer(peerId2, ReplicationPeerConfig.newBuilder().setClusterKey("key").build(), - true); + true, SyncReplicationState.NONE); for (int i = 0; i < 10; i++) { queueStorage.addWAL(ServerName.valueOf("localhost", 10000 + i, 100000 + i), peerId1, "file-" + i);
http://git-wip-us.apache.org/repos/asf/hbase/blob/409e8017/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 d1f1344..5f86365 100644 --- a/hbase-shell/src/main/ruby/hbase/replication_admin.rb +++ b/hbase-shell/src/main/ruby/hbase/replication_admin.rb @@ -20,6 +20,7 @@ include Java java_import org.apache.hadoop.hbase.client.replication.ReplicationPeerConfigUtil +java_import org.apache.hadoop.hbase.replication.SyncReplicationState java_import org.apache.hadoop.hbase.replication.ReplicationPeerConfig java_import org.apache.hadoop.hbase.util.Bytes java_import org.apache.hadoop.hbase.zookeeper.ZKConfig @@ -338,6 +339,20 @@ module Hbase '!' + ReplicationPeerConfigUtil.convertToString(tableCFs) end + # Transit current cluster to a new state in the specified synchronous + # replication peer + def transit_peer_sync_replication_state(id, state) + if 'ACTIVE'.eql?(state) + @admin.transitReplicationPeerSyncReplicationState(id, SyncReplicationState::ACTIVE) + elsif 'DOWNGRADE_ACTIVE'.eql?(state) + @admin.transitReplicationPeerSyncReplicationState(id, SyncReplicationState::DOWNGRADE_ACTIVE) + elsif 'STANDBY'.eql?(state) + @admin.transitReplicationPeerSyncReplicationState(id, SyncReplicationState::STANDBY) + else + raise(ArgumentError, 'synchronous replication state must be ACTIVE, DOWNGRADE_ACTIVE or STANDBY') + end + end + #---------------------------------------------------------------------------------------------- # Enables a table's replication switch def enable_tablerep(table_name) http://git-wip-us.apache.org/repos/asf/hbase/blob/409e8017/hbase-shell/src/main/ruby/shell.rb ---------------------------------------------------------------------- diff --git a/hbase-shell/src/main/ruby/shell.rb b/hbase-shell/src/main/ruby/shell.rb index ab07a79..ba4d154 100644 --- a/hbase-shell/src/main/ruby/shell.rb +++ b/hbase-shell/src/main/ruby/shell.rb @@ -391,6 +391,7 @@ Shell.load_command_group( get_peer_config list_peer_configs update_peer_config + transit_peer_sync_replication_state ] ) http://git-wip-us.apache.org/repos/asf/hbase/blob/409e8017/hbase-shell/src/main/ruby/shell/commands/list_peers.rb ---------------------------------------------------------------------- diff --git a/hbase-shell/src/main/ruby/shell/commands/list_peers.rb b/hbase-shell/src/main/ruby/shell/commands/list_peers.rb index f3ab749..f2ec014 100644 --- a/hbase-shell/src/main/ruby/shell/commands/list_peers.rb +++ b/hbase-shell/src/main/ruby/shell/commands/list_peers.rb @@ -39,8 +39,8 @@ EOF peers = replication_admin.list_peers formatter.header(%w[PEER_ID CLUSTER_KEY ENDPOINT_CLASSNAME - REMOTE_ROOT_DIR STATE REPLICATE_ALL - NAMESPACES TABLE_CFS BANDWIDTH + REMOTE_ROOT_DIR SYNC_REPLICATION_STATE STATE + REPLICATE_ALL NAMESPACES TABLE_CFS BANDWIDTH SERIAL]) peers.each do |peer| @@ -67,7 +67,7 @@ EOF remote_root_dir = config.getRemoteWALDir end formatter.row([id, cluster_key, endpoint_classname, - remote_root_dir, state, + remote_root_dir, peer.getSyncReplicationState, state, config.replicateAllUserTables, namespaces, tableCFs, config.getBandwidth, config.isSerial]) end http://git-wip-us.apache.org/repos/asf/hbase/blob/409e8017/hbase-shell/src/main/ruby/shell/commands/transit_peer_sync_replication_state.rb ---------------------------------------------------------------------- diff --git a/hbase-shell/src/main/ruby/shell/commands/transit_peer_sync_replication_state.rb b/hbase-shell/src/main/ruby/shell/commands/transit_peer_sync_replication_state.rb new file mode 100644 index 0000000..6d4a963 --- /dev/null +++ b/hbase-shell/src/main/ruby/shell/commands/transit_peer_sync_replication_state.rb @@ -0,0 +1,44 @@ +# +# 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 TransitPeerSyncReplicationState < Command + def help + <<-EOF +Transit current cluster to new state in the specified synchronous replication peer. +Examples: + + # Transit cluster state to DOWNGRADE_ACTIVE in a synchronous replication peer + hbase> transit_peer_sync_replication_state '1', 'DOWNGRADE_ACTIVE' + # Transit cluster state to ACTIVE in a synchronous replication peer + hbase> transit_peer_sync_replication_state '1', 'ACTIVE' + # Transit cluster state to STANDBY in a synchronous replication peer + hbase> transit_peer_sync_replication_state '1', 'STANDBY' + +EOF + end + + def command(id, state) + replication_admin.transit_peer_sync_replication_state(id, state) + end + end + end +end http://git-wip-us.apache.org/repos/asf/hbase/blob/409e8017/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 5d04fbb..9d364ce 100644 --- a/hbase-shell/src/test/ruby/hbase/replication_admin_test.rb +++ b/hbase-shell/src/test/ruby/hbase/replication_admin_test.rb @@ -23,6 +23,9 @@ require 'hbase/hbase' require 'hbase/table' include HBaseConstants +include Java + +java_import org.apache.hadoop.hbase.replication.SyncReplicationState module Hbase class ReplicationAdminTest < Test::Unit::TestCase @@ -513,6 +516,27 @@ module Hbase command(:remove_peer, @peer_id) end + define_test "transit_peer_sync_replication_state: test" do + cluster_key = "server1.cie.com:2181:/hbase" + remote_wal_dir = "hdfs://srv1:9999/hbase" + args = { CLUSTER_KEY => cluster_key, REMOTE_WAL_DIR => remote_wal_dir } + 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(SyncReplicationState::DOWNGRADE_ACTIVE, peer.getSyncReplicationState) + + command(:transit_peer_sync_replication_state, @peer_id, 'ACTIVE') + assert_equal(1, command(:list_peers).length) + peer = command(:list_peers).get(0) + assert_equal(@peer_id, peer.getPeerId) + assert_equal(SyncReplicationState::ACTIVE, peer.getSyncReplicationState) + + # cleanup for future tests + command(:remove_peer, @peer_id) + end + define_test "get_peer_config: works with simple clusterKey peer" do cluster_key = "localhost:2181:/hbase-test" args = { CLUSTER_KEY => cluster_key }