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 3b03ae4c7902..ae987b600c5a 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 @@ -183,7 +183,7 @@ static class ReplicationPeerConfigBuilderImpl implements ReplicationPeerConfigBu @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 479fe6b35a43..f7a28f9c998c 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 @@ -469,6 +469,14 @@ public void testInvalidClusterKey() throws InterruptedException { } } + @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 {