Skip to content

[Storage] Cap the temporary flush memory estimate at the memtable size - #19108

Open
chrisdutz wants to merge 1 commit into
masterfrom
fix/flush-memory-estimate-cap
Open

chrisdutz wants to merge 1 commit into
masterfrom
fix/flush-memory-estimate-cap

Conversation

@chrisdutz

Copy link
Copy Markdown
Contributor

Description

MemTableFlushTask.syncFlushMemTable() reserves temporary memory for a flush and takes it out of
the MemTable budget (SystemInfo.reserveTemporaryMemoryForFlushing, since #18848; before that
applyTemporaryMemoryForFlushing with the same estimate):

memSize / seriesNumber * io_task_queue_size_for_flushing

The bounded IO queue holds up to io_task_queue_size_for_flushing (default 10) encoded series of
average size. With fewer series than queue slots the formula estimates more than the memtable
itself: a memtable with 3 series reserves 10/3 = 3.3 times its size. With a small MemTable budget
a single flush can then reserve more than the whole budget, so FLUSH_THRESHOLD and
REJECT_THRESHOLD become negative and the node rejects writes until the flush is done.

Measured with the same code in a downstream fork (standalone DataNode, 147.9 MB MemTable budget),
writing to one device with 3 series (flushes of about 52 MB):

largest reservation lowest reject threshold
before 174.5 MB -21.3 MB (rejecting)
after 52.4 MB 76.4 MB
before, 100 devices x 3 series (not affected) 1.7 MB 116.9 MB

The queue can never hold more than the memtable, so the estimate is now capped at memSize
when there are no more series than queue slots; with more series it is unchanged.

The estimate is moved into a small static method estimateTemporaryMemory(...) so that it can
be unit tested (FlushMemoryEstimateTest).

Tests

  • New FlushMemoryEstimateTest (fails before the change: 173.3 MB estimated for a 52 MB memtable
    with 3 series).
  • MemTableFlushTaskTest, TsFileProcessorTest, SystemInfoTest, DataRegionTest: 106 tests
    pass; spotless:check passes.

🤖 Generated with Claude Code

@codecov

codecov Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 48.46%. Comparing base (4b80fa5) to head (506a770).
⚠️ Report is 8 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master   #19108      +/-   ##
============================================
+ Coverage     48.43%   48.46%   +0.03%     
  Complexity      635      635              
============================================
  Files          5572     5573       +1     
  Lines        412012   412098      +86     
  Branches      54309    54329      +20     
============================================
+ Hits         199556   199739     +183     
+ Misses       212456   212359      -97     

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

@chrisdutz

Copy link
Copy Markdown
Contributor Author

The failing SonarCloud quality gate (new_reliability_rating = 3) is not caused by this change: it comes from two bugs in recently merged pipe code and currently fails for every pull request. #19109 fixes them (its own SonarCloud gate passes); once it is merged, the gate here should pass on the next analysis.

@JackieTien97

Copy link
Copy Markdown
Contributor

@jt2594838 @HTHou plz take a look

A flush reserves memSize / seriesNumber * io_task_queue_size_for_flushing
and takes it out of the MemTable budget. With fewer series than queue slots
(default 10) the estimate exceeds the memtable itself: a memtable with 3
series reserved 3.3 times its size, more than the whole MemTable budget, so
the reject threshold became negative and writes were rejected.

The bounded IO queue can never hold more than the memtable, so the estimate
is now capped at memSize when there are no more series than queue slots.
With more series the estimate is unchanged.
@chrisdutz
chrisdutz force-pushed the fix/flush-memory-estimate-cap branch from 20b3655 to 506a770 Compare November 5, 2026 11:11
@sonarqubecloud

sonarqubecloud Bot commented Nov 5, 2026

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

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