Conversation
ColinLeeo
requested review from
hongzhi-gao
and
a balanced review from Copilot
September 17, 2026 08:04
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Empty chunk groups can create invalid iterator state and undefined behavior during file close.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Optimizes C++ TsFile close and metadata-index generation for high-device-count workloads.
Changes:
- Enlarges write-stream pages to 16 KiB.
- Reduces metadata copying and sorting overhead.
- Builds per-table device indexes directly and adds regression tests.
File summaries
| File | Description |
|---|---|
cpp/src/common/tsfile_common.cc |
Reworks chunk metadata grouping and iteration. |
cpp/src/common/tsfile_common.h |
Simplifies iterator state and map aliases. |
cpp/src/file/tsfile_io_writer.cc |
Optimizes table/device index construction. |
cpp/src/file/tsfile_io_writer.h |
Increases write-stream page size. |
cpp/test/common/tsfile_common_test.cc |
Adds ordering and page-size regression tests. |
Review details
- Files reviewed: 5/5 changed files
- Comments generated: 1
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+86
to
91
| if (!device_exists) { | ||
| tsm_chunk_meta_info_.emplace_hint(device_pos, | ||
| chunk_group_meta->device_id_, | ||
| std::move(chunk_group_map)); | ||
| continue; | ||
| } |
Contributor
There was a problem hiding this comment.
Please skip empty chunk groups here and add a regression test for this case.
Contributor
|
LGTM |
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.
What is changed
This PR optimizes the C++ TsFile close/index-writing path for workloads with many devices and repeated flushes.
TsFileIOWriterwrite-stream pages from 512 B to 16 KiB to reduce small metadata writes.TSMIteratorto avoid mutating sourceChunkGroupMetalists, avoid unnecessary temporary list copies, skip sorting already ordered chunk metadata, and preserve recovery write ordering.lower_boundwith hint insertion for device index nodes.Benchmark
Workload: 10,000 devices × 100 batches, 1,000,000 physical ChunkGroups, 2,000,000 Chunks, 1,000,000 rows, C++ table writer, arm64 macOS.
close()medianThe generated file size remains unchanged at 159,940,628 bytes. The optimization targets close/index finalization; it does not change the flush policy or file format.
Verification
cmake -S cpp -B cpp/target/build -DCMAKE_BUILD_TYPE=Release -DBUILD_TEST=ONcmake --build cpp/target/build --target TsFile_Test -j4cpp/target/build/test/lib/TsFile_Testclang-format --dry-run --Werroron all changed C++ filesgit diff --checkThe branch is rebased onto the latest
origin/develop.