diff --git a/confignode/src/main/java/org/apache/iotdb/confignode/manager/ConfigManager.java b/confignode/src/main/java/org/apache/iotdb/confignode/manager/ConfigManager.java index f695373c21514..c75db5a5a2eb8 100644 --- a/confignode/src/main/java/org/apache/iotdb/confignode/manager/ConfigManager.java +++ b/confignode/src/main/java/org/apache/iotdb/confignode/manager/ConfigManager.java @@ -24,6 +24,7 @@ import org.apache.iotdb.commons.conf.CommonDescriptor; import org.apache.iotdb.commons.path.PartialPath; import org.apache.iotdb.commons.utils.AuthUtils; +import org.apache.iotdb.commons.utils.PathUtils; import org.apache.iotdb.confignode.conf.ConfigNodeConf; import org.apache.iotdb.confignode.conf.ConfigNodeDescriptor; import org.apache.iotdb.confignode.consensus.request.ConfigRequest; @@ -281,7 +282,7 @@ public DataSet getSchemaPartition(PathPatternTree patternTree) { for (String devicePath : devicePaths) { boolean matchStorageGroup = false; for (String storageGroup : storageGroups) { - if (devicePath.startsWith(storageGroup + ".")) { + if (PathUtils.isStartWith(devicePath, storageGroup)) { matchStorageGroup = true; if (devicePath.contains("*")) { // Get all SchemaPartitions of this StorageGroup if the devicePath contains "*" @@ -342,7 +343,7 @@ public DataSet getOrCreateSchemaPartition(PathPatternTree patternTree) { if (!devicePath.contains("*")) { // Only check devicePaths that without "*" for (String storageGroup : storageGroups) { - if (devicePath.startsWith(storageGroup + ".")) { + if (PathUtils.isStartWith(devicePath, storageGroup)) { partitionSlotsMap .computeIfAbsent(storageGroup, key -> new ArrayList<>()) .add(getPartitionManager().getSeriesPartitionSlot(devicePath)); diff --git a/node-commons/src/main/java/org/apache/iotdb/commons/partition/DataPartition.java b/node-commons/src/main/java/org/apache/iotdb/commons/partition/DataPartition.java index e1004d7445d2a..9523e22482ec8 100644 --- a/node-commons/src/main/java/org/apache/iotdb/commons/partition/DataPartition.java +++ b/node-commons/src/main/java/org/apache/iotdb/commons/partition/DataPartition.java @@ -21,6 +21,7 @@ import org.apache.iotdb.common.rpc.thrift.TRegionReplicaSet; import org.apache.iotdb.common.rpc.thrift.TSeriesPartitionSlot; import org.apache.iotdb.common.rpc.thrift.TTimePartitionSlot; +import org.apache.iotdb.commons.utils.PathUtils; import java.util.ArrayList; import java.util.Collection; @@ -114,7 +115,7 @@ public TRegionReplicaSet getDataRegionReplicaSetForWriting( private String getStorageGroupByDevice(String deviceName) { for (String storageGroup : dataPartitionMap.keySet()) { - if (deviceName.startsWith(storageGroup + ".")) { + if (PathUtils.isStartWith(deviceName, storageGroup)) { return storageGroup; } } diff --git a/node-commons/src/main/java/org/apache/iotdb/commons/partition/SchemaPartition.java b/node-commons/src/main/java/org/apache/iotdb/commons/partition/SchemaPartition.java index 989586458f0be..f9ed307c6908e 100644 --- a/node-commons/src/main/java/org/apache/iotdb/commons/partition/SchemaPartition.java +++ b/node-commons/src/main/java/org/apache/iotdb/commons/partition/SchemaPartition.java @@ -20,6 +20,7 @@ import org.apache.iotdb.common.rpc.thrift.TRegionReplicaSet; import org.apache.iotdb.common.rpc.thrift.TSeriesPartitionSlot; +import org.apache.iotdb.commons.utils.PathUtils; import java.util.ArrayList; import java.util.HashMap; @@ -69,7 +70,7 @@ public TRegionReplicaSet getSchemaRegionReplicaSet(String deviceName) { private String getStorageGroupByDevice(String deviceName) { for (String storageGroup : schemaPartitionMap.keySet()) { - if (deviceName.startsWith(storageGroup + ".")) { + if (PathUtils.isStartWith(deviceName, storageGroup)) { return storageGroup; } } diff --git a/node-commons/src/main/java/org/apache/iotdb/commons/utils/PathUtils.java b/node-commons/src/main/java/org/apache/iotdb/commons/utils/PathUtils.java index a886350498fe1..474010392c345 100644 --- a/node-commons/src/main/java/org/apache/iotdb/commons/utils/PathUtils.java +++ b/node-commons/src/main/java/org/apache/iotdb/commons/utils/PathUtils.java @@ -126,6 +126,10 @@ public static void isLegalMeasurements(List measurements) throws Illegal } } + public static boolean isStartWith(String deviceName, String storageGroup) { + return deviceName.equals(storageGroup) || deviceName.startsWith(storageGroup + "."); + } + private static boolean checkBackQuotes(String src) { int num = src.length() - src.replace("`", "").length(); if (num % 2 == 1) { diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/common/schematree/SchemaTree.java b/server/src/main/java/org/apache/iotdb/db/mpp/common/schematree/SchemaTree.java index 8c3e307b584d3..e30d650140d03 100644 --- a/server/src/main/java/org/apache/iotdb/db/mpp/common/schematree/SchemaTree.java +++ b/server/src/main/java/org/apache/iotdb/db/mpp/common/schematree/SchemaTree.java @@ -20,6 +20,7 @@ package org.apache.iotdb.db.mpp.common.schematree; import org.apache.iotdb.commons.path.PartialPath; +import org.apache.iotdb.commons.utils.PathUtils; import org.apache.iotdb.commons.utils.TestOnly; import org.apache.iotdb.db.conf.IoTDBDescriptor; import org.apache.iotdb.db.metadata.path.MeasurementPath; @@ -267,7 +268,7 @@ public static SchemaTree deserialize(ByteBuffer buffer) { */ public String getBelongedStorageGroup(String pathName) { for (String storageGroup : storageGroups) { - if (pathName.startsWith(storageGroup + ".")) { + if (PathUtils.isStartWith(pathName, storageGroup)) { return storageGroup; } } diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/ClusterPartitionFetcher.java b/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/ClusterPartitionFetcher.java index 1470daf66a6bc..5da5985d80290 100644 --- a/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/ClusterPartitionFetcher.java +++ b/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/ClusterPartitionFetcher.java @@ -30,6 +30,7 @@ import org.apache.iotdb.commons.partition.SchemaPartition; import org.apache.iotdb.commons.partition.executor.SeriesPartitionExecutor; import org.apache.iotdb.commons.path.PartialPath; +import org.apache.iotdb.commons.utils.PathUtils; import org.apache.iotdb.confignode.rpc.thrift.TDataPartitionReq; import org.apache.iotdb.confignode.rpc.thrift.TDataPartitionResp; import org.apache.iotdb.confignode.rpc.thrift.TSchemaNodeManagementReq; @@ -460,7 +461,7 @@ public boolean getStorageGroup( for (String devicePath : devicePaths) { boolean hit = false; for (String storageGroup : storageGroupCache) { - if (devicePath.startsWith(storageGroup + ".")) { + if (PathUtils.isStartWith(devicePath, storageGroup)) { deviceToStorageGroupMap.put(devicePath, storageGroup); hit = true; break; @@ -597,7 +598,7 @@ public void updateSchemaPartitionCache(List devices, SchemaPartition sch if (!device.contains("*")) { String storageGroup = null; for (String storageGroupName : storageGroupNames) { - if (device.startsWith(storageGroupName + ".")) { + if (PathUtils.isStartWith(device, storageGroup)) { storageGroup = storageGroupName; break; } diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/StandalonePartitionFetcher.java b/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/StandalonePartitionFetcher.java index 5f291684b1daf..d389e124f3f7e 100644 --- a/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/StandalonePartitionFetcher.java +++ b/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/StandalonePartitionFetcher.java @@ -25,6 +25,7 @@ import org.apache.iotdb.commons.partition.SchemaPartition; import org.apache.iotdb.commons.partition.executor.SeriesPartitionExecutor; import org.apache.iotdb.commons.path.PartialPath; +import org.apache.iotdb.commons.utils.PathUtils; import org.apache.iotdb.db.conf.IoTDBConfig; import org.apache.iotdb.db.conf.IoTDBDescriptor; import org.apache.iotdb.db.engine.StorageEngineV2; @@ -169,7 +170,7 @@ private Map getDeviceToStorageGroup( List allStorageGroups = localConfigNode.getAllStorageGroupPaths(); for (String devicePath : devicePaths) { for (PartialPath storageGroup : allStorageGroups) { - if (devicePath.startsWith(storageGroup.getFullPath() + ".")) { + if (PathUtils.isStartWith(devicePath, storageGroup.getFullPath())) { deviceToStorageGroup.put(devicePath, storageGroup.getFullPath()); } }