Fix oversized audit logs for tree batch writes - #18345
Conversation
There was a problem hiding this comment.
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.
|
Codecov Report❌ Patch coverage is 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. 🚀 New features to boost your workflow:
|




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.__auditlogfield, 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
path_log_max_sizesetting (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.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/datanodemvn test -pl iotdb-core/datanode -Dtest=AuthorityCheckerTest,TreeAccessTestThis PR has:
Key changed/added classes (or packages if there are too many classes) in this PR
AuthorityCheckerTreeAccessCheckVisitorInsertBaseStatementInsertRowsStatementInsertMultiTabletsStatement