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


##########
be/src/cloud/cloud_engine_calc_delete_bitmap_task.cpp:
##########
@@ -0,0 +1,165 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "cloud/cloud_engine_calc_delete_bitmap_task.h"
+
+#include <memory>
+
+#include "cloud/cloud_meta_mgr.h"
+#include "cloud/cloud_tablet.h"
+#include "common/status.h"
+#include "olap/base_tablet.h"
+#include "olap/olap_common.h"
+#include "olap/rowset/rowset.h"
+#include "olap/tablet_fwd.h"
+#include "olap/tablet_meta.h"
+#include "olap/txn_manager.h"
+#include "olap/utils.h"
+
+namespace doris {
+
+CloudEngineCalcDeleteBitmapTask::CloudEngineCalcDeleteBitmapTask(
+        CloudStorageEngine& engine, const TCalcDeleteBitmapRequest& 
cal_delete_bitmap_req,
+        std::vector<TTabletId>* error_tablet_ids, std::vector<TTabletId>* 
succ_tablet_ids)
+        : _engine(engine),
+          _cal_delete_bitmap_req(cal_delete_bitmap_req),
+          _error_tablet_ids(error_tablet_ids),
+          _succ_tablet_ids(succ_tablet_ids) {}
+
+void CloudEngineCalcDeleteBitmapTask::add_error_tablet_id(int64_t tablet_id, 
const Status& err) {

Review Comment:
   warning: method 'add_error_tablet_id' can be made static 
[readability-convert-member-functions-to-static]
   
   be/src/cloud/cloud_engine_calc_delete_bitmap_task.h:58:
   ```diff
   -     void add_error_tablet_id(int64_t tablet_id, const Status& err);
   +     static void add_error_tablet_id(int64_t tablet_id, const Status& err);
   ```
   



##########
be/src/olap/base_tablet.cpp:
##########
@@ -1059,4 +1063,181 @@ Status BaseTablet::_capture_consistent_rowsets_unlocked(
     return Status::OK();
 }
 
+Status BaseTablet::check_delete_bitmap_correctness(DeleteBitmapPtr 
delete_bitmap,
+                                                   int64_t max_version, 
int64_t txn_id,
+                                                   const RowsetIdUnorderedSet& 
rowset_ids,
+                                                   
std::vector<RowsetSharedPtr>* rowsets) {
+    RowsetIdUnorderedSet missing_ids;
+    for (const auto& rowsetid : rowset_ids) {
+        if (!delete_bitmap->delete_bitmap.contains({rowsetid, 
DeleteBitmap::INVALID_SEGMENT_ID,
+                                                    
DeleteBitmap::TEMP_VERSION_COMMON})) {
+            missing_ids.insert(rowsetid);
+        }
+    }
+
+    if (!missing_ids.empty()) {
+        LOG(WARNING) << "[txn_id:" << txn_id << "][tablet_id:" << tablet_id()
+                     << "][max_version: " << max_version
+                     << "] check delete bitmap correctness failed!";
+        rapidjson::Document root;
+        root.SetObject();
+        rapidjson::Document required_rowsets_arr;
+        required_rowsets_arr.SetArray();
+        rapidjson::Document missing_rowsets_arr;
+        missing_rowsets_arr.SetArray();
+
+        if (rowsets != nullptr) {
+            for (const auto& rowset : *rowsets) {
+                rapidjson::Value value;
+                std::string version_str = rowset->get_rowset_info_str();
+                value.SetString(version_str.c_str(), version_str.length(),
+                                required_rowsets_arr.GetAllocator());
+                required_rowsets_arr.PushBack(value, 
required_rowsets_arr.GetAllocator());
+            }
+        } else {
+            std::vector<RowsetSharedPtr> rowsets;
+            {
+                std::shared_lock meta_rlock(_meta_lock);
+                rowsets = get_rowset_by_ids(&rowset_ids);
+            }
+            for (const auto& rowset : rowsets) {
+                rapidjson::Value value;
+                std::string version_str = rowset->get_rowset_info_str();
+                value.SetString(version_str.c_str(), version_str.length(),
+                                required_rowsets_arr.GetAllocator());
+                required_rowsets_arr.PushBack(value, 
required_rowsets_arr.GetAllocator());
+            }
+        }
+        for (const auto& missing_rowset_id : missing_ids) {
+            rapidjson::Value miss_value;
+            std::string rowset_id_str = missing_rowset_id.to_string();
+            miss_value.SetString(rowset_id_str.c_str(), rowset_id_str.length(),
+                                 missing_rowsets_arr.GetAllocator());
+            missing_rowsets_arr.PushBack(miss_value, 
missing_rowsets_arr.GetAllocator());
+        }
+
+        root.AddMember("required_rowsets", required_rowsets_arr, 
root.GetAllocator());
+        root.AddMember("missing_rowsets", missing_rowsets_arr, 
root.GetAllocator());
+        rapidjson::StringBuffer strbuf;
+        rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(strbuf);
+        root.Accept(writer);
+        std::string rowset_status_string = std::string(strbuf.GetString());
+        LOG_EVERY_SECOND(WARNING) << rowset_status_string;
+        // let it crash if correctness check failed in Debug mode
+        DCHECK(false) << "delete bitmap correctness check failed in publish 
phase!";
+        return Status::InternalError("check delete bitmap failed!");
+    }
+    return Status::OK();
+}
+
+void BaseTablet::_remove_sentinel_mark_from_delete_bitmap(DeleteBitmapPtr 
delete_bitmap) {
+    for (auto it = delete_bitmap->delete_bitmap.begin(), end = 
delete_bitmap->delete_bitmap.end();
+         it != end;) {
+        if (std::get<1>(it->first) == DeleteBitmap::INVALID_SEGMENT_ID) {
+            it = delete_bitmap->delete_bitmap.erase(it);
+        } else {
+            ++it;
+        }
+    }
+}
+
+Status BaseTablet::update_delete_bitmap(const BaseTabletSPtr& self, const 
TabletTxnInfo* txn_info,

Review Comment:
   warning: function 'update_delete_bitmap' exceeds recommended size/complexity 
thresholds [readability-function-size]
   ```cpp
   Status BaseTablet::update_delete_bitmap(const BaseTabletSPtr& self, const 
TabletTxnInfo* txn_info,
                      ^
   ```
   <details>
   <summary>Additional context</summary>
   
   **be/src/olap/base_tablet.cpp:1143:** 96 lines including whitespace and 
comments (threshold 80)
   ```cpp
   Status BaseTablet::update_delete_bitmap(const BaseTabletSPtr& self, const 
TabletTxnInfo* txn_info,
                      ^
   ```
   
   </details>
   



##########
be/src/cloud/cloud_engine_calc_delete_bitmap_task.cpp:
##########
@@ -0,0 +1,165 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "cloud/cloud_engine_calc_delete_bitmap_task.h"
+
+#include <memory>
+
+#include "cloud/cloud_meta_mgr.h"
+#include "cloud/cloud_tablet.h"
+#include "common/status.h"
+#include "olap/base_tablet.h"
+#include "olap/olap_common.h"
+#include "olap/rowset/rowset.h"
+#include "olap/tablet_fwd.h"
+#include "olap/tablet_meta.h"
+#include "olap/txn_manager.h"
+#include "olap/utils.h"
+
+namespace doris {
+
+CloudEngineCalcDeleteBitmapTask::CloudEngineCalcDeleteBitmapTask(
+        CloudStorageEngine& engine, const TCalcDeleteBitmapRequest& 
cal_delete_bitmap_req,
+        std::vector<TTabletId>* error_tablet_ids, std::vector<TTabletId>* 
succ_tablet_ids)
+        : _engine(engine),
+          _cal_delete_bitmap_req(cal_delete_bitmap_req),
+          _error_tablet_ids(error_tablet_ids),
+          _succ_tablet_ids(succ_tablet_ids) {}
+
+void CloudEngineCalcDeleteBitmapTask::add_error_tablet_id(int64_t tablet_id, 
const Status& err) {
+    std::lock_guard<std::mutex> lck(_mutex);
+    _error_tablet_ids->push_back(tablet_id);
+    if (_res.ok() || _res.is<ErrorCode::DELETE_BITMAP_LOCK_ERROR>()) {
+        _res = err;
+    }
+}
+
+void CloudEngineCalcDeleteBitmapTask::add_succ_tablet_id(int64_t tablet_id) {
+    std::lock_guard<std::mutex> lck(_mutex);
+    _succ_tablet_ids->push_back(tablet_id);
+}
+
+Status CloudEngineCalcDeleteBitmapTask::execute() {
+    int64_t transaction_id = _cal_delete_bitmap_req.transaction_id;
+    OlapStopWatch watch;
+    VLOG_NOTICE << "begin to calculate delete bitmap. transaction_id=" << 
transaction_id;
+    std::unique_ptr<ThreadPoolToken> token =
+            _engine.calc_tablet_delete_bitmap_task_thread_pool()->new_token(
+                    ThreadPool::ExecutionMode::CONCURRENT);
+
+    for (const auto& partition : _cal_delete_bitmap_req.partitions) {
+        int64_t version = partition.version;
+        for (auto tablet_id : partition.tablet_ids) {
+            auto base_tablet = DORIS_TRY(_engine.get_tablet(tablet_id));
+            std::shared_ptr<CloudTablet> tablet =
+                    std::dynamic_pointer_cast<CloudTablet>(base_tablet);
+            if (tablet == nullptr) {
+                LOG(WARNING) << "can't get tablet when calculate delete 
bitmap. tablet_id="
+                             << tablet_id;
+                _error_tablet_ids->push_back(tablet_id);
+                _res = Status::Error<ErrorCode::PUSH_TABLE_NOT_EXIST>(
+                        "can't get tablet when calculate delete bitmap. 
tablet_id={}", tablet_id);
+                break;
+            }
+
+            Status st = tablet->sync_rowsets();
+            if (!st.ok() && !st.is<ErrorCode::INVALID_TABLET_STATE>()) {
+                return st;
+            }
+            if (st.is<ErrorCode::INVALID_TABLET_STATE>()) [[unlikely]] {
+                add_succ_tablet_id(tablet->tablet_id());
+                LOG(INFO)
+                        << "tablet is under alter process, delete bitmap will 
be calculated later, "
+                           "tablet_id: "
+                        << tablet->tablet_id() << " txn_id: " << transaction_id
+                        << ", request_version=" << version;
+                continue;
+            }
+            int64_t max_version = tablet->max_version_unlocked();
+            if (version != max_version + 1) {
+                _error_tablet_ids->push_back(tablet_id);
+                _res = Status::Error<ErrorCode::DELETE_BITMAP_LOCK_ERROR, 
false>(
+                        "version not continuous");
+                LOG(WARNING) << "version not continuous, current max version=" 
<< max_version
+                             << ", request_version=" << version
+                             << " tablet_id=" << tablet->tablet_id();
+                break;
+            }
+
+            auto tablet_calc_delete_bitmap_ptr = 
std::make_shared<CloudTabletCalcDeleteBitmapTask>(
+                    _engine, this, tablet, transaction_id, version);
+            auto submit_st = token->submit_func([=]() { 
tablet_calc_delete_bitmap_ptr->handle(); });
+            CHECK(submit_st.ok());
+        }
+    }
+    // wait for all finished
+    token->wait();
+
+    LOG(INFO) << "finish to calculate delete bitmap on transaction."
+              << "transaction_id=" << transaction_id << ", cost(us): " << 
watch.get_elapse_time_us()
+              << ", error_tablet_size=" << _error_tablet_ids->size()
+              << ", res=" << _res.to_string();
+    return _res;
+}
+
+CloudTabletCalcDeleteBitmapTask::CloudTabletCalcDeleteBitmapTask(
+        CloudStorageEngine& engine, CloudEngineCalcDeleteBitmapTask* 
engine_task,
+        std::shared_ptr<CloudTablet> tablet, int64_t transaction_id, int64_t 
version)
+        : _engine(engine),
+          _engine_calc_delete_bitmap_task(engine_task),
+          _tablet(tablet),
+          _transaction_id(transaction_id),
+          _version(version) {}
+
+void CloudTabletCalcDeleteBitmapTask::handle() {

Review Comment:
   warning: method 'handle' can be made const 
[readability-make-member-function-const]
   
   ```suggestion
   void CloudTabletCalcDeleteBitmapTask::handle() const {
   ```
   
   be/src/cloud/cloud_engine_calc_delete_bitmap_task.h:39:
   ```diff
   -     void handle();
   +     void handle() const;
   ```
   



##########
be/src/cloud/cloud_engine_calc_delete_bitmap_task.cpp:
##########
@@ -0,0 +1,165 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "cloud/cloud_engine_calc_delete_bitmap_task.h"
+
+#include <memory>
+
+#include "cloud/cloud_meta_mgr.h"
+#include "cloud/cloud_tablet.h"
+#include "common/status.h"
+#include "olap/base_tablet.h"
+#include "olap/olap_common.h"
+#include "olap/rowset/rowset.h"
+#include "olap/tablet_fwd.h"
+#include "olap/tablet_meta.h"
+#include "olap/txn_manager.h"
+#include "olap/utils.h"
+
+namespace doris {
+
+CloudEngineCalcDeleteBitmapTask::CloudEngineCalcDeleteBitmapTask(
+        CloudStorageEngine& engine, const TCalcDeleteBitmapRequest& 
cal_delete_bitmap_req,
+        std::vector<TTabletId>* error_tablet_ids, std::vector<TTabletId>* 
succ_tablet_ids)
+        : _engine(engine),
+          _cal_delete_bitmap_req(cal_delete_bitmap_req),
+          _error_tablet_ids(error_tablet_ids),
+          _succ_tablet_ids(succ_tablet_ids) {}
+
+void CloudEngineCalcDeleteBitmapTask::add_error_tablet_id(int64_t tablet_id, 
const Status& err) {
+    std::lock_guard<std::mutex> lck(_mutex);
+    _error_tablet_ids->push_back(tablet_id);
+    if (_res.ok() || _res.is<ErrorCode::DELETE_BITMAP_LOCK_ERROR>()) {
+        _res = err;
+    }
+}
+
+void CloudEngineCalcDeleteBitmapTask::add_succ_tablet_id(int64_t tablet_id) {

Review Comment:
   warning: method 'add_succ_tablet_id' can be made static 
[readability-convert-member-functions-to-static]
   
   be/src/cloud/cloud_engine_calc_delete_bitmap_task.h:59:
   ```diff
   -     void add_succ_tablet_id(int64_t tablet_id);
   +     static void add_succ_tablet_id(int64_t tablet_id);
   ```
   



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to