github-actions[bot] commented on code in PR #30128:
URL: https://github.com/apache/doris/pull/30128#discussion_r1458704017


##########
be/src/olap/base_tablet.cpp:
##########
@@ -104,11 +103,143 @@
             return Status::Error<CAPTURE_ROWSET_READER_ERROR>(
                     "failed to create reader for rowset:{}", 
it->second->rowset_id().to_string());
         }
-        rs_splits->push_back(RowSetSplits(std::move(rs_reader)));
+        rs_splits->emplace_back(std::move(rs_reader));
     }
     return Status::OK();
 }
 
+// snapshot manager may call this api to check if version exists, so that
+// the version maybe not exist
+RowsetSharedPtr BaseTablet::get_rowset_by_version(const Version& version,
+                                                  bool find_in_stale) const {
+    auto iter = _rs_version_map.find(version);
+    if (iter == _rs_version_map.end()) {
+        if (find_in_stale) {
+            return get_stale_rowset_by_version(version);
+        }
+        return nullptr;
+    }
+    return iter->second;
+}
+
+RowsetSharedPtr BaseTablet::get_stale_rowset_by_version(const Version& 
version) const {
+    auto iter = _stale_rs_version_map.find(version);
+    if (iter == _stale_rs_version_map.end()) {
+        VLOG_NOTICE << "no rowset for version:" << version << ", tablet: " << 
tablet_id();
+        return nullptr;
+    }
+    return iter->second;
+}
+
+// Already under _meta_lock
+RowsetSharedPtr BaseTablet::get_rowset_with_max_version() const {
+    Version max_version = _tablet_meta->max_version();
+    if (max_version.first == -1) {
+        return nullptr;
+    }
+
+    auto iter = _rs_version_map.find(max_version);
+    if (iter == _rs_version_map.end()) {
+        DCHECK(false) << "invalid version:" << max_version;
+        return nullptr;
+    }
+    return iter->second;
+}
+
+Status BaseTablet::get_all_rs_id(int64_t max_version, RowsetIdUnorderedSet* 
rowset_ids) const {

Review Comment:
   warning: method 'get_all_rs_id' can be made static 
[readability-convert-member-functions-to-static]
   
   ```suggestion
   static Status BaseTablet::get_all_rs_id(int64_t max_version, 
RowsetIdUnorderedSet* rowset_ids) {
   ```
   



##########
be/src/olap/base_tablet.cpp:
##########
@@ -81,7 +80,7 @@ Status BaseTablet::update_by_least_common_schema(const 
TabletSchemaSPtr& update_
     return Status::OK();
 }
 
-Status BaseTablet::capture_rs_readers_unlocked(const std::vector<Version>& 
version_path,
+Status BaseTablet::capture_rs_readers_unlocked(const Versions& version_path,
                                                std::vector<RowSetSplits>* 
rs_splits) const {

Review Comment:
   warning: method 'capture_rs_readers_unlocked' can be made static 
[readability-convert-member-functions-to-static]
   
   ```suggestion
   static Status BaseTablet::capture_rs_readers_unlocked(const Versions& 
version_path,
                                                  std::vector<RowSetSplits>* 
rs_splits) {
   ```
   



##########
be/src/olap/base_tablet.cpp:
##########
@@ -104,11 +103,143 @@
             return Status::Error<CAPTURE_ROWSET_READER_ERROR>(
                     "failed to create reader for rowset:{}", 
it->second->rowset_id().to_string());
         }
-        rs_splits->push_back(RowSetSplits(std::move(rs_reader)));
+        rs_splits->emplace_back(std::move(rs_reader));
     }
     return Status::OK();
 }
 
