This is an automated email from the ASF dual-hosted git repository. vgalaxies pushed a commit to branch trans-pd in repository https://gitbox.apache.org/repos/asf/incubator-hugegraph.git
commit f1c0d44d8b46365037f23cdf37a33ec6bd8ab588 Author: VGalaxies <[email protected]> AuthorDate: Sun May 12 11:44:15 2024 +0800 translate pd common --- .../apache/hugegraph/pd/common/PartitionCache.java | 22 ++++++++++++---------- .../apache/hugegraph/pd/common/PartitionUtils.java | 2 +- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/hugegraph-pd/hg-pd-common/src/main/java/org/apache/hugegraph/pd/common/PartitionCache.java b/hugegraph-pd/hg-pd-common/src/main/java/org/apache/hugegraph/pd/common/PartitionCache.java index 9bd233fd2..9b98cbbb0 100644 --- a/hugegraph-pd/hg-pd-common/src/main/java/org/apache/hugegraph/pd/common/PartitionCache.java +++ b/hugegraph-pd/hg-pd-common/src/main/java/org/apache/hugegraph/pd/common/PartitionCache.java @@ -35,18 +35,18 @@ import com.google.common.collect.RangeMap; import com.google.common.collect.TreeRangeMap; /** - * 放弃 copy on write 的方式 - * 1. 在 graph * partition 数量极多的时候,效率严重下降,不能用 + * abandon copy on write way + * 1. When the number of graph * partitions is extremely large, the efficiency is severely + * reduced and cannot be used */ public class PartitionCache { - // 读写锁对象 private final ReadWriteLock readWriteLock = new ReentrantReadWriteLock(); private final Map<String, AtomicBoolean> locks = new HashMap<>(); Lock writeLock = readWriteLock.writeLock(); - // 每张图一个缓存 + // One cache per graph private volatile Map<String, RangeMap<Long, Integer>> keyToPartIdCache; - // graphName + PartitionID 组成 key + // graphName + PartitionID private volatile Map<String, Map<Integer, Metapb.Partition>> partitionCache; private volatile Map<Integer, Metapb.ShardGroup> shardGroupCache; private volatile Map<Long, Metapb.Store> storeCache; @@ -96,7 +96,7 @@ public class PartitionCache { } /** - * 根据 partitionId 返回分区信息 + * Returns partition information based on partitionId * * @param graphName * @param partId @@ -116,7 +116,7 @@ public class PartitionCache { } /** - * 返回 key 所在的分区信息 + * Returns the partition information where the key is located * * @param key * @return @@ -127,7 +127,7 @@ public class PartitionCache { } /** - * 根据 key 的 hashcode 返回分区信息 + * Returns partition information based on the hashcode of the key * * @param graphName * @param code @@ -177,8 +177,10 @@ public class PartitionCache { partitionCache.computeIfAbsent(graphName, k -> new HashMap<>()).put(partId, partition); if (old != null) { - // old [1-3) 被 [2-3) 覆盖了。当 [1-3) 变成 [1-2) 不应该删除原先的 [1-3) - // 当确认老的 start, end 都是自己的时候,才可以删除老的。(即还没覆盖) + // old [1-3] is covered by [2-3]. When [1-3) becomes [1-2], the original [1-3] + // should not be deleted + // When you confirm that the old start and end are your own, you can delete the + // old ones. (i.e. not covered yet) var graphRange = keyToPartIdCache.get(graphName); if (Objects.equals(partition.getId(), graphRange.get(partition.getStartKey())) && Objects.equals(partition.getId(), graphRange.get(partition.getEndKey() - 1))) { diff --git a/hugegraph-pd/hg-pd-common/src/main/java/org/apache/hugegraph/pd/common/PartitionUtils.java b/hugegraph-pd/hg-pd-common/src/main/java/org/apache/hugegraph/pd/common/PartitionUtils.java index 0e35cc555..1b24ec4c8 100644 --- a/hugegraph-pd/hg-pd-common/src/main/java/org/apache/hugegraph/pd/common/PartitionUtils.java +++ b/hugegraph-pd/hg-pd-common/src/main/java/org/apache/hugegraph/pd/common/PartitionUtils.java @@ -22,7 +22,7 @@ public class PartitionUtils { public static final int MAX_VALUE = 0xffff; /** - * 计算key的hashcode + * compute key hashcode * * @param key * @return hashcode
