From e0585c3c067ff9e5fd472e7037a7329270f7ad2c Mon Sep 17 00:00:00 2001 From: Caideyipi <87789683+Caideyipi@users.noreply.github.com> Date: Mon, 12 Oct 2026 13:57:23 +0800 Subject: [PATCH] Fix schema existence check fail-open behavior (#18755) * Fix schema existence check fail-open behavior * Fix PR 18755 encoding and compilation issues (cherry picked from commit 0f91bed7544464f3fcb7f46d3bdf8c50669ed9b8) --- .../db/schemaengine/schemaregion/ISchemaRegion.java | 10 ++++------ .../schemaregion/impl/SchemaRegionMemoryImpl.java | 10 +++------- .../schemaregion/impl/SchemaRegionPBTreeImpl.java | 10 +++------- .../mtree/impl/pbtree/MTreeBelowSGCachedImpl.java | 4 +++- 4 files changed, 13 insertions(+), 21 deletions(-) diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/ISchemaRegion.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/ISchemaRegion.java index 7248fe260463a..0b1041d364630 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/ISchemaRegion.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/ISchemaRegion.java @@ -62,7 +62,7 @@ *

The interfaces are divided as following: * *

    - *
  1. Interfaces for initialization、recover and clear + *
  2. Interfaces for initialization, recover and clear *
  3. Interfaces for schema region Info query and operation *
  4. Interfaces for Timeseries operation *
  5. Interfaces for metadata info Query @@ -76,7 +76,7 @@ */ public interface ISchemaRegion { - // region Interfaces for initialization、recover and clear + // region Interfaces for initialization, recover and clear void init() throws MetadataException; /** clear all metadata components of this schemaRegion */ @@ -131,10 +131,8 @@ public interface ISchemaRegion { * @param aliasList a list of alias that you want to check * @return returns a map contains index of the measurements or alias that threw the exception, and * exception details. The exceptions describe whether the measurement or alias exists. For - * example, a MeasurementAlreadyExistException means this measurement exists. If there are - * exceptions during check, this may return an empty map, then all the measurements will be - * re-checked under consensus layer, which guarantees safety(Yet may cause unnecessary replay - * of raft log) + * example, a MeasurementAlreadyExistException means this measurement exists. An empty map + * means that no measurement exists and can be created. */ Map checkMeasurementExistence( PartialPath devicePath, List measurementList, List aliasList); diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/impl/SchemaRegionMemoryImpl.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/impl/SchemaRegionMemoryImpl.java index 0f6490eceb467..1c89a9b613b75 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/impl/SchemaRegionMemoryImpl.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/impl/SchemaRegionMemoryImpl.java @@ -125,7 +125,7 @@ *

    The codes are divided into the following code regions: * *

      - *
    1. Interfaces and Implementation for initialization、recover and clear + *
    2. Interfaces and Implementation for initialization, recover and clear *
    3. Interfaces and Implementation for schema region Info query and operation *
    4. Interfaces and Implementation for Timeseries operation *
    5. Interfaces for auto create device @@ -166,7 +166,7 @@ public class SchemaRegionMemoryImpl implements ISchemaRegion { private MTreeBelowSGMemoryImpl mtree; private TagManager tagManager; - // region Interfaces and Implementation of initialization、snapshot、recover and clear + // region Interfaces and Implementation of initialization, snapshot, recover and clear public SchemaRegionMemoryImpl(final ISchemaRegionParams schemaRegionParams) throws MetadataException { @@ -766,11 +766,7 @@ public void createAlignedTimeSeries(final ICreateAlignedTimeSeriesPlan plan) @Override public Map checkMeasurementExistence( PartialPath devicePath, List measurementList, List aliasList) { - try { - return mtree.checkMeasurementExistence(devicePath, measurementList, aliasList); - } catch (final Exception e) { - return Collections.emptyMap(); - } + return mtree.checkMeasurementExistence(devicePath, measurementList, aliasList); } @Override diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/impl/SchemaRegionPBTreeImpl.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/impl/SchemaRegionPBTreeImpl.java index 73bbce272e2fd..b78f570125a0a 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/impl/SchemaRegionPBTreeImpl.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/impl/SchemaRegionPBTreeImpl.java @@ -126,7 +126,7 @@ *

      The codes are divided into the following code regions: * *

        - *
      1. Interfaces and Implementation for initialization、recover and clear + *
      2. Interfaces and Implementation for initialization, recover and clear *
      3. Interfaces and Implementation for schema region Info query and operation *
      4. Interfaces and Implementation for Timeseries operation *
      5. Interfaces for auto create device @@ -169,7 +169,7 @@ public class SchemaRegionPBTreeImpl implements ISchemaRegion { private MTreeBelowSGCachedImpl mtree; private TagManager tagManager; - // region Interfaces and Implementation of initialization、snapshot、recover and clear + // region Interfaces and Implementation of initialization, snapshot, recover and clear public SchemaRegionPBTreeImpl(ISchemaRegionParams schemaRegionParams) throws MetadataException { storageGroupFullPath = schemaRegionParams.getDatabase().getFullPath(); @@ -850,11 +850,7 @@ public void createAlignedTimeSeries(final ICreateAlignedTimeSeriesPlan plan) @Override public Map checkMeasurementExistence( PartialPath devicePath, List measurementList, List aliasList) { - try { - return mtree.checkMeasurementExistence(devicePath, measurementList, aliasList); - } catch (final Exception e) { - return Collections.emptyMap(); - } + return mtree.checkMeasurementExistence(devicePath, measurementList, aliasList); } @Override diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/mtree/impl/pbtree/MTreeBelowSGCachedImpl.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/mtree/impl/pbtree/MTreeBelowSGCachedImpl.java index 829d242187e61..a326a9512d9bd 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/mtree/impl/pbtree/MTreeBelowSGCachedImpl.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/mtree/impl/pbtree/MTreeBelowSGCachedImpl.java @@ -591,8 +591,10 @@ public Map checkMeasurementExistence( ICachedMNode device; try { device = getNodeByPath(devicePath); - } catch (MetadataException e) { + } catch (PathNotExistException e) { return Collections.emptyMap(); + } catch (MetadataException e) { + return Collections.singletonMap(0, e); } try { if (!device.isDevice()) {