-
Notifications
You must be signed in to change notification settings - Fork 92
Fix/aligned tv page seal #734
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hongzhi-gao
wants to merge
11
commits into
apache:develop
Choose a base branch
from
hongzhi-gao:fix/aligned_tv_page_seal
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
cd3dab2
fix readme logo
hongzhi-gao c643961
fix readme logo
hongzhi-gao 7a61f3e
fix readme badge
hongzhi-gao 5fb0580
Merge branch 'apache:develop' into develop
hongzhi-gao 8368538
tmp
hongzhi-gao 0bbd644
add ut
hongzhi-gao 6028c9c
mvn spotless:apply
hongzhi-gao 846804e
tmp
hongzhi-gao eafd8e0
try to fix ut
hongzhi-gao 1c06fda
Align C++ aligned-model page sealing with the Java behavior and fix r…
hongzhi-gao 94d51ea
fix ut
hongzhi-gao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -634,6 +634,14 @@ int TsFileWriter::write_record_aligned(const TsRecord& record) { | |
| if (value_chunk_writers.size() != record.points_.size()) { | ||
| return E_INVALID_ARG; | ||
| } | ||
| int32_t time_pages_before = time_chunk_writer->num_of_pages(); | ||
| std::vector<int32_t> value_pages_before(value_chunk_writers.size(), 0); | ||
| for (uint32_t c = 0; c < value_chunk_writers.size(); c++) { | ||
| ValueChunkWriter* value_chunk_writer = value_chunk_writers[c]; | ||
| if (!IS_NULL(value_chunk_writer)) { | ||
| value_pages_before[c] = value_chunk_writer->num_of_pages(); | ||
| } | ||
| } | ||
| time_chunk_writer->write(record.timestamp_); | ||
| for (uint32_t c = 0; c < value_chunk_writers.size(); c++) { | ||
| ValueChunkWriter* value_chunk_writer = value_chunk_writers[c]; | ||
|
|
@@ -643,6 +651,11 @@ int TsFileWriter::write_record_aligned(const TsRecord& record) { | |
| write_point_aligned(value_chunk_writer, record.timestamp_, | ||
| data_types[c], record.points_[c]); | ||
| } | ||
| if (RET_FAIL(maybe_seal_aligned_pages_together( | ||
| time_chunk_writer, value_chunk_writers, time_pages_before, | ||
| value_pages_before))) { | ||
| return ret; | ||
| } | ||
| return ret; | ||
| } | ||
|
|
||
|
|
@@ -704,6 +717,41 @@ int TsFileWriter::write_point_aligned(ValueChunkWriter* value_chunk_writer, | |
| } | ||
| } | ||
|
|
||
| int TsFileWriter::maybe_seal_aligned_pages_together( | ||
| TimeChunkWriter* time_chunk_writer, | ||
| common::SimpleVector<ValueChunkWriter*>& value_chunk_writers, | ||
| int32_t time_pages_before, const std::vector<int32_t>& value_pages_before) { | ||
| bool should_seal_all = | ||
| time_chunk_writer->num_of_pages() > time_pages_before; | ||
| for (uint32_t c = 0; c < value_chunk_writers.size() && !should_seal_all; | ||
| c++) { | ||
| ValueChunkWriter* value_chunk_writer = value_chunk_writers[c]; | ||
| if (!IS_NULL(value_chunk_writer) && | ||
| value_chunk_writer->num_of_pages() > value_pages_before[c]) { | ||
| should_seal_all = true; | ||
| break; | ||
| } | ||
| } | ||
| if (!should_seal_all) { | ||
| return E_OK; | ||
| } | ||
|
|
||
| int ret = E_OK; | ||
| if (time_chunk_writer->has_current_page_data() && | ||
| RET_FAIL(time_chunk_writer->seal_current_page())) { | ||
| return ret; | ||
| } | ||
| for (uint32_t c = 0; c < value_chunk_writers.size(); c++) { | ||
| ValueChunkWriter* value_chunk_writer = value_chunk_writers[c]; | ||
| if (!IS_NULL(value_chunk_writer) && | ||
| value_chunk_writer->has_current_page_data() && | ||
| RET_FAIL(value_chunk_writer->seal_current_page())) { | ||
| return ret; | ||
| } | ||
| } | ||
| return ret; | ||
| } | ||
|
|
||
| int TsFileWriter::write_tablet_aligned(const Tablet& tablet) { | ||
| int ret = E_OK; | ||
| SimpleVector<ValueChunkWriter*> value_chunk_writers; | ||
|
|
@@ -716,15 +764,33 @@ int TsFileWriter::write_tablet_aligned(const Tablet& tablet) { | |
| data_types))) { | ||
| return ret; | ||
| } | ||
| time_write_column(time_chunk_writer, tablet); | ||
| ASSERT(value_chunk_writers.size() == tablet.get_column_count()); | ||
| for (uint32_t c = 0; c < value_chunk_writers.size(); c++) { | ||
| ValueChunkWriter* value_chunk_writer = value_chunk_writers[c]; | ||
| if (IS_NULL(value_chunk_writer)) { | ||
| continue; | ||
| for (uint32_t row = 0; row < tablet.get_cur_row_size(); row++) { | ||
| int32_t time_pages_before = time_chunk_writer->num_of_pages(); | ||
| std::vector<int32_t> value_pages_before(value_chunk_writers.size(), 0); | ||
| for (uint32_t c = 0; c < value_chunk_writers.size(); c++) { | ||
| ValueChunkWriter* value_chunk_writer = value_chunk_writers[c]; | ||
| if (!IS_NULL(value_chunk_writer)) { | ||
| value_pages_before[c] = value_chunk_writer->num_of_pages(); | ||
| } | ||
| } | ||
|
|
||
| if (RET_FAIL(time_chunk_writer->write(tablet.timestamps_[row]))) { | ||
| return ret; | ||
| } | ||
| ASSERT(value_chunk_writers.size() == tablet.get_column_count()); | ||
| for (uint32_t c = 0; c < value_chunk_writers.size(); c++) { | ||
| ValueChunkWriter* value_chunk_writer = value_chunk_writers[c]; | ||
| if (IS_NULL(value_chunk_writer)) { | ||
| continue; | ||
| } | ||
| if (RET_FAIL(value_write_column(value_chunk_writer, tablet, c, row, | ||
| row + 1))) { | ||
| return ret; | ||
| } | ||
| } | ||
| if (RET_FAIL(value_write_column(value_chunk_writer, tablet, c, 0, | ||
| tablet.get_cur_row_size()))) { | ||
| if (RET_FAIL(maybe_seal_aligned_pages_together( | ||
| time_chunk_writer, value_chunk_writers, time_pages_before, | ||
| value_pages_before))) { | ||
| return ret; | ||
| } | ||
| } | ||
|
|
@@ -808,26 +874,38 @@ int TsFileWriter::write_table(Tablet& tablet) { | |
| value_chunk_writers))) { | ||
| return ret; | ||
| } | ||
| // Row-by-row write so that when time page seals (e.g. by memory | ||
| // threshold), we can seal all value pages together (Java | ||
| // semantics). | ||
| for (int i = start_idx; i < end_idx; i++) { | ||
| int32_t time_pages_before = time_chunk_writer->num_of_pages(); | ||
| if (RET_FAIL(time_chunk_writer->write(tablet.timestamps_[i]))) { | ||
| return ret; | ||
| } | ||
| } | ||
| uint32_t field_col_count = 0; | ||
| for (uint32_t i = 0; i < tablet.get_column_count(); ++i) { | ||
| if (tablet.column_categories_[i] == | ||
| common::ColumnCategory::FIELD) { | ||
| ValueChunkWriter* value_chunk_writer = | ||
| value_chunk_writers[field_col_count]; | ||
| if (IS_NULL(value_chunk_writer)) { | ||
| continue; | ||
| uint32_t field_col_count = 0; | ||
| for (uint32_t col = 0; col < tablet.get_column_count(); ++col) { | ||
| if (tablet.column_categories_[col] == | ||
| common::ColumnCategory::FIELD) { | ||
| ValueChunkWriter* value_chunk_writer = | ||
| value_chunk_writers[field_col_count]; | ||
| if (!IS_NULL(value_chunk_writer) && | ||
| RET_FAIL(value_write_column( | ||
| value_chunk_writer, tablet, col, i, i + 1))) { | ||
| return ret; | ||
| } | ||
| field_col_count++; | ||
| } | ||
|
|
||
| if (RET_FAIL(value_write_column(value_chunk_writer, tablet, | ||
| i, start_idx, end_idx))) { | ||
| return ret; | ||
| } | ||
| int32_t time_pages_after = time_chunk_writer->num_of_pages(); | ||
| if (time_pages_after > time_pages_before) { | ||
| for (uint32_t k = 0; k < value_chunk_writers.size(); k++) { | ||
| if (!IS_NULL(value_chunk_writers[k]) && | ||
| value_chunk_writers[k]->get_point_numer() > 0 && | ||
| RET_FAIL( | ||
| value_chunk_writers[k]->seal_current_page())) { | ||
| return ret; | ||
| } | ||
| } | ||
|
Comment on lines
+898
to
908
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is the number of value pages not checked. |
||
| field_col_count++; | ||
| } | ||
| } | ||
| start_idx = end_idx; | ||
|
|
||
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
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
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing from a column-based order to a row-based order may cause a performance downgrade.
May add a configuration to optionally sacrifice the page size limit:
If strict_page_size=true, use the row-based insertion with checking the page size each time.
Otherwise, insert each column wholly without the page size check, and perform it at the very end.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or, when there is no string/blob/text column, the memory size of each column can be directly computed with its length. Thus, we can divide the incoming column into splits that will cause a page seal, and write them one by one in a column-based order.