From 40ad5aeafe5019abf59c3d149df42d5f4afcc1a2 Mon Sep 17 00:00:00 2001 From: zhangduo Date: Thu, 22 Mar 2018 08:31:20 +0800 Subject: [PATCH] HBASE-20116 addendum fix javadoc and also a simple optimization --- .../ZKReplicationQueueStorage.java | 22 +++++++++++-------- .../TestZKReplicationQueueStorage.java | 2 +- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/hbase-replication/src/main/java/org/apache/hadoop/hbase/replication/ZKReplicationQueueStorage.java b/hbase-replication/src/main/java/org/apache/hadoop/hbase/replication/ZKReplicationQueueStorage.java index 6c9752a9f70..1a5749eadb8 100644 --- a/hbase-replication/src/main/java/org/apache/hadoop/hbase/replication/ZKReplicationQueueStorage.java +++ b/hbase-replication/src/main/java/org/apache/hadoop/hbase/replication/ZKReplicationQueueStorage.java @@ -133,26 +133,30 @@ class ZKReplicationQueueStorage extends ZKReplicationStorageBase } /** + *

* Put all regions under /hbase/replication/regions znode will lead to too many children because - * of the huge number of regions in real production environment. So here we use hash of encoded - * region name to distribute the znode into multiple znodes.
+ * of the huge number of regions in real production environment. So here we will distribute the + * znodes to multiple directories. + *

+ *

* So the final znode path will be format like this: * *

-   * /hbase/replication/regions/e1/ff/dd04e76a6966d4ffa908ed0586764767-100
+   * /hbase/replication/regions/dd/04/e76a6966d4ffa908ed0586764767-100
    * 
* - * The e1 indicate the first level hash of encoded region name, and the ff indicate the second - * level hash of encoded region name, the 100 indicate the peer id.
- * Note that here we use two-level hash because if only one-level hash (such as mod 65535), it - * will still lead to too many children under the /hbase/replication/regions znode. + * Here the full encoded region name is dd04e76a6966d4ffa908ed0586764767, and we use the first two + * characters 'dd' as the first level directory name, and use the next two characters '04' as the + * second level directory name, and the rest part as the prefix of the znode, and the suffix '100' + * is the peer id. + *

* @param encodedRegionName the encoded region name. * @param peerId peer id for replication. * @return ZNode path to persist the max sequence id that we've pushed for the given region and * peer. */ @VisibleForTesting - public String getSerialReplicationRegionPeerNode(String encodedRegionName, String peerId) { + String getSerialReplicationRegionPeerNode(String encodedRegionName, String peerId) { if (encodedRegionName == null || encodedRegionName.length() != RegionInfo.MD5_HEX_LENGTH) { throw new IllegalArgumentException( "Invalid encoded region name: " + encodedRegionName + ", length should be 32."); @@ -160,7 +164,7 @@ class ZKReplicationQueueStorage extends ZKReplicationStorageBase return new StringBuilder(regionsZNode).append(ZNodePaths.ZNODE_PATH_SEPARATOR) .append(encodedRegionName.substring(0, 2)).append(ZNodePaths.ZNODE_PATH_SEPARATOR) .append(encodedRegionName.substring(2, 4)).append(ZNodePaths.ZNODE_PATH_SEPARATOR) - .append(encodedRegionName).append("-").append(peerId).toString(); + .append(encodedRegionName.substring(4)).append("-").append(peerId).toString(); } @Override diff --git a/hbase-replication/src/test/java/org/apache/hadoop/hbase/replication/TestZKReplicationQueueStorage.java b/hbase-replication/src/test/java/org/apache/hadoop/hbase/replication/TestZKReplicationQueueStorage.java index 28cdff17f44..ca86a05d456 100644 --- a/hbase-replication/src/test/java/org/apache/hadoop/hbase/replication/TestZKReplicationQueueStorage.java +++ b/hbase-replication/src/test/java/org/apache/hadoop/hbase/replication/TestZKReplicationQueueStorage.java @@ -257,7 +257,7 @@ public class TestZKReplicationQueueStorage { public void testRegionsZNodeLayout() throws Exception { String peerId = "1"; String encodedRegionName = "31d9792f4435b99d9fb1016f6fbc8dc7"; - String expectedPath = "/hbase/replication/regions/31/d9/" + encodedRegionName + "-" + peerId; + String expectedPath = "/hbase/replication/regions/31/d9/792f4435b99d9fb1016f6fbc8dc7-" + peerId; String path = STORAGE.getSerialReplicationRegionPeerNode(encodedRegionName, peerId); Assert.assertEquals(expectedPath, path); }