Skip to content

feat(append): support write-buffer spill for append-only tables - #614

Merged
lxy-9602 merged 1 commit into
apache:mainfrom
SteNicholas:PAIMON-606
Dec 4, 2026
Merged

lxy-9602 merged 1 commit into
apache:mainfrom
SteNicholas:PAIMON-606

Conversation

@SteNicholas

@SteNicholas SteNicholas commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

Purpose

Linked issue: close #606

Support write buffers and spilling for append-only tables in Paimon C++, following Paimon Java's write-buffer-for-append and write-max-writers-to-spill. Append-only writers sent every batch straight to a data file writer and reported no memory to the write memory manager, so many concurrent writers, e.g. a batch insert into many partitions, could run out of memory without any way to spill.

  • Buffer written batches in an AppendWriteBuffer that reports the size of the Arrow buffers they reference to the write memory manager, spills them to temporary Arrow IPC files under memory pressure, written and read with the threads set by WriteContextBuilder::SetWriteBufferSpillThreadNumber(), and replays them in write order on flush.
  • Flush data files instead of spilling when the buffer is not spillable, the spill directory cannot be created, or its spill files reach write-buffer-spill.max-disk-size.
  • Once the active writers reach write-max-writers-to-spill, switch existing and future writers to spillable buffers before creating the next one. As in Paimon Java's toBufferedWriter(), a writer without a buffer closes its data files, reads their rows back into the new buffer ahead of later rows, and deletes the files, even if reading them back fails. A writer that already has a buffer keeps its rows and starts spilling. Skip real-time writes, writes without a usable temporary directory, and writes with BLOBs in dedicated .blob files, which also bypass the write buffer; BLOB fields stored inline are buffered and can switch.
  • Count each batch read back toward the shared write-buffer-size, so the write memory manager spills or flushes the largest writers during the switch instead of letting every switched writer keep nearly write-buffer-size of rows until the next write, much as Paimon Java's shared memory pool bounds toBufferedWriter().
  • Keep the buffered rows after a failed replay, and fail a writer once rows it accepted can no longer be committed exactly once, e.g. when a spill fails or closing or reading back its data files fails during a switch, so retries neither duplicate nor lose rows.
  • Delete spill files once their rows are flushed or the writer closes, retrying failed deletes, and on close delete the data files flushed but never returned by PrepareCommit().

With dedicated VECTOR storage, the read-back can return one logical row as two partial rows, as in Paimon Java. A TODO in AppendOnlyFileStoreWrite::CreateWriter() defers the fix until the Java one is merged, to keep both implementations aligned.

Tests

  • AppendWriteBuffer tests for in-memory buffering, enabling spill, spill and replay in write order with and without spill threads and with rows that are null at the top level, spill files of another schema, the disk budget, and cleanup of failed spills and on destruction.
  • AppendOnlyWriter tests for spill and replay on commit, memory accounting of imported slices, flushing when the buffer cannot spill or the disk budget is used up, and retries after failed replays, data file closes and compaction syncs, failed spills, BLOB inline field validation with a buffer, and cleanup on close.
  • AppendOnlyWriter tests for the switch to a spillable buffer: reusing an existing buffer, reading the rows already written back into the buffer and deleting their files, flushing them by spilling, by writing data files or through the memory check called after each batch read back, failing the writer and deleting the files when opening, reading or the memory check fails, and keeping direct writes without a reader.
  • AppendOnlyFileStoreWrite tests for switching at a custom and the default threshold, with and without write-buffer-for-append and a usable temporary directory, across file formats and shared shredding, leaving only committed files, the write buffer size shared across buckets with and without spill threads and by the rows read back during a switch, BLOB fields, real-time writes and failed switches.
  • CoreOptions tests for the defaults and parsing of the new options.

API and Format

  • Add write-buffer-for-append, defaulting to false, and write-max-writers-to-spill, defaulting to 10, and document that write-buffer-size is shared by the write buffers of one write for append-only tables.
  • Note on FileStoreWrite::Write() that an I/O error may leave an append-only writer with write buffers unable to commit the rows it accepted, so the write must be recreated.
  • Spill files are temporary; the storage format is unchanged.

Documentation

Yes. docs/source/user_guide/append_only_table.rst covers the options, memory accounting, spilling and its threads, the switch to spillable buffers and how it reads written rows back within the shared write-buffer-size, its exclusions, cleanup and failure handling.

Generative AI tooling

Generated-by: Claude Code (Claude Opus 5.5)

🤖 Generated with Claude Code

@SteNicholas
SteNicholas force-pushed the PAIMON-606 branch 2 times, most recently from 810ac91 to 1558e63 Compare December 2, 2026 15:22
@SteNicholas
SteNicholas requested a review from zjw1111 December 3, 2026 17:39
@SteNicholas
SteNicholas force-pushed the PAIMON-606 branch 4 times, most recently from 7a8cc8a to e64b790 Compare December 4, 2026 07:24

@zjw1111 zjw1111 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Append-only writers sent every batch straight to a data file writer and
reported no memory to the write memory manager, so many concurrent
writers, e.g. a batch insert into many partitions, could run out of
memory without any way to spill.

- Add `write-buffer-for-append` and `write-max-writers-to-spill`, as in
  Paimon Java, defaulting to false and 10.
- Add AppendWriteBuffer to keep written batches in memory, report the
  size of the Arrow buffers they reference to the write memory manager,
  spill them to temporary Arrow IPC files under memory pressure, with
  the threads set by SetWriteBufferSpillThreadNumber(), and replay them
  in write order on flush.
- Let AppendOnlyWriter buffer batches with `write-buffer-for-append`,
  spilling only with `write-buffer-spillable` and a temporary
  directory, and flush data files instead when it cannot spill, its
  spill directory cannot be created, or its spill files reach
  `write-buffer-spill.max-disk-size`.
- Once the active writers reach `write-max-writers-to-spill`, switch
  existing and future writers to spillable buffers before creating the
  next one, except for real-time writes, writes without a usable
  temporary directory, and writes with BLOBs in dedicated .blob files,
  which also bypass the write buffer. As in Paimon Java, a writer
  without a buffer closes its data files, reads their rows back into
  the new buffer ahead of later rows, and deletes the files, even if
  reading them back fails.
- Count each batch read back toward the shared `write-buffer-size`, so
  the write memory manager spills or flushes the largest writers during
  the switch instead of letting every switched writer keep nearly
  `write-buffer-size` of rows.
- Validate BLOB inline fields of buffered batches on write.
- Keep the buffered rows and discard the partial data files of a failed
  replay, and track flushed data files before the buffer drops their
  rows, so a retry neither duplicates nor loses rows.
- Fail a writer once rows it accepted can no longer be committed
  exactly once, e.g. when a spill fails or closing or reading back its
  data files fails during a switch, so later writes and commits return
  the error.
- Delete spill files once their rows are flushed or the writer closes,
  retrying failed deletes, and on close delete the data files flushed
  but never returned by PrepareCommit().
- Add tests for AppendWriteBuffer, and extend the AppendOnlyWriter and
  AppendOnlyFileStoreWrite tests to cover spill and replay order, the
  shared `write-buffer-size`, the switch and its read-back, the spill
  disk budget, failures and cleanup.
- Document the write buffer options, memory accounting, failure
  handling and cleanup in the append-only table user guide.

@lxy-9602 lxy-9602 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@lxy-9602
lxy-9602 merged commit 57faabc into apache:main Dec 4, 2026
31 of 32 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.

[Feature] Support append-only write-buffer spill

3 participants