From 5edd57d6d9f59d39716053528f6213d44b1957fa Mon Sep 17 00:00:00 2001 From: Yuan Zi Date: Tue, 27 Jul 2021 15:02:48 +0800 Subject: [PATCH] fix bug --- ...dgeCloudCollaborationFragmentGenerator.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/cn/edu/tsinghua/iginx/policy/cloud/EdgeCloudCollaborationFragmentGenerator.java b/core/src/main/java/cn/edu/tsinghua/iginx/policy/cloud/EdgeCloudCollaborationFragmentGenerator.java index 9ce2e4cf2..5c84f3de8 100644 --- a/core/src/main/java/cn/edu/tsinghua/iginx/policy/cloud/EdgeCloudCollaborationFragmentGenerator.java +++ b/core/src/main/java/cn/edu/tsinghua/iginx/policy/cloud/EdgeCloudCollaborationFragmentGenerator.java @@ -61,7 +61,7 @@ public Pair, List> generateFragmentsAndStora List edgeStorageEngineList = groupedStorageEngineLists.get(edge); if (edgeStorageEngineList == null) { // 边缘端部署了 iginx,没有部署 iotdb,所有的备份均存储在云端 List storageEngineIds = selectStorageEngines(storageEngineFragmentCounts, replicaNum); - Pair pair = generateFragmentAndStorageUnit(edge + '.', edge + (char) ('.' + 1), startTime, storageEngineIds); + Pair pair = generateFragmentAndStorageUnit(lowerBound(edge), upperBound(edge), startTime, storageEngineIds); fragmentList.add(pair.k); storageUnitList.add(pair.v); } else { // 边缘端部署了 iginx 也部署了 iotdb,每个分片在本地存储一个备份 @@ -86,20 +86,20 @@ public Pair, List> generateFragmentsAndStora } else { // 上空隙 List storageEngineIds = selectStorageEngines(storageEngineFragmentCounts, replicaNum); - Pair pair = generateFragmentAndStorageUnit(null, edges.get(0) + '.', startTime, storageEngineIds); + Pair pair = generateFragmentAndStorageUnit(null, lowerBound(edges.get(0)), startTime, storageEngineIds); fragmentList.add(pair.k); storageUnitList.add(pair.v); // 下空隙 storageEngineIds = selectStorageEngines(storageEngineFragmentCounts, replicaNum); - pair = generateFragmentAndStorageUnit(edges.get(edges.size() - 1) + (char) ('.' + 1), null, startTime, storageEngineIds); + pair = generateFragmentAndStorageUnit(upperBound(edges.get(edges.size() - 1)), null, startTime, storageEngineIds); fragmentList.add(pair.k); storageUnitList.add(pair.v); // 中间的空隙 for (int i = 0; i < edges.size() - 1; i++) { storageEngineIds = selectStorageEngines(storageEngineFragmentCounts, replicaNum); - pair = generateFragmentAndStorageUnit(edges.get(i) + (char) ('.' + 1), edges.get(i + 1) + '.', startTime, storageEngineIds); + pair = generateFragmentAndStorageUnit(upperBound(edges.get(i)), lowerBound(edges.get(i + 1)), startTime, storageEngineIds); fragmentList.add(pair.k); storageUnitList.add(pair.v); } @@ -141,7 +141,7 @@ private List partitionWithinEdge(String edge, int partition) { if (partition < 1) { return Collections.emptyList(); } - return Arrays.asList(edge + '.', edge + (char) ('.' + 1)); + return Arrays.asList(lowerBound(edge), upperBound(edge)); } // 根据时间和序列区间以及一组 storageEngineList 来生成分片和存储单元 @@ -155,4 +155,12 @@ private Pair generateFragmentAndStorageUnit(Strin return new Pair<>(fragment, storageUnit); } + private static String lowerBound(String string) { + return string + '.' + (char)('A' - 1); + } + + private static String upperBound(String string) { + return string + '.' + (char)('z' + 1); + } + }