Repository navigation
Refactor write memory accounting into named memory blocks - #18848
Merged
jt2594838 merged 4 commits intoOct 21, 2026
Merged
Conversation
Caideyipi
reviewed
Oct 13, 2026
Caideyipi
left a comment
Collaborator
There was a problem hiding this comment.
Reviewed commit ef0d5bfa35c3 against the PR's merge base eb0e3f1f2080. I did not find an actionable regression introduced by this change.
The review covered row, mixed-row and split-tablet memory admission/WAL rollback; MemTable and metadata release; WAL snapshot format compatibility; idle-array accounting; and flush-worker failure/interruption cleanup.
Validation
89 focused tests passed:
- 59 DataNode tests across
WriteMemoryBlockTest,MemTableMemoryBlockTest,WriteMemoryLifecycleTest,PrimitiveArrayManagerTest,MemTableFlushTaskTest, andTsFileProcessorTest. - 3 tests in
ReadOnlyMemoryBlockTest. - 27 tests in
AlignedTVListTest.
git diff --check also passed.
Full-reactor test compilation could not complete because the local JVM failed to reserve native memory. The integration tests in this PR were not rerun as part of this review.
jt2594838
reviewed
Oct 15, 2026
jt2594838
approved these changes
Oct 15, 2026
Preserve explicit data-model handling and flush worker lifetime accounting. Adapt PR-only tests to the updated flush and memchunk APIs.
jt2594838
approved these changes
Oct 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Write-memory accounting is spread across MemTables, TsFileProcessors and DataRegions, requiring callers to update several counters together. This change introduces named, categorized owner blocks that propagate usage to their accounting scope and tie rollback/release to the owner's lifecycle.
Accounting and lifecycle
WriteMemoryBlockandWriteMemoryManagerfor MemTable arrays, Binary values, recovered totals, TsFile metadata and flush temporary reservations. Pending reservations count toward admission but become used MemTable memory only after admission succeeds. WAL failures roll back the admitted deltas.Array-pool accounting and hot paths
Count idle arrays by actual shallow size under the existing per-type queue locks. A new
ReadOnlyMemoryBlockexposes an exact snapshot to the existing memory-manager tree; readers acquire queue locks in a fixed order. This avoids an additional global atomic update on each array borrow/return.WriteMemoryBlockuses a monitor-guardedlong; region totals remain atomic. Zero-delta writes skip reservation creation while retaining pressure checks.SQL, configured memory limits, file/WAL formats and the existing admission policy are unchanged. Accounting follows write ownership, not total JVM heap liveness. New exception messages are provided in both English and Chinese.
Verification
Added 4 lifecycle integration tests, all passed in a real 1 ConfigNode + 1 DataNode environment using the repository’s fixtures, run through JUnitCore.
The tests cover:
Assertions check both query results and live database write-memory metrics, including memory charged by writes and released after flush or rejection.
Performance observations
Compared with
eb0e3f1f2080e34bf5593bfd1cf63b62ecdba2e0, using the same workload/configuration and three interleaved runs per version:Environment: shared Xeon Gold 6130 KVM host, 32 vCPUs, JDK 21, 1C1D/SimpleConsensus, ASYNC WAL, memory control enabled, 2 GiB DataNode heap, array size 64, MemTable threshold 32 MiB, compaction and timed flush disabled. Fixed per-writer warmup/measurement calls were 50k/100k for non-aligned Tablet, 125k/250k for aligned rows, and 20k/40k for aligned Tablet. Each run checked acknowledged row counts through queries after a final FLUSH.
These are controlled class-overlay comparisons, not two independent clean distribution builds. The throughput window excludes the final FLUSH; it does not measure synchronous durability throughput. Shared-host variability and existing QueryId waits affect single-row results. The repeated throughput regression observed during development did not recur in the final comparisons, but the latency increases above remain review considerations; these measurements do not establish a universal speedup.
This PR has:
Key changed/added classes
WriteMemoryBlock,WriteMemoryManager,AbstractMemTable,TsFileProcessor,DataRegionInfo,TsFileProcessorInfo,MemTableFlushTask,SystemInfo,MemoryControlledWALEntryQueue,PrimitiveArrayManager,ReadOnlyMemoryBlock,MemoryManager.