Skip to content

Commit 1bcfd51

Browse files
authored
branch-4.0: [opt](memory) implement freeing memory column by column for partial update (#58275) (#58843)
pick #58275 Now, pages of column writer will be released after write all memtable block in the scenario of partial updates, the process is as follows: 1. create all column_writer 2. append all column_writer (significant amount of memory expansion) 3. finish and free memory. This implement will cause a significant amount of memory expansion when flushing memtable(The larger the number of columns, the more obvious it is), and make load could easily cancelled by memory manager when table column too wide(such as 5000 column). This pr implement freeing memory column by column for partial update to solve the problem, the process is as follows: 1. create all column_writer 2. append column_writer and free memory column by column. Test using machines with specifications of 16c and 64G with 5000 column table: - Before this pr, `VerticalSegmentWriter::_create_column_writer` occupies nearly 20% of the memory. - After fix, ` VerticalSegmentWriter::_create_column_writer` hardly occupies memory. ### What problem does this PR solve? Issue Number: close #xxx Related PR: #xxx Problem Summary: ### Release note None ### Check List (For Author) - Test <!-- At least one of them must be included. --> - [ ] Regression test - [ ] Unit Test - [ ] Manual test (add detailed scripts or steps below) - [ ] No need to test or manual test. Explain why: - [ ] This is a refactor/code format and no logic has been changed. - [ ] Previous test can cover this change. - [ ] No code files have been changed. - [ ] Other reason <!-- Add your reason? --> - Behavior changed: - [ ] No. - [ ] Yes. <!-- Explain the behavior change --> - Does this need documentation? - [ ] No. - [ ] Yes. <!-- Add document PR link here. eg: apache/doris-website#1214 --> ### Check List (For Reviewer who merge this PR) - [ ] Confirm the release note - [ ] Confirm test cases - [ ] Confirm document - [ ] Add branch pick label <!-- Add branch pick label that this PR should merge into -->
1 parent cafd800 commit 1bcfd51

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

be/src/olap/rowset/segment_v2/vertical_segment_writer.cpp

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,19 @@ Status VerticalSegmentWriter::_probe_key_for_mow(
451451
return Status::OK();
452452
}
453453

454+
Status VerticalSegmentWriter::_finalize_column_writer_and_update_meta(size_t cid) {
455+
RETURN_IF_ERROR(_column_writers[cid]->finish());
456+
RETURN_IF_ERROR(_column_writers[cid]->write_data());
457+
458+
auto* column_meta = _column_writers[cid]->get_column_meta();
459+
column_meta->set_compressed_data_bytes(
460+
_column_writers[cid]->get_total_compressed_data_pages_bytes());
461+
column_meta->set_uncompressed_data_bytes(
462+
_column_writers[cid]->get_total_uncompressed_data_pages_bytes());
463+
column_meta->set_raw_data_bytes(_column_writers[cid]->get_raw_data_bytes());
464+
return Status::OK();
465+
}
466+
454467
Status VerticalSegmentWriter::_partial_update_preconditions_check(size_t row_pos,
455468
bool is_flexible_update) {
456469
if (!_is_mow()) {
@@ -540,6 +553,7 @@ Status VerticalSegmentWriter::_append_block_with_partial_content(RowsInBlock& da
540553
}
541554
RETURN_IF_ERROR(_column_writers[cid]->append(column->get_nullmap(), column->get_data(),
542555
data.num_rows));
556+
RETURN_IF_ERROR(_finalize_column_writer_and_update_meta(cid));
543557
}
544558

545559
bool has_default_or_nullable = false;
@@ -629,6 +643,7 @@ Status VerticalSegmentWriter::_append_block_with_partial_content(RowsInBlock& da
629643
}
630644
RETURN_IF_ERROR(_column_writers[cid]->append(column->get_nullmap(), column->get_data(),
631645
data.num_rows));
646+
RETURN_IF_ERROR(_finalize_column_writer_and_update_meta(cid));
632647
}
633648

634649
_num_rows_updated += stats.num_rows_updated;
@@ -726,6 +741,7 @@ Status VerticalSegmentWriter::_append_block_with_flexible_partial_content(
726741
RETURN_IF_ERROR(_column_writers[cid]->append(column->get_nullmap(), column->get_data(),
727742
data.num_rows));
728743
DCHECK(_column_writers[cid]->get_next_rowid() == _num_rows_written + data.num_rows);
744+
RETURN_IF_ERROR(_finalize_column_writer_and_update_meta(cid));
729745
}
730746

731747
// 5. genreate read plan
@@ -771,6 +787,7 @@ Status VerticalSegmentWriter::_append_block_with_flexible_partial_content(
771787
RETURN_IF_ERROR(_column_writers[cid]->append(column->get_nullmap(), column->get_data(),
772788
data.num_rows));
773789
DCHECK(_column_writers[cid]->get_next_rowid() == _num_rows_written + data.num_rows);
790+
RETURN_IF_ERROR(_finalize_column_writer_and_update_meta(cid));
774791
}
775792

776793
_num_rows_updated += stats.num_rows_updated;
@@ -932,17 +949,6 @@ Status VerticalSegmentWriter::write_batch() {
932949
RETURN_IF_ERROR(_append_block_with_partial_content(data, full_block));
933950
}
934951
}
935-
for (auto& column_writer : _column_writers) {
936-
RETURN_IF_ERROR(column_writer->finish());
937-
RETURN_IF_ERROR(column_writer->write_data());
938-
939-
auto* column_meta = column_writer->get_column_meta();
940-
column_meta->set_compressed_data_bytes(
941-
column_writer->get_total_compressed_data_pages_bytes());
942-
column_meta->set_uncompressed_data_bytes(
943-
column_writer->get_total_uncompressed_data_pages_bytes());
944-
column_meta->set_raw_data_bytes(column_writer->get_raw_data_bytes());
945-
}
946952
return Status::OK();
947953
}
948954
// Row column should be filled here when it's a directly write from memtable
@@ -992,15 +998,7 @@ Status VerticalSegmentWriter::write_batch() {
992998
return Status::Error<DISK_REACH_CAPACITY_LIMIT>("disk {} exceed capacity limit.",
993999
_data_dir->path_hash());
9941000
}
995-
RETURN_IF_ERROR(_column_writers[cid]->finish());
996-
RETURN_IF_ERROR(_column_writers[cid]->write_data());
997-
998-
auto* column_meta = _column_writers[cid]->get_column_meta();
999-
column_meta->set_compressed_data_bytes(
1000-
_column_writers[cid]->get_total_compressed_data_pages_bytes());
1001-
column_meta->set_uncompressed_data_bytes(
1002-
_column_writers[cid]->get_total_uncompressed_data_pages_bytes());
1003-
column_meta->set_raw_data_bytes(_column_writers[cid]->get_raw_data_bytes());
1001+
RETURN_IF_ERROR(_finalize_column_writer_and_update_meta(cid));
10041002
}
10051003

10061004
for (auto& data : _batched_blocks) {

be/src/olap/rowset/segment_v2/vertical_segment_writer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ class VerticalSegmentWriter {
198198
vectorized::IOlapColumnDataAccessor* seq_column, size_t num_rows, bool need_sort);
199199
Status _generate_short_key_index(std::vector<vectorized::IOlapColumnDataAccessor*>& key_columns,
200200
size_t num_rows, const std::vector<size_t>& short_key_pos);
201+
Status _finalize_column_writer_and_update_meta(size_t cid);
202+
201203
bool _is_mow();
202204
bool _is_mow_with_cluster_key();
203205

0 commit comments

Comments
 (0)