refactor: extract WriteBuffer from MergeTreeWriter#206
Merged
zjw1111 merged 11 commits intoalibaba:mainfrom Apr 3, 2026
Merged
refactor: extract WriteBuffer from MergeTreeWriter#206zjw1111 merged 11 commits intoalibaba:mainfrom
zjw1111 merged 11 commits intoalibaba:mainfrom
Conversation
Extract batch buffering logic from MergeTreeWriter into a dedicated WriteBuffer class. WriteBuffer manages batch_vec_, row_kinds_vec_, and current_memory_in_bytes_, and provides Write() and Flush() methods. This is a pure internal refactoring that: - Does not change any external API or behavior - Prepares for future Spill-to-Disk functionality - Improves separation of concerns in MergeTreeWriter
There was a problem hiding this comment.
Pull request overview
Extracts MergeTreeWriter’s in-memory buffering and flush logic into a dedicated WriteBuffer abstraction and adds unit tests to validate flush behavior and memory estimation.
Changes:
- Introduces new
WriteBufferclass for buffering, flushing, and memory usage tracking. - Refactors
MergeTreeWriterto delegate buffering/flush responsibilities toWriteBuffer. - Adds focused tests for flush state reset, sequence advancement, row kind preservation, and memory estimation.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| src/paimon/core/mergetree/write_buffer.h | Adds the WriteBuffer API used by MergeTreeWriter. |
| src/paimon/core/mergetree/write_buffer.cpp | Implements buffering, flushing to in-memory readers, and memory estimation. |
| src/paimon/core/mergetree/write_buffer_test.cpp | Adds new unit tests for WriteBuffer flush semantics and memory estimation. |
| src/paimon/core/mergetree/merge_tree_writer.h | Replaces ad-hoc buffer state with a WriteBuffer member. |
| src/paimon/core/mergetree/merge_tree_writer.cpp | Delegates write buffering and flush reader creation to WriteBuffer. |
| src/paimon/core/mergetree/merge_tree_writer_test.cpp | Refactors batch creation helper and removes now-moved memory estimation tests. |
| src/paimon/CMakeLists.txt | Wires write_buffer.cpp and write_buffer_test.cpp into the build. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
lxy-9602
reviewed
Apr 2, 2026
lxy-9602
reviewed
Apr 2, 2026
lxy-9602
reviewed
Apr 2, 2026
lxy-9602
reviewed
Apr 2, 2026
lucasfang
reviewed
Apr 3, 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.
Purpose
Linked issue: #149
Refactor MergeTreeWriter by extracting the in-memory buffering logic into WriteBuffer. This moves buffered batch ingestion, memory tracking, and flush-to-reader preparation into a dedicated component, while keeping MergeTreeWriter focused on file writing and compaction orchestration.
Tests
TEST_F(WriteBufferTest.*)
TEST_F(CleanInteTest.TestOrphanFilesCleanWithIOException)
Existing unit and integration tests
API and Format
No API, storage format, or protocol changes.
Documentation
No.
Generative AI tooling
Generated-by: Aone Copilot(Claude-4.6-Opus) and GitHub Copilot(GPT-5.4)