From commits-return-72629-archive-asf-public=cust-asf.ponee.io@hbase.apache.org Tue May 15 02:40:27 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 698121807BC for ; Tue, 15 May 2018 02:40:25 +0200 (CEST) Received: (qmail 44569 invoked by uid 500); 15 May 2018 00:40:22 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 43906 invoked by uid 99); 15 May 2018 00:40:21 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 15 May 2018 00:40:21 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 410B8F6D08; Tue, 15 May 2018 00:40:21 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: zhangduo@apache.org To: commits@hbase.apache.org Date: Tue, 15 May 2018 00:40:33 -0000 Message-Id: In-Reply-To: <873ebb505b1f4d9592fdeb97b6b51c1c@git.apache.org> References: <873ebb505b1f4d9592fdeb97b6b51c1c@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [14/32] hbase git commit: HBASE-19781 Add a new cluster state flag for synchronous replication http://git-wip-us.apache.org/repos/asf/hbase/blob/e1f3d5b6/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/e1f3d5b6/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/e1f3d5b6/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 9a79658..934fa11 100644 --- a/hbase-shell/src/main/ruby/shell.rb +++ b/hbase-shell/src/main/ruby/shell.rb @@ -393,6 +393,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/e1f3d5b6/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/e1f3d5b6/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/e1f3d5b6/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 }