diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/replication/ReplicationPeerConfig.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/replication/ReplicationPeerConfig.java index 534357af569..2f871a39755 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/replication/ReplicationPeerConfig.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/replication/ReplicationPeerConfig.java @@ -263,7 +263,7 @@ public class ReplicationPeerConfig { @Override public ReplicationPeerConfigBuilder setClusterKey(String clusterKey) { - this.clusterKey = clusterKey; + this.clusterKey = clusterKey != null ? clusterKey.trim() : null; return this; } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncReplicationAdminApi.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncReplicationAdminApi.java index 5aecd310d22..5a0fc975ffb 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncReplicationAdminApi.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncReplicationAdminApi.java @@ -477,6 +477,14 @@ public class TestAsyncReplicationAdminApi extends TestAsyncAdminBase { } } + @Test + public void testClusterKeyWithTrailingSpace() throws Exception { + admin.addReplicationPeer(ID_ONE, + ReplicationPeerConfig.newBuilder().setClusterKey(KEY_ONE + " ").build()).get(); + String clusterKey = admin.getReplicationPeerConfig(ID_ONE).get().getClusterKey(); + assertEquals(KEY_ONE, clusterKey); + } + @Test public void testInvalidReplicationEndpoint() throws InterruptedException { try {