This is an automated email from the ASF dual-hosted git repository.

yiguolei pushed a commit to branch branch-4.0
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-4.0 by this push:
     new 1bcfd51933b branch-4.0: [opt](memory) implement freeing memory column 
by column for partial update (#58275) (#58843)
1bcfd51933b is described below

commit 1bcfd51933b1e924e74d3f9da969ad32b964f527
Author: hui lai <[email protected]>
AuthorDate: Mon Dec 29 10:01:44 2025 +0800

    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:
    https://github.com/apache/doris-website/pull/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 -->
---
 .../rowset/segment_v2/vertical_segment_writer.cpp  | 38 ++++++++++------------
 .../rowset/segment_v2/vertical_segment_writer.h    |  2 ++
 2 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/be/src/olap/rowset/segment_v2/vertical_segment_writer.cpp 
b/be/src/olap/rowset/segment_v2/vertical_segment_writer.cpp
index 975a9970252..f9cc984a370 100644
--- a/be/src/olap/rowset/segment_v2/vertical_segment_writer.cpp
+++ b/be/src/olap/rowset/segment_v2/vertical_segment_writer.cpp
@@ -451,6 +451,19 @@ Status VerticalSegmentWriter::_probe_key_for_mow(
     return Status::OK();
 }
 
+Status VerticalSegmentWriter::_finalize_column_writer_and_update_meta(size_t 
cid) {
+    RETURN_IF_ERROR(_column_writers[cid]->finish());
+    RETURN_IF_ERROR(_column_writers[cid]->write_data());
+
+    auto* column_meta = _column_writers[cid]->get_column_meta();
+    column_meta->set_compressed_data_bytes(
+            _column_writers[cid]->get_total_compressed_data_pages_bytes());
+    column_meta->set_uncompressed_data_bytes(
+            _column_writers[cid]->get_total_uncompressed_data_pages_bytes());
+    
column_meta->set_raw_data_bytes(_column_writers[cid]->get_raw_data_bytes());
+    return Status::OK();
+}
+
 Status VerticalSegmentWriter::_partial_update_preconditions_check(size_t 
row_pos,
                                                                   bool 
is_flexible_update) {
     if (!_is_mow()) {
@@ -540,6 +553,7 @@ Status 
VerticalSegmentWriter::_append_block_with_partial_content(RowsInBlock& da
         }
         RETURN_IF_ERROR(_column_writers[cid]->append(column->get_nullmap(), 
column->get_data(),
                                                      data.num_rows));
+        RETURN_IF_ERROR(_finalize_column_writer_and_update_meta(cid));
     }
 
     bool has_default_or_nullable = false;
@@ -629,6 +643,7 @@ Status 
VerticalSegmentWriter::_append_block_with_partial_content(RowsInBlock& da
         }
         RETURN_IF_ERROR(_column_writers[cid]->append(column->get_nullmap(), 
column->get_data(),
                                                      data.num_rows));
+        RETURN_IF_ERROR(_finalize_column_writer_and_update_meta(cid));
     }
 
     _num_rows_updated += stats.num_rows_updated;
@@ -726,6 +741,7 @@ Status 
VerticalSegmentWriter::_append_block_with_flexible_partial_content(
         RETURN_IF_ERROR(_column_writers[cid]->append(column->get_nullmap(), 
column->get_data(),
                                                      data.num_rows));
         DCHECK(_column_writers[cid]->get_next_rowid() == _num_rows_written + 
data.num_rows);
+        RETURN_IF_ERROR(_finalize_column_writer_and_update_meta(cid));
     }
 
     // 5. genreate read plan
@@ -771,6 +787,7 @@ Status 
VerticalSegmentWriter::_append_block_with_flexible_partial_content(
         RETURN_IF_ERROR(_column_writers[cid]->append(column->get_nullmap(), 
column->get_data(),
                                                      data.num_rows));
         DCHECK(_column_writers[cid]->get_next_rowid() == _num_rows_written + 
data.num_rows);
+        RETURN_IF_ERROR(_finalize_column_writer_and_update_meta(cid));
     }
 
     _num_rows_updated += stats.num_rows_updated;
@@ -932,17 +949,6 @@ Status VerticalSegmentWriter::write_batch() {
                 RETURN_IF_ERROR(_append_block_with_partial_content(data, 
full_block));
             }
         }
-        for (auto& column_writer : _column_writers) {
-            RETURN_IF_ERROR(column_writer->finish());
-            RETURN_IF_ERROR(column_writer->write_data());
-
-            auto* column_meta = column_writer->get_column_meta();
-            column_meta->set_compressed_data_bytes(
-                    column_writer->get_total_compressed_data_pages_bytes());
-            column_meta->set_uncompressed_data_bytes(
-                    column_writer->get_total_uncompressed_data_pages_bytes());
-            
column_meta->set_raw_data_bytes(column_writer->get_raw_data_bytes());
-        }
         return Status::OK();
     }
     // Row column should be filled here when it's a directly write from 
memtable
@@ -992,15 +998,7 @@ Status VerticalSegmentWriter::write_batch() {
             return Status::Error<DISK_REACH_CAPACITY_LIMIT>("disk {} exceed 
capacity limit.",
                                                             
_data_dir->path_hash());
         }
-        RETURN_IF_ERROR(_column_writers[cid]->finish());
-        RETURN_IF_ERROR(_column_writers[cid]->write_data());
-
-        auto* column_meta = _column_writers[cid]->get_column_meta();
-        column_meta->set_compressed_data_bytes(
-                _column_writers[cid]->get_total_compressed_data_pages_bytes());
-        column_meta->set_uncompressed_data_bytes(
-                
_column_writers[cid]->get_total_uncompressed_data_pages_bytes());
-        
column_meta->set_raw_data_bytes(_column_writers[cid]->get_raw_data_bytes());
+        RETURN_IF_ERROR(_finalize_column_writer_and_update_meta(cid));
     }
 
     for (auto& data : _batched_blocks) {
diff --git a/be/src/olap/rowset/segment_v2/vertical_segment_writer.h 
b/be/src/olap/rowset/segment_v2/vertical_segment_writer.h
index 7bf795a7d62..9528f12f5c7 100644
--- a/be/src/olap/rowset/segment_v2/vertical_segment_writer.h
+++ b/be/src/olap/rowset/segment_v2/vertical_segment_writer.h
@@ -198,6 +198,8 @@ private:
             vectorized::IOlapColumnDataAccessor* seq_column, size_t num_rows, 
bool need_sort);
     Status 
_generate_short_key_index(std::vector<vectorized::IOlapColumnDataAccessor*>& 
key_columns,
                                      size_t num_rows, const 
std::vector<size_t>& short_key_pos);
+    Status _finalize_column_writer_and_update_meta(size_t cid);
+
     bool _is_mow();
     bool _is_mow_with_cluster_key();
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to