This is an automated email from the ASF dual-hosted git repository.

dataroaring pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 362efda9fd3 [chore](static-check) Add some cast checks for files under 
dir be/src/olap/ (#44398)
362efda9fd3 is described below

commit 362efda9fd3929062c7c2ea8aa2ab4c456bdb10d
Author: Siyang Tang <tangsiy...@selectdb.com>
AuthorDate: Sat Nov 23 10:52:32 2024 +0800

    [chore](static-check) Add some cast checks for files under dir be/src/olap/ 
(#44398)
    
    ### What problem does this PR solve?
    
    Issue Number: related #44400
---
 be/src/common/cast_set.h                    | 12 +++++++++++
 be/src/http/action/calc_file_crc_action.cpp |  4 ++--
 be/src/http/action/calc_file_crc_action.h   |  2 +-
 be/src/olap/base_compaction.cpp             |  6 +++++-
 be/src/olap/base_tablet.cpp                 | 32 +++++++++++++++++++----------
 be/src/olap/base_tablet.h                   |  2 +-
 6 files changed, 42 insertions(+), 16 deletions(-)

diff --git a/be/src/common/cast_set.h b/be/src/common/cast_set.h
index 08a9c8fbb7e..dcc744d8122 100644
--- a/be/src/common/cast_set.h
+++ b/be/src/common/cast_set.h
@@ -61,6 +61,12 @@ void cast_set(T& a, U b) {
     a = static_cast<T>(b);
 }
 
+template <typename T, typename U>
+    requires std::is_floating_point_v<T> and std::is_integral_v<U>
+void cast_set(T& a, U b) {
+    a = static_cast<T>(b);
+}
+
 template <typename T, typename U, bool need_check_value = true>
     requires std::is_integral_v<T> && std::is_integral_v<U>
 T cast_set(U b) {
@@ -70,4 +76,10 @@ T cast_set(U b) {
     return static_cast<T>(b);
 }
 
+template <typename T, typename U>
+    requires std::is_floating_point_v<T> and std::is_integral_v<U>
+T cast_set(U b) {
+    return static_cast<T>(b);
+}
+
 } // namespace doris
diff --git a/be/src/http/action/calc_file_crc_action.cpp 
b/be/src/http/action/calc_file_crc_action.cpp
index 66ec96a2a9a..123f55dd7fd 100644
--- a/be/src/http/action/calc_file_crc_action.cpp
+++ b/be/src/http/action/calc_file_crc_action.cpp
@@ -46,7 +46,7 @@ CalcFileCrcAction::CalcFileCrcAction(ExecEnv* exec_env, 
BaseStorageEngine& engin
 // calculate the crc value of the files in the tablet
 Status CalcFileCrcAction::_handle_calc_crc(HttpRequest* req, uint32_t* 
crc_value,
                                            int64_t* start_version, int64_t* 
end_version,
-                                           int32_t* rowset_count, int64_t* 
file_count) {
+                                           uint32_t* rowset_count, int64_t* 
file_count) {
     uint64_t tablet_id = 0;
     const auto& req_tablet_id = req->param(TABLET_ID_KEY);
     if (req_tablet_id.empty()) {
@@ -110,7 +110,7 @@ void CalcFileCrcAction::handle(HttpRequest* req) {
     uint32_t crc_value = 0;
     int64_t start_version = 0;
     int64_t end_version = 0;
-    int32_t rowset_count = 0;
+    uint32_t rowset_count = 0;
     int64_t file_count = 0;
 
     MonotonicStopWatch timer;
diff --git a/be/src/http/action/calc_file_crc_action.h 
b/be/src/http/action/calc_file_crc_action.h
index 30df8bfe629..ea5fb894957 100644
--- a/be/src/http/action/calc_file_crc_action.h
+++ b/be/src/http/action/calc_file_crc_action.h
@@ -44,7 +44,7 @@ public:
 
 private:
     Status _handle_calc_crc(HttpRequest* req, uint32_t* crc_value, int64_t* 
start_version,
-                            int64_t* end_version, int32_t* rowset_count, 
int64_t* file_count);
+                            int64_t* end_version, uint32_t* rowset_count, 
int64_t* file_count);
 
 private:
     BaseStorageEngine& _engine;
diff --git a/be/src/olap/base_compaction.cpp b/be/src/olap/base_compaction.cpp
index 8b9cbd75ed3..9e428f27b0b 100644
--- a/be/src/olap/base_compaction.cpp
+++ b/be/src/olap/base_compaction.cpp
@@ -23,6 +23,7 @@
 #include <mutex>
 #include <ostream>
 
+#include "common/cast_set.h"
 #include "common/config.h"
 #include "common/logging.h"
 #include "olap/compaction.h"
@@ -35,6 +36,8 @@
 #include "util/trace.h"
 
 namespace doris {
+#include "common/compile_check_begin.h"
+
 using namespace ErrorCode;
 
 BaseCompaction::BaseCompaction(StorageEngine& engine, const TabletSharedPtr& 
tablet)
@@ -184,7 +187,8 @@ Status BaseCompaction::pick_rowsets_to_compact() {
         // set to 1 to void divide by zero
         base_size = 1;
     }
-    double cumulative_base_ratio = static_cast<double>(cumulative_total_size) 
/ base_size;
+    double cumulative_base_ratio =
+            cast_set<double>(cumulative_total_size) / 
cast_set<double>(base_size);
 
     if (cumulative_base_ratio > min_data_ratio) {
         VLOG_NOTICE << "satisfy the base compaction policy. tablet=" << 
_tablet->tablet_id()
diff --git a/be/src/olap/base_tablet.cpp b/be/src/olap/base_tablet.cpp
index 89886ec8b4b..2e70e4586cc 100644
--- a/be/src/olap/base_tablet.cpp
+++ b/be/src/olap/base_tablet.cpp
@@ -20,6 +20,10 @@
 #include <fmt/format.h>
 #include <rapidjson/prettywriter.h>
 
+#include <cstdint>
+#include <iterator>
+
+#include "common/cast_set.h"
 #include "common/logging.h"
 #include "common/status.h"
 #include "olap/calc_delete_bitmap_executor.h"
@@ -45,6 +49,8 @@
 #include "vec/jsonb/serialize.h"
 
 namespace doris {
+#include "common/compile_check_begin.h"
+
 using namespace ErrorCode;
 
 namespace {
@@ -462,9 +468,9 @@ Status BaseTablet::lookup_row_key(const Slice& encoded_key, 
TabletSchema* latest
     RowLocation loc;
 
     for (size_t i = 0; i < specified_rowsets.size(); i++) {
-        auto& rs = specified_rowsets[i];
-        auto& segments_key_bounds = 
rs->rowset_meta()->get_segments_key_bounds();
-        int num_segments = rs->num_segments();
+        const auto& rs = specified_rowsets[i];
+        const auto& segments_key_bounds = 
rs->rowset_meta()->get_segments_key_bounds();
+        int num_segments = cast_set<int>(rs->num_segments());
         DCHECK_EQ(segments_key_bounds.size(), num_segments);
         std::vector<uint32_t> picked_segments;
         for (int i = num_segments - 1; i >= 0; i--) {
@@ -671,7 +677,8 @@ Status 
BaseTablet::calc_segment_delete_bitmap(RowsetSharedPtr rowset,
 
             RowsetSharedPtr rowset_find;
             auto st = lookup_row_key(key, rowset_schema.get(), true, 
specified_rowsets, &loc,
-                                     dummy_version.first - 1, segment_caches, 
&rowset_find);
+                                     cast_set<uint32_t>(dummy_version.first - 
1), segment_caches,
+                                     &rowset_find);
             bool expected_st = st.ok() || st.is<KEY_NOT_FOUND>() || 
st.is<KEY_ALREADY_EXISTS>();
             // It's a defensive DCHECK, we need to exclude some common errors 
to avoid core-dump
             // while stress test
@@ -1130,7 +1137,7 @@ Status 
BaseTablet::generate_new_block_for_flexible_partial_update(
                                            const signed char* 
delete_sign_column_data) {
         if (skipped) {
             if (delete_sign_column_data != nullptr &&
-                delete_sign_column_data[read_index_old[idx]] != 0) {
+                
delete_sign_column_data[read_index_old[cast_set<uint32_t>(idx)]] != 0) {
                 if (tablet_column.has_default_value()) {
                     new_col->insert_from(default_value_col, 0);
                 } else if (tablet_column.is_nullable()) {
@@ -1300,7 +1307,8 @@ Status 
BaseTablet::check_delete_bitmap_correctness(DeleteBitmapPtr delete_bitmap
             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(),
+                value.SetString(version_str.c_str(),
+                                
cast_set<rapidjson::SizeType>(version_str.length()),
                                 required_rowsets_arr.GetAllocator());
                 required_rowsets_arr.PushBack(value, 
required_rowsets_arr.GetAllocator());
             }
@@ -1313,7 +1321,8 @@ Status 
BaseTablet::check_delete_bitmap_correctness(DeleteBitmapPtr delete_bitmap
             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(),
+                value.SetString(version_str.c_str(),
+                                
cast_set<rapidjson::SizeType>(version_str.length()),
                                 required_rowsets_arr.GetAllocator());
                 required_rowsets_arr.PushBack(value, 
required_rowsets_arr.GetAllocator());
             }
@@ -1321,7 +1330,8 @@ Status 
BaseTablet::check_delete_bitmap_correctness(DeleteBitmapPtr delete_bitmap
         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(),
+            miss_value.SetString(rowset_id_str.c_str(),
+                                 
cast_set<rapidjson::SizeType>(rowset_id_str.length()),
                                  missing_rowsets_arr.GetAllocator());
             missing_rowsets_arr.PushBack(miss_value, 
missing_rowsets_arr.GetAllocator());
         }
@@ -1725,7 +1735,7 @@ std::vector<RowsetSharedPtr> 
BaseTablet::get_snapshot_rowset(bool include_stale_
 void BaseTablet::calc_consecutive_empty_rowsets(
         std::vector<RowsetSharedPtr>* empty_rowsets,
         const std::vector<RowsetSharedPtr>& candidate_rowsets, int limit) {
-    int len = candidate_rowsets.size();
+    int len = cast_set<int>(candidate_rowsets.size());
     for (int i = 0; i < len - 1; ++i) {
         auto rowset = candidate_rowsets[i];
         auto next_rowset = candidate_rowsets[i + 1];
@@ -1761,7 +1771,7 @@ void BaseTablet::calc_consecutive_empty_rowsets(
 }
 
 Status BaseTablet::calc_file_crc(uint32_t* crc_value, int64_t start_version, 
int64_t end_version,
-                                 int32_t* rowset_count, int64_t* file_count) {
+                                 uint32_t* rowset_count, int64_t* file_count) {
     Version v(start_version, end_version);
     std::vector<RowsetSharedPtr> rowsets;
     traverse_rowsets([&rowsets, &v](const auto& rs) {
@@ -1771,7 +1781,7 @@ Status BaseTablet::calc_file_crc(uint32_t* crc_value, 
int64_t start_version, int
         }
     });
     std::sort(rowsets.begin(), rowsets.end(), Rowset::comparator);
-    *rowset_count = rowsets.size();
+    *rowset_count = cast_set<uint32_t>(rowsets.size());
 
     *crc_value = 0;
     *file_count = 0;
diff --git a/be/src/olap/base_tablet.h b/be/src/olap/base_tablet.h
index b5da0e3bf06..b6fc953e460 100644
--- a/be/src/olap/base_tablet.h
+++ b/be/src/olap/base_tablet.h
@@ -289,7 +289,7 @@ public:
     }
 
     Status calc_file_crc(uint32_t* crc_value, int64_t start_version, int64_t 
end_version,
-                         int32_t* rowset_count, int64_t* file_count);
+                         uint32_t* rowset_count, int64_t* file_count);
 
     Status show_nested_index_file(std::string* json_meta);
 


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

Reply via email to