+// snapshot manager may call this api to check if version exists, so that
+// the version maybe not exist
+RowsetSharedPtr BaseTablet::get_rowset_by_version(const Version& version,
+                                                  bool find_in_stale) const {
+    auto iter = _rs_version_map.find(version);
+    if (iter == _rs_version_map.end()) {
+        if (find_in_stale) {
+            return get_stale_rowset_by_version(version);
+        }
+        return nullptr;
+    }
+    return iter->second;
+}
+
+RowsetSharedPtr BaseTablet::get_stale_rowset_by_version(const Version& 
version) const {
+    auto iter = _stale_rs_version_map.find(version);
+    if (iter == _stale_rs_version_map.end()) {
+        VLOG_NOTICE << "no rowset for version:" << version << ", tablet: " << 
tablet_id();
+        return nullptr;
+    }
+    return iter->second;
+}
+
+// Already under _meta_lock
+RowsetSharedPtr BaseTablet::get_rowset_with_max_version() const {
+    Version max_version = _tablet_meta->max_version();
+    if (max_version.first == -1) {
+        return nullptr;
+    }
+
+    auto iter = _rs_version_map.find(max_version);
+    if (iter == _rs_version_map.end()) {
+        DCHECK(false) << "invalid version:" << max_version;
+        return nullptr;
+    }
+    return iter->second;
+}
+
+Status BaseTablet::get_all_rs_id(int64_t max_version, RowsetIdUnorderedSet* 
rowset_ids) const {
+    std::shared_lock rlock(_meta_lock);
+    return _get_all_rs_id_unlocked(max_version, rowset_ids);
+}
+
+Versions BaseTablet::get_missed_versions(int64_t spec_version) const {
+    DCHECK(spec_version > 0) << "invalid spec_version: " << spec_version;
+
+    Versions existing_versions;
+    {
+        std::shared_lock rdlock(_meta_lock);
+        for (const auto& rs : _tablet_meta->all_rs_metas()) {
+            existing_versions.emplace_back(rs->version());
+        }
+    }
+    return calc_missed_versions(spec_version, existing_versions);
+}
+
+Versions BaseTablet::get_missed_versions_unlocked(int64_t spec_version) const {
+    DCHECK(spec_version > 0) << "invalid spec_version: " << spec_version;
+
+    Versions existing_versions;
+    for (const auto& rs : _tablet_meta->all_rs_metas()) {
+        existing_versions.emplace_back(rs->version());
+    }
+    return calc_missed_versions(spec_version, existing_versions);
+}
+
+Versions BaseTablet::calc_missed_versions(int64_t spec_version, Versions 
existing_versions) {
+    DCHECK(spec_version > 0) << "invalid spec_version: " << spec_version;
+
+    // sort the existing versions in ascending order
+    std::sort(existing_versions.begin(), existing_versions.end(),
+              [](const Version& a, const Version& b) {
+                  // simple because 2 versions are certainly not overlapping
+                  return a.first < b.first;
+              });
+
+    // From the first version(=0), find the missing version until spec_version
+    int64_t last_version = -1;
+    Versions missed_versions;
+    for (const Version& version : existing_versions) {
+        if (version.first > last_version + 1) {
+            // there is a hole between versions
+            missed_versions.emplace_back(last_version + 1, 
std::min(version.first, spec_version));
+        }
+        last_version = version.second;
+        if (last_version >= spec_version) {
+            break;
+        }
+    }
+    if (last_version < spec_version) {
+        // there is a hole between the last version and the specificed version.
+        missed_versions.emplace_back(last_version + 1, spec_version);
+    }
+    return missed_versions;
+}
+
+Status BaseTablet::_get_all_rs_id_unlocked(int64_t max_version,
+                                           RowsetIdUnorderedSet* rowset_ids) 
const {

Review Comment:
   warning: method '_get_all_rs_id_unlocked' can be made static 
[readability-convert-member-functions-to-static]
   
   ```suggestion
   static Status BaseTablet::_get_all_rs_id_unlocked(int64_t max_version,
                                              RowsetIdUnorderedSet* rowset_ids) 
{
   ```
   



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