From bb8489255071add3a388f6627dc1496398a25835 Mon Sep 17 00:00:00 2001 From: mokai Date: Sun, 11 Jul 2021 20:45:25 +0800 Subject: [PATCH] HBASE-25700 Enhance znode parent validation when add_peer (#3458) Signed-off-by: Duo Zhang Signed-off-by: Pankaj Kumar --- .../hadoop/hbase/replication/ReplicationPeerConfig.java | 2 +- .../hadoop/hbase/client/TestAsyncReplicationAdminApi.java | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) 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 {