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


##########
be/src/cloud/cloud_engine_calc_delete_bitmap_task.cpp:
##########
@@ -0,0 +1,162 @@
+// 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/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:57:
   ```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/cloud/cloud_engine_calc_delete_bitmap_task.cpp:
##########
@@ -0,0 +1,162 @@
+// 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/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:58:
   ```diff
   -     void add_succ_tablet_id(int64_t tablet_id);
   +     static void add_succ_tablet_id(int64_t tablet_id);
   ```
   



##########
be/src/cloud/cloud_engine_calc_delete_bitmap_task.cpp:
##########
@@ -0,0 +1,162 @@
+// 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/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:38:
   ```diff
   -     void handle();
   +     void handle() const;
   ```
   



##########
be/src/cloud/cloud_tablet.cpp:
##########
@@ -443,4 +480,129 @@
     _cumulative_point = new_point;
 }
 
+Status CloudTablet::update_delete_bitmap(const std::shared_ptr<CloudTablet>& 
self,

Review Comment:
   warning: function 'update_delete_bitmap' exceeds recommended size/complexity 
thresholds [readability-function-size]
   ```cpp
   Status CloudTablet::update_delete_bitmap(const std::shared_ptr<CloudTablet>& 
self,
                       ^
   ```
   <details>
   <summary>Additional context</summary>
   
   **be/src/cloud/cloud_tablet.cpp:482:** 118 lines including whitespace and 
comments (threshold 80)
   ```cpp
   Status CloudTablet::update_delete_bitmap(const std::shared_ptr<CloudTablet>& 
self,
                       ^
   ```
   
   </details>
   



##########
be/src/cloud/cloud_tablet.cpp:
##########
@@ -443,4 +480,129 @@ void CloudTablet::set_cumulative_layer_point(int64_t 
new_point) {
     _cumulative_point = new_point;
 }
 
+Status CloudTablet::update_delete_bitmap(const std::shared_ptr<CloudTablet>& 
self,

Review Comment:
   warning: function 'update_delete_bitmap' has cognitive complexity of 59 
(threshold 50) [readability-function-cognitive-complexity]
   ```cpp
   Status CloudTablet::update_delete_bitmap(const std::shared_ptr<CloudTablet>& 
self,
                       ^
   ```
   <details>
   <summary>Additional context</summary>
   
   **be/src/cloud/cloud_tablet.cpp:499:** +1, including nesting penalty of 0, 
nesting level increased to 1
   ```cpp
       RETURN_IF_ERROR(beta_rowset->load_segments(&segments));
       ^
   ```
   **be/src/common/status.h:541:** expanded from macro 'RETURN_IF_ERROR'
   ```cpp
       do {                                \
       ^
   ```
   **be/src/cloud/cloud_tablet.cpp:499:** +2, including nesting penalty of 1, 
nesting level increased to 2
   ```cpp
       RETURN_IF_ERROR(beta_rowset->load_segments(&segments));
       ^
   ```
   **be/src/common/status.h:543:** expanded from macro 'RETURN_IF_ERROR'
   ```cpp
           if (UNLIKELY(!_status_.ok())) { \
           ^
   ```
   **be/src/cloud/cloud_tablet.cpp:505:** +1, including nesting penalty of 0, 
nesting level increased to 1
   ```cpp
           if (self->tablet_state() == TABLET_NOTREADY) {
           ^
   ```
   **be/src/cloud/cloud_tablet.cpp:510:** +1, including nesting penalty of 0, 
nesting level increased to 1
   ```cpp
           RETURN_IF_ERROR(self->get_all_rs_id_unlocked(cur_version - 1, 
&cur_rowset_ids));
           ^
   ```
   **be/src/common/status.h:541:** expanded from macro 'RETURN_IF_ERROR'
   ```cpp
       do {                                \
       ^
   ```
   **be/src/cloud/cloud_tablet.cpp:510:** +2, including nesting penalty of 1, 
nesting level increased to 2
   ```cpp
           RETURN_IF_ERROR(self->get_all_rs_id_unlocked(cur_version - 1, 
&cur_rowset_ids));
           ^
   ```
   **be/src/common/status.h:543:** expanded from macro 'RETURN_IF_ERROR'
   ```cpp
           if (UNLIKELY(!_status_.ok())) { \
           ^
   ```
   **be/src/cloud/cloud_tablet.cpp:529:** +1, including nesting penalty of 0, 
nesting level increased to 1
   ```cpp
       if (segments.size() <= 1) {
       ^
   ```
   **be/src/cloud/cloud_tablet.cpp:530:** +2, including nesting penalty of 1, 
nesting level increased to 2
   ```cpp
           RETURN_IF_ERROR(calc_delete_bitmap(self, rowset, segments, 
specified_rowsets, delete_bitmap,
           ^
   ```
   **be/src/common/status.h:541:** expanded from macro 'RETURN_IF_ERROR'
   ```cpp
       do {                                \
       ^
   ```
   **be/src/cloud/cloud_tablet.cpp:530:** +3, including nesting penalty of 2, 
nesting level increased to 3
   ```cpp
           RETURN_IF_ERROR(calc_delete_bitmap(self, rowset, segments, 
specified_rowsets, delete_bitmap,
           ^
   ```
   **be/src/common/status.h:543:** expanded from macro 'RETURN_IF_ERROR'
   ```cpp
           if (UNLIKELY(!_status_.ok())) { \
           ^
   ```
   **be/src/cloud/cloud_tablet.cpp:533:** +1, nesting level increased to 1
   ```cpp
       } else {
         ^
   ```
   **be/src/cloud/cloud_tablet.cpp:535:** +2, including nesting penalty of 1, 
nesting level increased to 2
   ```cpp
           RETURN_IF_ERROR(calc_delete_bitmap(self, rowset, segments, 
specified_rowsets, delete_bitmap,
           ^
   ```
   **be/src/common/status.h:541:** expanded from macro 'RETURN_IF_ERROR'
   ```cpp
       do {                                \
       ^
   ```
   **be/src/cloud/cloud_tablet.cpp:535:** +3, including nesting penalty of 2, 
nesting level increased to 3
   ```cpp
           RETURN_IF_ERROR(calc_delete_bitmap(self, rowset, segments, 
specified_rowsets, delete_bitmap,
           ^
   ```
   **be/src/common/status.h:543:** expanded from macro 'RETURN_IF_ERROR'
   ```cpp
           if (UNLIKELY(!_status_.ok())) { \
           ^
   ```
   **be/src/cloud/cloud_tablet.cpp:537:** +2, including nesting penalty of 1, 
nesting level increased to 2
   ```cpp
           RETURN_IF_ERROR(token->wait());
           ^
   ```
   **be/src/common/status.h:541:** expanded from macro 'RETURN_IF_ERROR'
   ```cpp
       do {                                \
       ^
   ```
   **be/src/cloud/cloud_tablet.cpp:537:** +3, including nesting penalty of 2, 
nesting level increased to 3
   ```cpp
           RETURN_IF_ERROR(token->wait());
           ^
   ```
   **be/src/common/status.h:543:** expanded from macro 'RETURN_IF_ERROR'
   ```cpp
           if (UNLIKELY(!_status_.ok())) { \
           ^
   ```
   **be/src/cloud/cloud_tablet.cpp:540:** +1, including nesting penalty of 0, 
nesting level increased to 1
   ```cpp
       if (watch.get_elapse_time_us() < 1 * 1000 * 1000) {
       ^
   ```
   **be/src/cloud/cloud_tablet.cpp:542:** +1, nesting level increased to 1
   ```cpp
       } else {
         ^
   ```
   **be/src/cloud/cloud_tablet.cpp:550:** nesting level increased to 1
   ```cpp
               [](size_t sum, const segment_v2::SegmentSharedPtr& s) { return 
sum += s->num_rows(); });
               ^
   ```
   **be/src/cloud/cloud_tablet.cpp:561:** +1, including nesting penalty of 0, 
nesting level increased to 1
   ```cpp
       if (config::enable_merge_on_write_correctness_check && 
rowset->num_rows() != 0) {
       ^
   ```
   **be/src/cloud/cloud_tablet.cpp:566:** +2, including nesting penalty of 1, 
nesting level increased to 2
   ```cpp
           if (!st.ok()) {
           ^
   ```
   **be/src/cloud/cloud_tablet.cpp:572:** +1, including nesting penalty of 0, 
nesting level increased to 1
   ```cpp
       if (partial_update_info && partial_update_info->is_partial_update &&
       ^
   ```
   **be/src/cloud/cloud_tablet.cpp:572:** +1
   ```cpp
       if (partial_update_info && partial_update_info->is_partial_update &&
                                                                         ^
   ```
   **be/src/cloud/cloud_tablet.cpp:574:** +2, including nesting penalty of 1, 
nesting level increased to 2
   ```cpp
           
DBUG_EXECUTE_IF("CloudTablet.update_delete_bitmap.partial_update_write_rowset_fail",
 {
           ^
   ```
   **be/src/util/debug_points.h:34:** expanded from macro 'DBUG_EXECUTE_IF'
   ```cpp
       if (UNLIKELY(config::enable_debug_points)) {                             
 \
       ^
   ```
   **be/src/cloud/cloud_tablet.cpp:574:** +3, including nesting penalty of 2, 
nesting level increased to 3
   ```cpp
           
DBUG_EXECUTE_IF("CloudTablet.update_delete_bitmap.partial_update_write_rowset_fail",
 {
           ^
   ```
   **be/src/util/debug_points.h:36:** expanded from macro 'DBUG_EXECUTE_IF'
   ```cpp
           if (dp) {                                                            
 \
           ^
   ```
   **be/src/cloud/cloud_tablet.cpp:575:** +4, including nesting penalty of 3, 
nesting level increased to 4
   ```cpp
               if (rand() % 100 < (100 * dp->param("percent", 0.5))) {
               ^
   ```
   **be/src/cloud/cloud_tablet.cpp:583:** +2, including nesting penalty of 1, 
nesting level increased to 2
   ```cpp
           RETURN_IF_ERROR(rowset_writer->flush());
           ^
   ```
   **be/src/common/status.h:541:** expanded from macro 'RETURN_IF_ERROR'
   ```cpp
       do {                                \
       ^
   ```
   **be/src/cloud/cloud_tablet.cpp:583:** +3, including nesting penalty of 2, 
nesting level increased to 3
   ```cpp
           RETURN_IF_ERROR(rowset_writer->flush());
           ^
   ```
   **be/src/common/status.h:543:** expanded from macro 'RETURN_IF_ERROR'
   ```cpp
           if (UNLIKELY(!_status_.ok())) { \
           ^
   ```
   **be/src/cloud/cloud_tablet.cpp:585:** +2, including nesting penalty of 1, 
nesting level increased to 2
   ```cpp
           RETURN_IF_ERROR(rowset_writer->build(transient_rowset));
           ^
   ```
   **be/src/common/status.h:541:** expanded from macro 'RETURN_IF_ERROR'
   ```cpp
       do {                                \
       ^
   ```
   **be/src/cloud/cloud_tablet.cpp:585:** +3, including nesting penalty of 2, 
nesting level increased to 3
   ```cpp
           RETURN_IF_ERROR(rowset_writer->build(transient_rowset));
           ^
   ```
   **be/src/common/status.h:543:** expanded from macro 'RETURN_IF_ERROR'
   ```cpp
           if (UNLIKELY(!_status_.ok())) { \
           ^
   ```
   **be/src/cloud/cloud_tablet.cpp:588:** +2, including nesting penalty of 1, 
nesting level increased to 2
   ```cpp
           
RETURN_IF_ERROR(self->_engine.meta_mgr().update_tmp_rowset(*rowset_meta));
           ^
   ```
   **be/src/common/status.h:541:** expanded from macro 'RETURN_IF_ERROR'
   ```cpp
       do {                                \
       ^
   ```
   **be/src/cloud/cloud_tablet.cpp:588:** +3, including nesting penalty of 2, 
nesting level increased to 3
   ```cpp
           
RETURN_IF_ERROR(self->_engine.meta_mgr().update_tmp_rowset(*rowset_meta));
           ^
   ```
   **be/src/common/status.h:543:** expanded from macro 'RETURN_IF_ERROR'
   ```cpp
           if (UNLIKELY(!_status_.ok())) { \
           ^
   ```
   **be/src/cloud/cloud_tablet.cpp:595:** +1, including nesting penalty of 0, 
nesting level increased to 1
   ```cpp
       for (auto iter = delete_bitmap->delete_bitmap.begin();
       ^
   ```
   **be/src/cloud/cloud_tablet.cpp:601:** +1, including nesting penalty of 0, 
nesting level increased to 1
   ```cpp
       RETURN_IF_ERROR(self->_engine.meta_mgr().update_delete_bitmap(
       ^
   ```
   **be/src/common/status.h:541:** expanded from macro 'RETURN_IF_ERROR'
   ```cpp
       do {                                \
       ^
   ```
   **be/src/cloud/cloud_tablet.cpp:601:** +2, including nesting penalty of 1, 
nesting level increased to 2
   ```cpp
       RETURN_IF_ERROR(self->_engine.meta_mgr().update_delete_bitmap(
       ^
   ```
   **be/src/common/status.h:543:** expanded from macro 'RETURN_IF_ERROR'
   ```cpp
           if (UNLIKELY(!_status_.ok())) { \
           ^
   ```
   
   </details>
   



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