This is an automated email from the ASF dual-hosted git repository.
jt2594838 pushed a commit to branch dev/1.3
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/dev/1.3 by this push:
new 2f36c374f7c Reject duplicate schema region IDs during recovery
(#18754) (#18775)
2f36c374f7c is described below
commit 2f36c374f7c7e3842e6b615df43dd78446fea621
Author: Caideyipi <[email protected]>
AuthorDate: Wed Sep 30 16:09:42 2026 +0800
Reject duplicate schema region IDs during recovery (#18754) (#18775)
(cherry picked from commit daf9dd8d77132aa35e7dd1414a1e804ae6d7eb2a)
---
.../iotdb/db/i18n/DataNodeSchemaMessages.java | 29 +++++++++++
.../iotdb/db/i18n/DataNodeSchemaMessages.java | 29 +++++++++++
.../apache/iotdb/db/schemaengine/SchemaEngine.java | 26 +++++++++-
.../iotdb/db/schemaengine/SchemaEngineTest.java | 57 ++++++++++++++++++++++
4 files changed, 139 insertions(+), 2 deletions(-)
diff --git
a/iotdb-core/datanode/src/main/i18n/en/org/apache/iotdb/db/i18n/DataNodeSchemaMessages.java
b/iotdb-core/datanode/src/main/i18n/en/org/apache/iotdb/db/i18n/DataNodeSchemaMessages.java
new file mode 100644
index 00000000000..df31f7e084d
--- /dev/null
+++
b/iotdb-core/datanode/src/main/i18n/en/org/apache/iotdb/db/i18n/DataNodeSchemaMessages.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.db.i18n;
+
+public final class DataNodeSchemaMessages {
+
+ private DataNodeSchemaMessages() {}
+
+ public static final String
+
EXCEPTION_CANNOT_RECOVER_DUPLICATED_SCHEMAREGION_ARG_FOUND_IN_DATABASES_ARG_AND_ARG_D9F60E05
=
+ "Cannot recover duplicated SchemaRegion [%s] found in databases [%s]
and [%s].";
+}
diff --git
a/iotdb-core/datanode/src/main/i18n/zh/org/apache/iotdb/db/i18n/DataNodeSchemaMessages.java
b/iotdb-core/datanode/src/main/i18n/zh/org/apache/iotdb/db/i18n/DataNodeSchemaMessages.java
new file mode 100644
index 00000000000..5fd43c669fc
--- /dev/null
+++
b/iotdb-core/datanode/src/main/i18n/zh/org/apache/iotdb/db/i18n/DataNodeSchemaMessages.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.db.i18n;
+
+public final class DataNodeSchemaMessages {
+
+ private DataNodeSchemaMessages() {}
+
+ public static final String
+
EXCEPTION_CANNOT_RECOVER_DUPLICATED_SCHEMAREGION_ARG_FOUND_IN_DATABASES_ARG_AND_ARG_D9F60E05
=
+ "无法恢复重复的 SchemaRegion [%s],其同时存在于数据库 [%s] 和 [%s] 中。";
+}
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/SchemaEngine.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/SchemaEngine.java
index dad19bbdfde..504eed7b904 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/SchemaEngine.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/SchemaEngine.java
@@ -34,6 +34,7 @@ import org.apache.iotdb.consensus.ConsensusFactory;
import org.apache.iotdb.db.conf.IoTDBConfig;
import org.apache.iotdb.db.conf.IoTDBDescriptor;
import org.apache.iotdb.db.consensus.SchemaRegionConsensusImpl;
+import org.apache.iotdb.db.i18n.DataNodeSchemaMessages;
import org.apache.iotdb.db.schemaengine.metric.ISchemaRegionMetric;
import org.apache.iotdb.db.schemaengine.metric.SchemaMetricManager;
import org.apache.iotdb.db.schemaengine.rescon.CachedSchemaEngineStatistics;
@@ -201,7 +202,8 @@ public class SchemaEngine {
@SuppressWarnings("java:S2142")
private void initSchemaRegion() {
// recover SchemaRegion concurrently
- Map<String, List<SchemaRegionId>> localSchemaRegionInfo =
getLocalSchemaRegionInfo();
+ final Map<String, List<SchemaRegionId>> localSchemaRegionInfo =
getLocalSchemaRegionInfo();
+ validateNoDuplicatedSchemaRegionId(localSchemaRegionInfo);
final ExecutorService schemaRegionRecoverPools =
IoTDBThreadPoolFactory.newFixedThreadPool(
Runtime.getRuntime().availableProcessors(),
@@ -232,6 +234,27 @@ public class SchemaEngine {
schemaRegionRecoverPools.shutdown();
}
+ static void validateNoDuplicatedSchemaRegionId(
+ final Map<String, List<SchemaRegionId>> localSchemaRegionInfo) {
+ final Map<SchemaRegionId, String> databaseBySchemaRegionId = new
HashMap<>();
+ localSchemaRegionInfo.forEach(
+ (database, schemaRegionIds) -> {
+ for (final SchemaRegionId schemaRegionId : schemaRegionIds) {
+ final String existingDatabase =
+ databaseBySchemaRegionId.putIfAbsent(schemaRegionId, database);
+ if (existingDatabase != null) {
+ throw new IllegalStateException(
+ String.format(
+ DataNodeSchemaMessages
+
.EXCEPTION_CANNOT_RECOVER_DUPLICATED_SCHEMAREGION_ARG_FOUND_IN_DATABASES_ARG_AND_ARG_D9F60E05,
+ schemaRegionId,
+ existingDatabase,
+ database));
+ }
+ }
+ });
+ }
+
private void initSchemaEngineStatistics() {
if
(CommonDescriptor.getInstance().getConfig().getSchemaEngineMode().equals("Memory"))
{
schemaEngineStatistics = new MemSchemaEngineStatistics();
@@ -310,7 +333,6 @@ public class SchemaEngine {
return () -> {
long timeRecord = System.currentTimeMillis();
try {
- // TODO: handle duplicated regionId across different database
ISchemaRegion schemaRegion =
createSchemaRegionWithoutExistenceCheck(storageGroup,
schemaRegionId);
timeRecord = System.currentTimeMillis() - timeRecord;
diff --git
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/schemaengine/SchemaEngineTest.java
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/schemaengine/SchemaEngineTest.java
new file mode 100644
index 00000000000..d4e55034f9d
--- /dev/null
+++
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/schemaengine/SchemaEngineTest.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iotdb.db.schemaengine;
+
+import org.apache.iotdb.commons.consensus.SchemaRegionId;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class SchemaEngineTest {
+
+ @Test
+ public void uniqueSchemaRegionIdsPassRecoveryValidation() {
+ final Map<String, List<SchemaRegionId>> localSchemaRegionInfo = new
HashMap<>();
+ localSchemaRegionInfo.put(
+ "root.db1", Arrays.asList(new SchemaRegionId(0), new
SchemaRegionId(1)));
+ localSchemaRegionInfo.put("root.db2", Collections.singletonList(new
SchemaRegionId(2)));
+
+ SchemaEngine.validateNoDuplicatedSchemaRegionId(localSchemaRegionInfo);
+ }
+
+ @Test
+ public void duplicatedSchemaRegionIdIsRejectedBeforeRecovery() {
+ final Map<String, List<SchemaRegionId>> localSchemaRegionInfo = new
HashMap<>();
+ localSchemaRegionInfo.put("root.db1", Collections.singletonList(new
SchemaRegionId(0)));
+ localSchemaRegionInfo.put("root.db2", Collections.singletonList(new
SchemaRegionId(0)));
+
+ final IllegalStateException exception =
+ Assert.assertThrows(
+ IllegalStateException.class,
+ () ->
SchemaEngine.validateNoDuplicatedSchemaRegionId(localSchemaRegionInfo));
+ Assert.assertTrue(exception.getMessage().contains("root.db1"));
+ Assert.assertTrue(exception.getMessage().contains("root.db2"));
+ }
+}