Skip to content

Optimize subscription acknowledgement and WAL prefetching - #18845

Merged
jt2594838 merged 6 commits into
masterfrom
fix/subscription-wal-prefetch-hotspots
Nov 20, 2026
Merged

jt2594838 merged 6 commits into
masterfrom
fix/subscription-wal-prefetch-hotspots

Conversation

@Caideyipi

@Caideyipi Caideyipi commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Move writer-progress commits and WAL retention refresh out of the inFlightEvents.compute callback. Remove the exact event only after a successful commit so a failed commit remains retryable.
  • Pre-size per-entry writer-progress lists when deserializing WAL metadata.
  • Estimate tablet payload size during conversion and reuse it for response chunking and memory-block allocation. Preserve tree projection and tag/column pruning, recalculating only when the final tablet references differ.
  • Maintain writer heads incrementally in a priority queue and rebuild the frontier when safe-frontier versions, active writer state, or ordering mode changes. Provide versioned safe-frontier snapshots to detect updates.

Validation

  • Focused consensus and datanode tests: 88 passed, 0 failures, 0 errors, 0 skipped.
  • Spotless formatting passed for the consensus and datanode modules.

Frontier microbenchmark

A standalone JVM microbenchmark compared rebuilding the writer frontier for each update with incremental priority-queue updates. It ran 20,000 frontier selection/update operations per round, with 3 warm-up rounds and 7 measured rounds; values below are median ns/op (Windows 11, JDK 17.0.15, Intel Core i9-13900H).

Active writers Rebuild frontier Incremental update Speedup
1 45.3 ns/op 17.4 ns/op 2.60x
8 110.7 ns/op 31.0 ns/op 3.57x
32 390.6 ns/op 50.1 ns/op 7.80x
64 632.6 ns/op 49.8 ns/op 12.70x

This measures frontier bookkeeping only; it is not end-to-end subscription throughput. Full cluster performance measurements were not rerun.

@codecov

codecov Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 12.60870% with 201 lines in your changes missing coverage. Please review.
✅ Project coverage is 49.28%. Comparing base (52b42d3) to head (49a933f).

Files with missing lines Patch % Lines
...on/broker/consensus/ConsensusPrefetchingQueue.java 0.00% 138 Missing ⚠️
.../event/batch/SubscriptionPipeTabletEventBatch.java 0.00% 55 Missing ⚠️
...vent/response/SubscriptionEventTabletResponse.java 0.00% 7 Missing ⚠️
...iotdb/consensus/iot/WriterSafeFrontierTracker.java 95.45% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #18845      +/-   ##
============================================
- Coverage     49.30%   49.28%   -0.03%     
  Complexity      717      717              
============================================
  Files          5648     5648              
  Lines        417020   417173     +153     
  Branches      55108    55145      +37     
============================================
- Hits         205608   205598      -10     
- Misses       211412   211575     +163     

☔ 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.

…l-prefetch-hotspots

# Conflicts:
#	iotdb-core/datanode/src/main/java/org/apache/iotdb/db/subscription/broker/consensus/ConsensusPrefetchingQueue.java
@Caideyipi

Copy link
Copy Markdown
Collaborator Author

Self-review passed. I fixed V2 WAL metadata deserialization preallocation and corrected ACK cleanup ordering so event cleanup follows the in-flight map lock order, while the potentially slow WAL retention refresh remains outside the map callback. Targeted tests passed: ConsensusPrefetchingQueueTest (53) and WALMetaDataV3CompatibilityTest (6).

@Caideyipi
Caideyipi marked this pull request as draft November 19, 2026 06:34
@Caideyipi Caideyipi changed the title Optimize subscription WAL acknowledgement path Optimize subscription tablet sizing and WAL prefetch ordering Nov 19, 2026
@Caideyipi

Copy link
Copy Markdown
Collaborator Author

Review Summary

  • Finding: An initial direct size handoff could bypass tree projection and tag/column pruning on this branch.
  • Fix: Preserve the existing transformation path and reuse the estimate only while tablet references match; recalculate after filtering or projection changes them.
  • Verification: 73 focused consensus and datanode tests passed with no failures, errors, or skips. Spotless passed. Full cluster performance measurements were not rerun.
  • Reviewed base: abef0a8c9da3f2e187d82f8bc3a53c91df1d6aa3.
  • Final local commit: 279f79d5af5ba1f700f69f3861f0f4ba65df8a5b.
  • Confirmed remote branch and PR head: 279f79d5af5ba1f700f69f3861f0f4ba65df8a5b.
  • Status: The PR remains Draft pending a fresh independent review.

@Caideyipi Caideyipi changed the title Optimize subscription tablet sizing and WAL prefetch ordering Optimize subscription acknowledgement and WAL prefetching Nov 19, 2026
…r-sync-20261119

# Conflicts:
#	iotdb-core/datanode/src/main/java/org/apache/iotdb/db/subscription/broker/consensus/ConsensusPrefetchingQueue.java
@Caideyipi

Copy link
Copy Markdown
Collaborator Author

Master sync and validation update

  • Merged origin/master at 52b42d310b3758734f8f131c8cfea55fedd42808; the PR is mergeable against that base.
  • Resolved the ConsensusPrefetchingQueue conflict and made the recycle poison-event test deterministic.
  • Spotless passed; the focused consensus and datanode tests passed: 88 tests, 0 failures, 0 errors, 0 skipped.
  • Added a frontier-bookkeeping microbenchmark comparison to the PR description; it is not end-to-end throughput, and cluster performance tests were not rerun.
  • Final local and confirmed remote head: 49a933fdf0a98742c8952c96189dba22abb39438. The reviewed scope in this update is the master sync and its focused test verification; a fresh independent review of the full final diff remains pending. The PR stays Draft.

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

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

See analysis details on SonarQube Cloud

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

@Caideyipi
Caideyipi marked this pull request as ready for review November 19, 2026 10:54
@jt2594838
jt2594838 merged commit 86b8295 into master Nov 20, 2026
39 of 42 checks passed
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