Skip to content

fix: bounded retry for TransferPage write to prevent DN OOM under IO faults - #24337

Merged
mergify[bot] merged 8 commits into
matrixorigin:3.0-devfrom
jiangxinmeng1:fix/dn-transfer-page-oom-24334
May 12, 2026
Merged

mergify[bot] merged 8 commits into
matrixorigin:3.0-devfrom
jiangxinmeng1:fix/dn-transfer-page-oom-24334

Conversation

@jiangxinmeng1

@jiangxinmeng1 jiangxinmeng1 commented May 11, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) does this PR fix or relate to?

Fixes #24334

What this PR does / why we need it:

Under IOChaos filesystem error injection, WriteTransferPage fails silently and still sets invalid paths on pages. The flusher keeps scheduling new flush tasks causing a 93 GB cumulative allocation storm that OOMs DN in 2 minutes.

Changes:

  1. Bounded retry with backoff (3 attempts, 100ms/200ms/400ms)
  2. Error propagation - paths only set on success
  3. Graceful degradation - pages kept in-memory on write failure

@jiangxinmeng1
jiangxinmeng1 requested a review from a user May 11, 2026 07:15
@qodo-code-review

Copy link
Copy Markdown
ⓘ You've reached your Qodo monthly free-tier limit. Reviews pause until next month — upgrade your plan to continue now, or link your paid account if you already have one.

Under IOChaos filesystem error injection, WriteTransferPage fails silently
and still sets invalid paths on pages, while the flusher keeps scheduling
new flushes — causing an allocation storm that OOMs DN in 2 minutes.

Changes:
- WriteTransferPage now retries up to 3 times with exponential backoff
  (100ms, 200ms, 400ms) before giving up
- WriteTransferPage returns an error; paths are only set on pages when
  the write actually succeeds
- Callers (flushTableTail, mergeObjects) log the failure but still keep
  pages in-memory so transfers continue to work without disk persistence
- Added unit tests with mock FS to verify retry behavior

Fixes matrixorigin#24334

Co-Authored-By: Claude Opus 4.6 <[email protected]>

@aunjgr aunjgr 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.

Direction is right — unbounded silent-failure retries were indeed the OOM vector — but the implementation has blockers.

Blocking

1. Doesn't compile against current main. The PR was authored against an older tree. On current main (pkg/vm/engine/tae/model/pages.go:427,450):

  • AddTransferPage(page, ioVector, bufs) takes 3 args
  • WriteTransferPage(ctx, fs, pages, ioVector, bufs) takes 5 args and calls ReleaseMarshalBufs(bufs) on its exit path

The PR's diff reverts to the older 2-arg / 4-arg signatures and drops the ReleaseMarshalBufs call. On rebase this means either the build breaks, or you reintroduce the pooled-buffer leak that was fixed upstream. Please rebase onto current main and preserve the bufs plumbing — including calling ReleaseMarshalBufs on every exit path of the new retry loop (success, exhausted, context-cancelled).

2. time.Sleep in the retry loop ignores context cancellation. On shutdown, ctx.Done() fires but the goroutine sleeps up to 400ms per attempt then re-enters fs.Write with a fresh 5s timeout. Replace with:

select {
case <-ctx.Done():
    return ctx.Err()
case <-time.After(transferPageWriteBaseWait << attempt):
}

3. PR description's worst-case delay is wrong. "3 attempts, 100/200/400ms" understates it. Real ceiling per call is 3 × 5s (fs.Write timeout) + 100ms + 200ms ≈ 15.3s. This runs on the commit pipeline (flushTableTail.go:PrepareCommit, mergeobjects.go:PrepareCommit), so under sustained IO faults commits stall for ~15s per batch. Worth stating plainly — 15s is still better than the 93GB storm, but the PR body should not advertise "700ms".

Correctness concern (not blocking, but worth addressing)

4. In-memory fallback has a data-loss window, not a memory leak. TransferTable.TTL() fires every 5s (pages.go:175-184) and clearMemory nils the hashmap even when path.Name == "". Readers after t+5s get ok=false from loadTable (pages.go:355-357). The pre-PR code had a bornTS += 1min hack to delay eviction; the new code drops it and flushTableTail.go:176-181 unconditionally stomps bornTS to now anyway. So under persistent IO faults, memory is bounded (good) but transfer lookups silently return empty from t+5s onward. Worth either preserving the bornTS extension on write failure, or documenting the 5s post-failure correctness window.

