Skip to content

Fix oversized audit logs for tree batch writes - #18345

Merged
HTHou merged 3 commits into
masterfrom
codex/limit-tree-audit-path-log
Jul 29, 2026
Merged

Fix oversized audit logs for tree batch writes#18345
HTHou merged 3 commits into
masterfrom
codex/limit-tree-audit-path-log

Conversation

@HTHou

@HTHou HTHou commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Description

Root cause

Tree-model batch inserts passed the complete distinct time-series path list to the object authentication audit logger. The object text is embedded in the root.__audit log field, so one audit record grew with every path in the batch. The root-user path also materialized the full path and device lists only for audit handling.

Changes

  • Reuse the existing path_log_max_size setting (default: 100) when formatting path lists for audit logs. Logs keep the first N distinct paths and append ... when truncated; small-list formatting is unchanged.
  • Add lazy path and device streams for insert statements, including rows of one device, multiple rows, tablets, and multiple tablets. Root-user audit handling no longer materializes complete flattened path/device lists.
  • Keep the complete distinct path list for non-root authorization checks and truncate only the audit representation, so paths after the log threshold cannot bypass permission checks.
  • Preserve the existing protection that rejects external writes to root.__audit, using a streaming first-match scan.

Impact and compatibility

This bounds audit-record growth by the configured path count without changing the audit schema or adding configuration. Authorization semantics are unchanged.

Validation

  • mvn spotless:apply -pl iotdb-core/datanode
  • mvn test -pl iotdb-core/datanode -Dtest=AuthorityCheckerTest,TreeAccessTest
    • 8 tests passed, 0 failures/errors/skips
    • Checkstyle and Spotless checks passed
  • Independent code review completed with no blocker/P1/P2 findings.

This PR has:

  • been self-reviewed.
  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold for code coverage.
  • added comments explaining the "why" and the intent of the code wherever it would not be obvious to an unfamiliar reader.

Key changed/added classes (or packages if there are too many classes) in this PR
  • AuthorityChecker
  • TreeAccessCheckVisitor
  • InsertBaseStatement
  • InsertRowsStatement
  • InsertMultiTabletsStatement

@HTHou
HTHou marked this pull request as ready for review July 29, 2026 06:29
@HTHou
HTHou requested a review from Copilot July 29, 2026 06:30

Copilot AI left a comment

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.

Pull request overview

This PR addresses oversized root.__audit records caused by embedding full distinct time-series path lists for tree-model batch inserts, by truncating the audit representation to the configured path_log_max_size while keeping full path lists for authorization checks and making insert-path/device enumeration lazy to avoid unnecessary materialization.

Changes:

  • Add AuthorityChecker.getPathListStringForLog(...) to format path lists for audit/error logging with a configurable truncation threshold.
  • Introduce lazy getPathsStream() / getDevicePathsStream() on insert statements and update tree-model access checking to use them for audit handling.
  • Add/extend unit tests covering truncation behavior, laziness, and ensuring permission checks are not affected by the log truncation setting.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/auth/AuthorityChecker.java Adds helper for bounded path-list formatting for log/audit strings.
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/security/TreeAccessCheckVisitor.java Uses bounded formatting for audit logging; switches audit DB protection and root-user audit logging to stream-based path/device enumeration.
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/statement/crud/InsertBaseStatement.java Adds default lazy streams for paths and device paths derived from devicePath/measurements.
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/statement/crud/InsertRowsStatement.java Implements stream-based paths/device-paths for batch row inserts.
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/statement/crud/InsertMultiTabletsStatement.java Implements stream-based paths/device-paths for multi-tablet inserts.
iotdb-core/datanode/src/test/java/org/apache/iotdb/db/auth/AuthorityCheckerTest.java Adds tests for truncation formatting and stream laziness behavior.
iotdb-core/datanode/src/test/java/org/apache/iotdb/db/auth/TreeAccessTest.java Adds test ensuring path_log_max_size does not affect permission checks.
Comments suppressed due to low confidence (1)

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/statement/crud/InsertBaseStatement.java:220

  • getDevicePathsStream() returns Stream.of(devicePath), which will include a null element if devicePath is unset. Downstream callers (e.g., Audit.includeByAuditTreeDB) are not null-safe and can NPE. Prefer returning Stream.empty() when devicePath is null.
  public Stream<PartialPath> getDevicePathsStream() {
    return Stream.of(devicePath);
  }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
Image C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Image Catch issues before they fail your Quality Gate with our IDE extension Image SonarQube for IDE

@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 46.34146% with 22 lines in your changes missing coverage. Please review.
✅ Project coverage is 43.32%. Comparing base (4861027) to head (c7c1ff1).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...an/relational/security/TreeAccessCheckVisitor.java 5.88% 16 Missing ⚠️
...ngine/plan/statement/crud/InsertBaseStatement.java 90.00% 2 Missing ⚠️
...an/statement/crud/InsertMultiTabletsStatement.java 0.00% 2 Missing ⚠️
...ngine/plan/statement/crud/InsertRowsStatement.java 0.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #18345      +/-   ##
============================================
+ Coverage     43.14%   43.32%   +0.18%     
  Complexity      374      374              
============================================
  Files          5364     5364              
  Lines        382623   382659      +36     
  Branches      49749    49755       +6     
============================================
+ Hits         165077   165795     +718     
+ Misses       217546   216864     -682     

☔ View full report in Codecov by Harness.
📢 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.

@HTHou
HTHou merged commit f39d0e9 into master Jul 29, 2026
43 of 44 checks passed
@HTHou
HTHou deleted the codex/limit-tree-audit-path-log branch July 29, 2026 08:27
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.

2 participants