Coverage Report

Created: 2026-04-15 11:06

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exec/sink/vtablet_finder.cpp
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
#include "exec/sink/vtablet_finder.h"
19
20
#include <fmt/format.h>
21
#include <gen_cpp/Exprs_types.h>
22
#include <gen_cpp/FrontendService_types.h>
23
#include <glog/logging.h>
24
25
#include <string>
26
#include <utility>
27
28
#include "common/compiler_util.h" // IWYU pragma: keep
29
#include "common/status.h"
30
#include "core/block/block.h"
31
#include "runtime/runtime_state.h"
32
#include "storage/tablet_info.h"
33
34
namespace doris {
35
Status OlapTabletFinder::find_tablets(RuntimeState* state, Block* block, int rows,
36
                                      std::vector<VOlapTablePartition*>& partitions,
37
                                      std::vector<uint32_t>& tablet_index, std::vector<bool>& skip,
38
39.4k
                                      std::vector<uint32_t>* miss_rows) {
39
35.5M
    for (int index = 0; index < rows; index++) {
40
35.5M
        _vpartition->find_partition(block, index, partitions[index]);
41
35.5M
    }
42
43
39.4k
    std::vector<uint32_t> qualified_rows;
44
39.4k
    qualified_rows.reserve(rows);
45
46
35.6M
    for (int row_index = 0; row_index < rows; row_index++) {
47
35.6M
        if (partitions[row_index] == nullptr) [[unlikely]] {
48
27.2k
            if (miss_rows != nullptr) {          // auto partition table
49
26.6k
                miss_rows->push_back(row_index); // already reserve memory outside
50
26.6k
                skip[row_index] = true;
51
26.6k
                continue;
52
26.6k
            }
53
538
            _num_filtered_rows++;
54
538
            _filter_bitmap.Set(row_index, true);
55
538
            skip[row_index] = true;
56
538
            RETURN_IF_ERROR(state->append_error_msg_to_file(
57
538
                    []() -> std::string { return ""; },
58
538
                    [&]() -> std::string {
59
538
                        fmt::memory_buffer buf;
60
538
                        fmt::format_to(buf, "no partition for this tuple. tuple={}",
61
538
                                       block->dump_data_json(row_index, 1));
62
538
                        return fmt::to_string(buf);
63
538
                    }));
64
537
            continue;
65
538
        }
66
35.5M
        if (!partitions[row_index]->is_mutable) [[unlikely]] {
67
12
            _num_immutable_partition_filtered_rows++;
68
12
            skip[row_index] = true;
69
12
            continue;
70
12
        }
71
35.5M
        if (partitions[row_index]->num_buckets <= 0) [[unlikely]] {
72
0
            std::stringstream ss;
73
0
            ss << "num_buckets must be greater than 0, num_buckets="
74
0
               << partitions[row_index]->num_buckets;
75
0
            return Status::InternalError(ss.str());
76
0
        }
77
78
35.5M
        _partition_ids.emplace(partitions[row_index]->id);
79
80
35.5M
        qualified_rows.push_back(row_index);
81
35.5M
    }
82
83
39.4k
    if (_find_tablet_mode == FindTabletMode::FIND_TABLET_EVERY_ROW) {
84
33.7k
        _vpartition->find_tablets(block, qualified_rows, partitions, tablet_index);
85
33.7k
    } else {
86
        // for random distribution
87
5.74k
        _vpartition->find_tablets(block, qualified_rows, partitions, tablet_index,
88
5.74k
                                  &_partition_to_tablet_map);
89
5.74k
        if (_find_tablet_mode == FindTabletMode::FIND_TABLET_EVERY_BATCH) {
90
5.84k
            for (auto it : _partition_to_tablet_map) {
91
                // do round-robin for next batch
92
5.84k
                if (it.first->load_tablet_idx != -1) {
93
5.84k
                    it.first->load_tablet_idx++;
94
5.84k
                }
95
5.84k
            }
96
5.74k
            _partition_to_tablet_map.clear();
97
5.74k
        }
98
5.74k
    }
99
100
39.4k
    return Status::OK();
101
39.4k
}
102
103
} // namespace doris