Skip to content

Backport(v1.19): buffer: fix an enqueued unstaged file chunk being re-staged and flushed twice (#5517) - #5532

Merged
Watson1978 merged 1 commit into
v1.19from
backport-to-v1.19/pr5517
Oct 11, 2026
Merged

Watson1978 merged 1 commit into
v1.19from
backport-to-v1.19/pr5517

Conversation

@github-actions

Copy link
Copy Markdown

Which issue(s) this PR fixes:
Backport #5517
Fixes #4662

What this PR does / why we need it:
FileChunk#enqueued! and FileSingleChunk#enqueued! did nothing for an unstaged chunk, so a chunk enqueued by Buffer#enqueue_unstaged_chunk stayed :unstaged and Buffer#write re-staged it, leaving the same chunk object in both @queue and @stage. The second flush of that object produced closed stream and ENOENT, and the buffer size gauges leaked (see #4662 (comment)). This change marks an unstaged chunk as :queued and renames its files to the queued path in enqueued!, and makes Buffer#write warn instead of raise when enqueueing a chunk fails, because the chunk is already queued and a chunk left unstaged there would be purged with its committed records. A chunk whose rename failed keeps its staged file name, so FileSingleBuffer#resume now enqueues a second staged chunk file with the same metadata as FileBuffer#resume already does, and file_rename reopens the old file when the rename fails on Windows.

Docs Changes:
None

Release Note:

  • buffer: fix an enqueued unstaged file chunk being re-staged and flushed twice, which caused closed stream / ENOENT errors and leaked buffer size gauges

…ed twice (#5517)

**Which issue(s) this PR fixes**:
Fixes #4662

**What this PR does / why we need it**:
`FileChunk#enqueued!` and `FileSingleChunk#enqueued!` did nothing for an
unstaged chunk, so a chunk enqueued by `Buffer#enqueue_unstaged_chunk`
stayed `:unstaged` and `Buffer#write` re-staged it, leaving the same
chunk object in both `@queue` and `@stage`. The second flush of that
object produced `closed stream` and `ENOENT`, and the buffer size gauges
leaked (see
#4662 (comment)).
This change marks an unstaged chunk as `:queued` and renames its files
to the queued path in `enqueued!`, and makes `Buffer#write` warn instead
of raise when enqueueing a chunk fails, because the chunk is already
queued and a chunk left unstaged there would be purged with its
committed records. A chunk whose rename failed keeps its staged file
name, so `FileSingleBuffer#resume` now enqueues a second staged chunk
file with the same metadata as `FileBuffer#resume` already does, and
`file_rename` reopens the old file when the rename fails on Windows.

**Docs Changes**:
None

**Release Note**:
* buffer: fix an enqueued unstaged file chunk being re-staged and
flushed twice, which caused `closed stream` / `ENOENT` errors and leaked
buffer size gauges

Signed-off-by: Shizuo Fujita <fujita@clear-code.com>
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
@Watson1978 Watson1978 added this to the v1.19.5 milestone Oct 11, 2026
@Watson1978
Watson1978 merged commit c475b67 into v1.19 Oct 11, 2026
21 checks passed
@Watson1978
Watson1978 deleted the backport-to-v1.19/pr5517 branch October 11, 2026 05:21
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.

1 participant