Test gaps

5. pages_test.go covers all-retries-fail, success-after-retry, success-first-try. Missing:

  • Mid-retry context cancellation (would catch finding #2 above).
  • Reader-side behavior after write failure — assert Transfer() with path.Name=="" returns ok=false without panicking through the hashmap-cleared path.
  • Consider parameterizing transferPageWriteBaseWait so tests don't eat 300ms of real sleeps.

Error propagation

addTransferPages/prepareTransferPage log the error and return nil, continuing the commit. Intentional ("graceful degradation"), fine — but make sure no downstream metric/log claims persistence success. Spot-checked nothing does, but worth a glance.

Please address #1–#3 before merge; #4–#5 are strong requests, not blockers.

jiangxinmeng1 and others added 2 commits May 12, 2026 09:45
…ory TTL

1. Replace time.Sleep with select on ctx.Done() so shutdown/cancellation
   is respected during retry backoff (review #2).
2. When WriteTransferPage fails, extend page bornTS by (diskTTL - ttl) so
   the in-memory hashmap survives ~5 minutes instead of being evicted after
   5s by the TTL sweeper. This preserves transfer correctness for the full
   diskTTL window under sustained IO faults (review #4).
3. Add test for context cancellation mid-retry.
4. Add test for Transfer() behavior after hashmap eviction with no path set.

Co-Authored-By: Claude Opus 4.6 <[email protected]>

@XuPeng-SH XuPeng-SH 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.

LGTM on the current head (41004b2). All blocking items from my earlier review are addressed:

  1. FileAlreadyExists → treated as success (lines 424-436), paths set correctly.
  2. Retry amplification in mergeobjects → writeFailed flag (line 121) fail-fasts the remaining dropped objects after first failure. Exactly what was suggested.
  3. Stale bornTS dance → now uses writeErr != nil / writeFailed to conditionally extend bornTS by diskTTL - TTL, giving in-memory pages survival time.
  4. Shift-backoff comment → present at line 397-398.
  5. Retry metrics → transfer_page_write_retry_total{succeeded|exhausted} counter registered and incremented at the right spots.

Also verified aunjgr's blockers are resolved:

  • Context-aware backoff (select on ctx.Done vs time.After) at lines 441-445.
  • TestWriteTransferPage_ContextCancellation covers early exit.
  • TestWriteTransferPage_FileAlreadyExistsOnRetry and _OnFirstAttempt cover that edge.
  • bornTS extension under write failure keeps pages alive for the full diskTTL window.

CI all green. The fix correctly bounds the retry-storm OOM vector while preserving in-memory fallback correctness during sustained IO faults.

@mergify

mergify Bot commented May 12, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-05-12 14:33 UTC · Rule: release-3.0
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-05-12 16:12 UTC · at aecbeb7995ef52f93f3dfdb9876d5a45889db628 · squash

This pull request spent 1 hour 38 minutes 44 seconds in the queue, including 55 minutes 17 seconds running CI.

Required conditions to merge
  • #approved-reviews-by >= 1 [🛡 GitHub branch protection]
  • #changes-requested-reviews-by = 0 [🛡 GitHub branch protection]
  • branch-protection-review-decision = APPROVED [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI (3.0) / Coverage
    • check-neutral = Matrixone Utils CI (3.0) / Coverage
    • check-skipped = Matrixone Utils CI (3.0) / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI (3.0) / SCA Test on Ubuntu/x86
    • check-neutral = Matrixone CI (3.0) / SCA Test on Ubuntu/x86
    • check-skipped = Matrixone CI (3.0) / SCA Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI (3.0) / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI (3.0) / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI (3.0) / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-neutral = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-skipped = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(Optimistic/PUSH)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-neutral = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-skipped = Matrixone Compose CI (3.0) / multi cn e2e bvt test docker compose(PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI (3.0) / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-neutral = Matrixone Standlone CI (3.0) / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-skipped = Matrixone Standlone CI (3.0) / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-neutral = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-skipped = Matrixone Standlone CI (3.0) / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Upgrade CI (3.0) / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-neutral = Matrixone Upgrade CI (3.0) / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-skipped = Matrixone Upgrade CI (3.0) / Compatibility Test With Target on Linux/x64(LAUNCH)

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants