Skip to content

Added flags to mark whether a device has device descendants to optimize query like select xx from xxx.**#17672

Open
Caideyipi wants to merge 3 commits into
masterfrom
device-flag-query
Open

Added flags to mark whether a device has device descendants to optimize query like select xx from xxx.**#17672
Caideyipi wants to merge 3 commits into
masterfrom
device-flag-query

Conversation

@Caideyipi
Copy link
Copy Markdown
Collaborator

Description

As the title said.


This PR has:

  • been self-reviewed.
    • concurrent read
    • concurrent write
    • concurrent read and write
  • added documentation for new or modified features or behaviors.
  • added Javadocs for most classes and all non-trivial methods.
  • added or updated version, license, or notice information
  • added comments explaining the "why" and the intent of the code wherever would not be obvious
    for an unfamiliar reader.
  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold
    for code coverage.
  • added integration tests.
  • been tested in a test IoTDB cluster.

Key changed/added classes (or packages if there are too many classes) in this PR

@codecov
Copy link
Copy Markdown

codecov Bot commented May 14, 2026

Codecov Report

❌ Patch coverage is 93.85475% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 40.43%. Comparing base (556cd66) to head (49071fd).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
...engine/schemaregion/mtree/traverser/Traverser.java 90.56% 5 Missing ⚠️
...aregion/mtree/impl/mem/MTreeBelowSGMemoryImpl.java 95.00% 2 Missing ⚠️
...impl/pbtree/mnode/impl/CachedMeasurementMNode.java 66.66% 2 Missing ⚠️
...gion/mtree/impl/pbtree/MTreeBelowSGCachedImpl.java 97.67% 1 Missing ⚠️
...pl/pbtree/mnode/impl/CachedAboveDatabaseMNode.java 83.33% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #17672      +/-   ##
============================================
+ Coverage     40.38%   40.43%   +0.05%     
  Complexity     2574     2574              
============================================
  Files          5178     5178              
  Lines        349134   349328     +194     
  Branches      44665    44697      +32     
============================================
+ Hits         140988   141252     +264     
+ Misses       208146   208076      -70     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment on lines +228 to +229
final IMNodeIterator<IMemMNode> iterator = store.getChildrenIterator(node);
try {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try-with-resource?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. IMNodeIterator now extends AutoCloseable, and the newly added child-iterator scans use try-with-resources in memory, cached, and traverser paths.

Copy link
Copy Markdown
Member

@luoluoyuyu luoluoyuyu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review summary

Adds hasDeviceDescendant flags on schema nodes and maintains them when creating devices and when deleting empty internal nodes. This should speed up queries that need to know if a prefix has device descendants.

Please fix CI failures and add tests for flag updates on delete/move paths touched in this PR.

entityMNode = device.getAsDeviceMNode();
} else {
entityMNode = store.setToEntity(device);
entityMNode = setToEntityAndUpdateFlags(device);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setToEntityAndUpdateFlags marks ancestors when a node becomes a device. Please confirm refreshAncestorsHavingDeviceDescendant on deleteEmptyInternalMNode keeps flags correct when the last device under a prefix is removed.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed and covered with tests. The delete refresh recomputes ancestors from children, so when the last device under one prefix is removed, higher ancestors stay true if another sibling device subtree still exists and become false only after the last remaining device subtree is removed. I extended both memory and cached MTree tests for that case, and added memory-mode table-device drop coverage as well.

@Caideyipi
Copy link
Copy Markdown
Collaborator Author

Addressed the review comments in commit 2a68c38:

  • Made IMNodeIterator AutoCloseable and converted the new iterator scans to try-with-resources.
  • Reduced the Sonar duplication from repeated flag delegate methods by moving the shared accessors to default methods on IMemMNode / ICachedMNode.
  • Added coverage for delete refresh correctness when one device subtree is removed while another sibling device subtree still exists, plus table-device drop coverage in memory mode.

Verification:

  • mvn -pl iotdb-core/datanode,iotdb-core/node-commons spotless:apply
  • MAVEN_OPTS=-Xmx768m mvn -Ddevelocity.off=true -Dcheckstyle.skip=true -Dspotless.check.skip=true -pl iotdb-core/node-commons,iotdb-core/datanode -Dtest=MTreeBelowSGMemoryImplTest,MTreeBelowSGCachedImplTest -DfailIfNoTests=false -Dsurefire.failIfNoSpecifiedTests=false test

For current CI: the latest failing Simple (17) job failed during �ctions/checkout with a GitHub TLS fetch error before build/test. The dual-tree-auto-basic failure is in IoTDBPipeLifeCycleIT.testLifeCycleLogMode, unrelated to this schema flag change.

@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants