HappenLee commented on code in PR #9157:
URL: https://github.com/apache/incubator-doris/pull/9157#discussion_r858183037


##########
be/src/olap/rowset/beta_rowset_writer.cpp:
##########
@@ -110,61 +106,27 @@ OLAPStatus BetaRowsetWriter::add_block(const 
vectorized::Block* block) {
     size_t block_row_num = block->rows();
     size_t row_avg_size_in_bytes = std::max((size_t)1, block_size_in_bytes / 
block_row_num);
     size_t row_offset = 0;
-    int64_t segment_capacity_in_bytes = 0;
-    int64_t segment_capacity_in_rows = 0;
-    auto refresh_segment_capacity = [&]() {
-        segment_capacity_in_bytes =
-                (int64_t)MAX_SEGMENT_SIZE - 
(int64_t)_segment_writer->estimate_segment_size();
-        segment_capacity_in_rows = (int64_t)_context.max_rows_per_segment -
-                                   
(int64_t)_segment_writer->num_rows_written();
-    };
-
-    refresh_segment_capacity();
-    if (UNLIKELY(segment_capacity_in_bytes < row_avg_size_in_bytes ||
-                      segment_capacity_in_rows <= 0)) {
-        // no space for another signle row, need flush now
-        RETURN_NOT_OK(_flush_segment_writer(&_segment_writer));
-        RETURN_NOT_OK(_create_segment_writer(&_segment_writer));
-        refresh_segment_capacity();
-    }
 
-    assert(segment_capacity_in_bytes > row_avg_size_in_bytes && 
segment_capacity_in_rows > 0);
-    if (block_size_in_bytes > segment_capacity_in_bytes ||
-        block_row_num > segment_capacity_in_rows) {
-        size_t segment_max_row_num;
-        size_t input_row_num;
-        do {
-            assert(row_offset < block_row_num);
-            segment_max_row_num =
-                    std::min((size_t)segment_capacity_in_bytes / 
row_avg_size_in_bytes,
-                             (size_t)segment_capacity_in_rows);
-            input_row_num = std::min(segment_max_row_num, block_row_num - 
row_offset);
-            assert(input_row_num > 0);
-            auto s = _segment_writer->append_block(block, row_offset, 
input_row_num);
-            if (UNLIKELY(!s.ok())) {
-                LOG(WARNING) << "failed to append block: " << s.to_string();
-                return OLAP_ERR_WRITER_DATA_WRITE_ERROR;
-            }
+    do {
+        auto max_row_add = 
_segment_writer->max_row_to_add(row_avg_size_in_bytes);
+        if (UNLIKELY(max_row_add < 1)) {
+            // no space for another signle row, need flush now
+            RETURN_NOT_OK(_flush_segment_writer(&_segment_writer));
+            RETURN_NOT_OK(_create_segment_writer(&_segment_writer));
+            DCHECK(_segment_writer->max_row_to_add(row_avg_size_in_bytes) > 0);
+            continue;

Review Comment:
   yes



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to