diff --git a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/schema/ClusterSchemaInfo.java b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/schema/ClusterSchemaInfo.java index b758631316df..9c599da5840c 100644 --- a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/schema/ClusterSchemaInfo.java +++ b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/schema/ClusterSchemaInfo.java @@ -557,8 +557,13 @@ public void isDatabaseNameValid(final String databaseName, final boolean isTable throws MetadataException { databaseReadWriteLock.readLock().lock(); try { - (isTableModel ? tableModelMTree : treeModelMTree) - .checkDatabaseAlreadySet(getQualifiedDatabasePartialPath(databaseName)); + final PartialPath databasePath = getQualifiedDatabasePartialPath(databaseName); + for (final String node : databasePath.getNodes()) { + if (node.isEmpty()) { + throw new IllegalPathException(databaseName); + } + } + (isTableModel ? tableModelMTree : treeModelMTree).checkDatabaseAlreadySet(databasePath); } finally { databaseReadWriteLock.readLock().unlock(); } diff --git a/iotdb-core/confignode/src/test/java/org/apache/iotdb/confignode/persistence/schema/ClusterSchemaInfoTest.java b/iotdb-core/confignode/src/test/java/org/apache/iotdb/confignode/persistence/schema/ClusterSchemaInfoTest.java index 948a3c5a73d9..142d015ebf96 100644 --- a/iotdb-core/confignode/src/test/java/org/apache/iotdb/confignode/persistence/schema/ClusterSchemaInfoTest.java +++ b/iotdb-core/confignode/src/test/java/org/apache/iotdb/confignode/persistence/schema/ClusterSchemaInfoTest.java @@ -20,6 +20,7 @@ package org.apache.iotdb.confignode.persistence.schema; import org.apache.iotdb.commons.exception.IllegalPathException; +import org.apache.iotdb.commons.exception.MetadataException; import org.apache.iotdb.commons.path.PartialPath; import org.apache.iotdb.commons.schema.table.TsTable; import org.apache.iotdb.commons.schema.template.Template; @@ -40,6 +41,7 @@ import org.apache.iotdb.confignode.consensus.response.template.TemplateSetInfoResp; import org.apache.iotdb.confignode.rpc.thrift.TDatabaseSchema; import org.apache.iotdb.db.schemaengine.template.TemplateInternalRPCUtil; +import org.apache.iotdb.rpc.TSStatusCode; import org.apache.tsfile.enums.TSDataType; import org.apache.tsfile.external.commons.io.FileUtils; @@ -162,6 +164,21 @@ public void testTableStatisticsRollbackAndDatabaseRecreation() { Assert.assertEquals(0, statistics.getBaseTableNum(database)); } + @Test + public void testDatabasePathWithEmptyNodeIsInvalid() throws MetadataException { + clusterSchemaInfo.isDatabaseNameValid("root.database", false); + clusterSchemaInfo.isDatabaseNameValid("database", true); + + for (final String database : Arrays.asList("", "root.", "root..database", "root.database.")) { + try { + clusterSchemaInfo.isDatabaseNameValid(database, database.isEmpty()); + Assert.fail("Expected IllegalPathException for database: " + database); + } catch (final IllegalPathException e) { + Assert.assertEquals(TSStatusCode.ILLEGAL_PATH.getStatusCode(), e.getErrorCode()); + } + } + } + @Test public void testSetTemplate() throws IllegalPathException { String templateName = "template_name";