fix(cpp): flush pending data on writer close - #969
Merged
ColinLeeo merged 1 commit intoSep 24, 2026
Merged
Conversation
ColinLeeo
requested review from
hongzhi-gao and
jt2594838
and
a lite review from Copilot
and removed request for
hongzhi-gao and
jt2594838
September 23, 2026 09:00
Contributor
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
Review effort: Lite
Findings: 1
Open (4)
This closes the result set twice (explicitclose()and thendestroy_query_data_set(...)which… · New This doc now guarantees \"releases resources\" on close, butTsFileWriter::close()can return… · New Onflush()failure this returns early without callingio_writer_->end_file()(or any… · New Casting theResultSet*returned fromreader.query(...)to a concrete derived type via… · New
What changed in this PR
Flushes buffered data as part of writer close to avoid missing trailing writes, and simplifies C ABI close wrappers by relying on the writer’s close semantics.
Changes:
- Call
flush()insideTsFileWriter::close()and propagate flush failures before finalization. - Remove redundant explicit
flush()calls from C wrapper close functions. - Add/extend regression tests verifying close persists data written after the last flush (writer + table view).
| File | Description |
|---|---|
| cpp/test/writer/tsfile_writer_test.cc | Adds a regression test ensuring close() flushes data written after the last flush(). |
| cpp/test/writer/table_view/tsfile_writer_table_test.cc | Updates table writer test to verify data is readable after close() (without explicit flush()). |
| cpp/src/writer/tsfile_writer.h | Updates close() documentation to reflect the new flush-and-finalize behavior. |
| cpp/src/writer/tsfile_writer.cc | Implements close() to flush() before calling end_file(). |
| cpp/src/writer/tsfile_table_writer.h | Updates close() documentation to mention flushing/finalization. |
| cpp/src/cwrapper/tsfile_cwrapper.h | Updates C API docstring to mention flush/finalize behavior on close. |
| cpp/src/cwrapper/tsfile_cwrapper.cc | Removes explicit flush() from C ABI close wrappers and relies on close(). |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| ++row_count; | ||
| } | ||
| EXPECT_EQ(row_count, 10); | ||
| table_result_set->close(); |
Comment on lines
+499
to
+500
| * @brief Flushes pending data, finalizes the TsFile, and releases resources | ||
| * associated with a TsFileWriter. |
Comment on lines
+1989
to
1993
| int ret = flush(); | ||
| if (ret != E_OK) { | ||
| return ret; | ||
| } | ||
| return io_writer_->end_file(); |
| std::vector<std::string> select_list = {device_path + "." + | ||
| measurement_name}; | ||
| ASSERT_EQ(reader.query(select_list, 100, 102, result_set), E_OK); | ||
| auto* query_result = static_cast<QDSWithoutTimeGenerator*>(result_set); |
jt2594838
approved these changes
Sep 23, 2026
hongzhi-gao
approved these changes
Sep 23, 2026
hongzhi-gao
approved these changes
Sep 23, 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.


Summary
Testing
cmake --build cpp/target/build --target TsFile_Test -j2