You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by "bobhan1 (via GitHub)" <gi...@apache.org> on 2025/11/24 09:11:50 UTC

[PR] persist segment rows in rowse meta pb [doris]

bobhan1 opened a new pull request, #58301:
URL: https://github.com/apache/doris/pull/58301

   ### 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 -->
   
   


-- 
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-unsubscribe@doris.apache.org

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


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


Re: [PR] cs_opt_version-3.1: [Opt](meta)persist segment rows in rowse meta pb [doris]

Posted by "gavinchou (via GitHub)" <gi...@apache.org>.
gavinchou commented on code in PR #58301:
URL: https://github.com/apache/doris/pull/58301#discussion_r2564021381


##########
be/src/olap/rowset/beta_rowset.cpp:
##########
@@ -68,6 +71,86 @@ Status BetaRowset::init() {
     return Status::OK(); // no op
 }
 
+namespace {
+Status load_segment_rows_from_footer(BetaRowsetSharedPtr rowset,
+                                     std::vector<uint32_t>* segment_rows, bool enable_segment_cache,
+                                     OlapReaderStatistics* read_stats) {
+    SegmentCacheHandle segment_cache_handle;
+    RETURN_IF_ERROR(SegmentLoader::instance()->load_segments(
+            rowset, &segment_cache_handle, enable_segment_cache, false, read_stats));
+    for (const auto& segment : segment_cache_handle.get_segments()) {
+        segment_rows->emplace_back(segment->num_rows());
+    }
+    return Status::OK();
+}
+
+Status check_segment_rows_consistency(const std::vector<uint32_t>& rows_from_meta,
+                                      const std::vector<uint32_t>& rows_from_footer,
+                                      int64_t tablet_id, const std::string& rowset_id) {
+    DCHECK_EQ(rows_from_footer.size(), rows_from_meta.size());
+    for (size_t i = 0; i < rows_from_footer.size(); i++) {
+        if (rows_from_footer[i] != rows_from_meta[i]) {
+            auto msg = fmt::format(
+                    "segment rows mismatch between rowset meta and segment footer. "
+                    "segment index: {}, meta rows: {}, footer rows: {}, tablet={}, rowset={}",
+                    i, rows_from_meta[i], rows_from_footer[i], tablet_id, rowset_id);
+            if (config::enable_segment_rows_check_core) {
+                CHECK(false) << msg;
+            }
+            return Status::InternalError(msg);
+        }
+    }
+    return Status::OK();
+}
+} // namespace
+
+Status BetaRowset::get_segment_num_rows(std::vector<uint32_t>* segment_rows,
+                                        bool enable_segment_cache,
+                                        OlapReaderStatistics* read_stats) {
+    RETURN_IF_ERROR(_load_segment_rows_once.call([this, enable_segment_cache, read_stats] {
+        auto segment_count = num_segments();
+
+        if (!_rowset_meta->get_segment_rows().empty()) {

Review Comment:
   try following to reduce large block of code indentions
   ```
   if (rowset meta DOES NOT have num seg rows) {
           // otherwise, read it from segment footer
           TEST_SYNC_POINT("BetaRowset::get_segment_num_rows:load_from_segment_footer");
           auto self = std::dynamic_pointer_cast<BetaRowset>(shared_from_this());
           return load_segment_rows_from_footer(self, &_segments_rows, enable_segment_cache,
                                                read_stats);
   }
   
   // ... read from rowset meta
   ```



-- 
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-unsubscribe@doris.apache.org

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


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


Re: [PR] cs_opt_version-3.1: [Opt](meta)persist segment rows in rowse meta pb [doris]

Posted by "bobhan1 (via GitHub)" <gi...@apache.org>.
bobhan1 commented on code in PR #58301:
URL: https://github.com/apache/doris/pull/58301#discussion_r2564121333


##########
be/src/olap/rowset/beta_rowset.cpp:
##########
@@ -68,6 +71,86 @@ Status BetaRowset::init() {
     return Status::OK(); // no op
 }
 
+namespace {
+Status load_segment_rows_from_footer(BetaRowsetSharedPtr rowset,
+                                     std::vector<uint32_t>* segment_rows, bool enable_segment_cache,
+                                     OlapReaderStatistics* read_stats) {
+    SegmentCacheHandle segment_cache_handle;
+    RETURN_IF_ERROR(SegmentLoader::instance()->load_segments(
+            rowset, &segment_cache_handle, enable_segment_cache, false, read_stats));
+    for (const auto& segment : segment_cache_handle.get_segments()) {
+        segment_rows->emplace_back(segment->num_rows());
+    }
+    return Status::OK();
+}
+
+Status check_segment_rows_consistency(const std::vector<uint32_t>& rows_from_meta,
+                                      const std::vector<uint32_t>& rows_from_footer,
+                                      int64_t tablet_id, const std::string& rowset_id) {
+    DCHECK_EQ(rows_from_footer.size(), rows_from_meta.size());
+    for (size_t i = 0; i < rows_from_footer.size(); i++) {
+        if (rows_from_footer[i] != rows_from_meta[i]) {
+            auto msg = fmt::format(
+                    "segment rows mismatch between rowset meta and segment footer. "
+                    "segment index: {}, meta rows: {}, footer rows: {}, tablet={}, rowset={}",
+                    i, rows_from_meta[i], rows_from_footer[i], tablet_id, rowset_id);
+            if (config::enable_segment_rows_check_core) {
+                CHECK(false) << msg;
+            }
+            return Status::InternalError(msg);
+        }
+    }
+    return Status::OK();
+}
+} // namespace
+
+Status BetaRowset::get_segment_num_rows(std::vector<uint32_t>* segment_rows,
+                                        bool enable_segment_cache,
+                                        OlapReaderStatistics* read_stats) {
+    RETURN_IF_ERROR(_load_segment_rows_once.call([this, enable_segment_cache, read_stats] {
+        auto segment_count = num_segments();
+
+        if (!_rowset_meta->get_segment_rows().empty()) {
+            if (_rowset_meta->get_segment_rows().size() == segment_count) {
+                // use segment rows in rowset meta if eligible
+                TEST_SYNC_POINT("BetaRowset::get_segment_num_rows:use_segment_rows_from_meta");
+                _segments_rows.assign(_rowset_meta->get_segment_rows().cbegin(),
+                                      _rowset_meta->get_segment_rows().cend());
+                if (config::enable_segment_rows_consistency_check) {
+                    // verify segment rows from meta match segment footer
+                    std::vector<uint32_t> rows_from_footer;
+                    auto self = std::dynamic_pointer_cast<BetaRowset>(shared_from_this());
+                    auto load_status = load_segment_rows_from_footer(
+                            self, &rows_from_footer, enable_segment_cache, read_stats);
+                    if (load_status.ok()) {
+                        return check_segment_rows_consistency(
+                                _segments_rows, rows_from_footer, _rowset_meta->tablet_id(),
+                                _rowset_meta->rowset_id().to_string());
+                    }
+                }
+                return Status::OK();
+            } else {

Review Comment:
   can fallback to read from segment footer if this really happened



-- 
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-unsubscribe@doris.apache.org

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


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


Re: [PR] cs_opt_version-3.1: [Opt](meta)persist segment rows in rowse meta pb [doris]

Posted by "liaoxin01 (via GitHub)" <gi...@apache.org>.
liaoxin01 merged PR #58301:
URL: https://github.com/apache/doris/pull/58301


-- 
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-unsubscribe@doris.apache.org

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


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


Re: [PR] cs_opt_version-3.1: [Opt](meta)persist segment rows in rowse meta pb [doris]

Posted by "gavinchou (via GitHub)" <gi...@apache.org>.
gavinchou commented on code in PR #58301:
URL: https://github.com/apache/doris/pull/58301#discussion_r2564035421


##########
be/src/olap/rowset/beta_rowset.h:
##########
@@ -91,6 +91,9 @@ class BetaRowset final : public Rowset {
     Status show_nested_index_file(rapidjson::Value* rowset_value,
                                   rapidjson::Document::AllocatorType& allocator);
 
+    Status get_segment_num_rows(std::vector<uint32_t>* segment_rows, bool enable_segment_cache,

Review Comment:
   naming `get_num_segment_rows`



-- 
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-unsubscribe@doris.apache.org

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


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


Re: [PR] cs_opt_version-3.1: [Opt](meta)persist segment rows in rowse meta pb [doris]

Posted by "bobhan1 (via GitHub)" <gi...@apache.org>.
bobhan1 commented on code in PR #58301:
URL: https://github.com/apache/doris/pull/58301#discussion_r2564119083


##########
be/src/olap/rowset/beta_rowset.cpp:
##########
@@ -68,6 +71,86 @@ Status BetaRowset::init() {
     return Status::OK(); // no op
 }
 
+namespace {
+Status load_segment_rows_from_footer(BetaRowsetSharedPtr rowset,
+                                     std::vector<uint32_t>* segment_rows, bool enable_segment_cache,
+                                     OlapReaderStatistics* read_stats) {
+    SegmentCacheHandle segment_cache_handle;
+    RETURN_IF_ERROR(SegmentLoader::instance()->load_segments(
+            rowset, &segment_cache_handle, enable_segment_cache, false, read_stats));
+    for (const auto& segment : segment_cache_handle.get_segments()) {
+        segment_rows->emplace_back(segment->num_rows());
+    }
+    return Status::OK();
+}
+
+Status check_segment_rows_consistency(const std::vector<uint32_t>& rows_from_meta,
+                                      const std::vector<uint32_t>& rows_from_footer,
+                                      int64_t tablet_id, const std::string& rowset_id) {
+    DCHECK_EQ(rows_from_footer.size(), rows_from_meta.size());
+    for (size_t i = 0; i < rows_from_footer.size(); i++) {
+        if (rows_from_footer[i] != rows_from_meta[i]) {
+            auto msg = fmt::format(
+                    "segment rows mismatch between rowset meta and segment footer. "
+                    "segment index: {}, meta rows: {}, footer rows: {}, tablet={}, rowset={}",
+                    i, rows_from_meta[i], rows_from_footer[i], tablet_id, rowset_id);
+            if (config::enable_segment_rows_check_core) {
+                CHECK(false) << msg;
+            }
+            return Status::InternalError(msg);
+        }
+    }
+    return Status::OK();
+}
+} // namespace
+
+Status BetaRowset::get_segment_num_rows(std::vector<uint32_t>* segment_rows,
+                                        bool enable_segment_cache,
+                                        OlapReaderStatistics* read_stats) {
+    RETURN_IF_ERROR(_load_segment_rows_once.call([this, enable_segment_cache, read_stats] {
+        auto segment_count = num_segments();
+
+        if (!_rowset_meta->get_segment_rows().empty()) {
+            if (_rowset_meta->get_segment_rows().size() == segment_count) {
+                // use segment rows in rowset meta if eligible
+                TEST_SYNC_POINT("BetaRowset::get_segment_num_rows:use_segment_rows_from_meta");
+                _segments_rows.assign(_rowset_meta->get_segment_rows().cbegin(),
+                                      _rowset_meta->get_segment_rows().cend());
+                if (config::enable_segment_rows_consistency_check) {
+                    // verify segment rows from meta match segment footer
+                    std::vector<uint32_t> rows_from_footer;
+                    auto self = std::dynamic_pointer_cast<BetaRowset>(shared_from_this());
+                    auto load_status = load_segment_rows_from_footer(
+                            self, &rows_from_footer, enable_segment_cache, read_stats);
+                    if (load_status.ok()) {
+                        return check_segment_rows_consistency(
+                                _segments_rows, rows_from_footer, _rowset_meta->tablet_id(),
+                                _rowset_meta->rowset_id().to_string());
+                    }
+                }
+                return Status::OK();
+            } else {

Review Comment:
   just to figure out if I missed some write path with enable_segment_rows_check_core=true in test environment



-- 
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-unsubscribe@doris.apache.org

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


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


Re: [PR] persist segment rows in rowse meta pb [doris]

Posted by "Thearas (via GitHub)" <gi...@apache.org>.
Thearas commented on PR #58301:
URL: https://github.com/apache/doris/pull/58301#issuecomment-3569668457

   
   Thank you for your contribution to Apache Doris.
   Don't know what should be done next? See [How to process your PR](https://cwiki.apache.org/confluence/display/DORIS/How+to+process+your+PR).
   
   Please clearly describe your PR:
   1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
   2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
   3. What features were added. Why was this function added?
   4. Which code was refactored and why was this part of the code refactored?
   5. Which functions were optimized and what is the difference before and after the optimization?
       


-- 
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-unsubscribe@doris.apache.org

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


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


Re: [PR] cs_opt_version-3.1: [Opt](meta)persist segment rows in rowse meta pb [doris]

Posted by "gavinchou (via GitHub)" <gi...@apache.org>.
gavinchou commented on code in PR #58301:
URL: https://github.com/apache/doris/pull/58301#discussion_r2564029093


##########
be/src/olap/rowset/beta_rowset.cpp:
##########
@@ -68,6 +71,86 @@ Status BetaRowset::init() {
     return Status::OK(); // no op
 }
 
+namespace {
+Status load_segment_rows_from_footer(BetaRowsetSharedPtr rowset,
+                                     std::vector<uint32_t>* segment_rows, bool enable_segment_cache,
+                                     OlapReaderStatistics* read_stats) {
+    SegmentCacheHandle segment_cache_handle;
+    RETURN_IF_ERROR(SegmentLoader::instance()->load_segments(
+            rowset, &segment_cache_handle, enable_segment_cache, false, read_stats));
+    for (const auto& segment : segment_cache_handle.get_segments()) {
+        segment_rows->emplace_back(segment->num_rows());
+    }
+    return Status::OK();
+}
+
+Status check_segment_rows_consistency(const std::vector<uint32_t>& rows_from_meta,
+                                      const std::vector<uint32_t>& rows_from_footer,
+                                      int64_t tablet_id, const std::string& rowset_id) {
+    DCHECK_EQ(rows_from_footer.size(), rows_from_meta.size());
+    for (size_t i = 0; i < rows_from_footer.size(); i++) {
+        if (rows_from_footer[i] != rows_from_meta[i]) {
+            auto msg = fmt::format(
+                    "segment rows mismatch between rowset meta and segment footer. "
+                    "segment index: {}, meta rows: {}, footer rows: {}, tablet={}, rowset={}",
+                    i, rows_from_meta[i], rows_from_footer[i], tablet_id, rowset_id);
+            if (config::enable_segment_rows_check_core) {
+                CHECK(false) << msg;
+            }
+            return Status::InternalError(msg);
+        }
+    }
+    return Status::OK();
+}
+} // namespace
+
+Status BetaRowset::get_segment_num_rows(std::vector<uint32_t>* segment_rows,
+                                        bool enable_segment_cache,
+                                        OlapReaderStatistics* read_stats) {
+    RETURN_IF_ERROR(_load_segment_rows_once.call([this, enable_segment_cache, read_stats] {
+        auto segment_count = num_segments();
+
+        if (!_rowset_meta->get_segment_rows().empty()) {
+            if (_rowset_meta->get_segment_rows().size() == segment_count) {
+                // use segment rows in rowset meta if eligible
+                TEST_SYNC_POINT("BetaRowset::get_segment_num_rows:use_segment_rows_from_meta");
+                _segments_rows.assign(_rowset_meta->get_segment_rows().cbegin(),
+                                      _rowset_meta->get_segment_rows().cend());
+                if (config::enable_segment_rows_consistency_check) {
+                    // verify segment rows from meta match segment footer
+                    std::vector<uint32_t> rows_from_footer;
+                    auto self = std::dynamic_pointer_cast<BetaRowset>(shared_from_this());
+                    auto load_status = load_segment_rows_from_footer(
+                            self, &rows_from_footer, enable_segment_cache, read_stats);
+                    if (load_status.ok()) {
+                        return check_segment_rows_consistency(
+                                _segments_rows, rows_from_footer, _rowset_meta->tablet_id(),
+                                _rowset_meta->rowset_id().to_string());
+                    }
+                }
+                return Status::OK();
+            } else {

Review Comment:
   when does this happen?
   could we fallback to read from segment footer if this happened



-- 
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-unsubscribe@doris.apache.org

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


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


Re: [PR] cs_opt_version-3.1: [Opt](meta)persist segment rows in rowse meta pb [doris]

Posted by "gavinchou (via GitHub)" <gi...@apache.org>.
gavinchou commented on code in PR #58301:
URL: https://github.com/apache/doris/pull/58301#discussion_r2564006203


##########
be/src/olap/rowset/rowset_meta.h:
##########
@@ -140,6 +140,17 @@ class RowsetMeta : public MetadataAdder<RowsetMeta> {
 
     void set_num_rows(int64_t num_rows) { _rowset_meta_pb.set_num_rows(num_rows); }
 
+    void set_segment_rows(const std::vector<uint32_t>& segment_rows) {

Review Comment:
   suggest naming `set_num_segment_rows`



##########
be/src/olap/rowset/rowset_meta.h:
##########
@@ -140,6 +140,17 @@ class RowsetMeta : public MetadataAdder<RowsetMeta> {
 
     void set_num_rows(int64_t num_rows) { _rowset_meta_pb.set_num_rows(num_rows); }
 
+    void set_segment_rows(const std::vector<uint32_t>& segment_rows) {
+        _rowset_meta_pb.mutable_segment_rows()->Assign(segment_rows.cbegin(), segment_rows.cend());
+    }
+
+    void get_segment_rows(std::vector<uint32_t>* segment_rows) const {

Review Comment:
   ditto



-- 
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-unsubscribe@doris.apache.org

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


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


Re: [PR] cs_opt_version-3.1: [Opt](meta)persist segment rows in rowse meta pb [doris]

Posted by "gavinchou (via GitHub)" <gi...@apache.org>.
gavinchou commented on code in PR #58301:
URL: https://github.com/apache/doris/pull/58301#discussion_r2563980163


##########
gensrc/proto/olap_file.proto:
##########
@@ -125,6 +125,9 @@ message RowsetMetaPB {
     // indicate that whether the segments key bounds is truncated
     optional bool segments_key_bounds_truncated = 55;
 
+    // rows count for each segment
+    repeated int64 segment_rows = 56;

Review Comment:
   suguest naming
   `num_segment_rows`



-- 
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-unsubscribe@doris.apache.org

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


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