Coverage Report

Created: 2026-03-13 05:13

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
#include "common/compile_check_begin.h"
36
Status OlapTabletFinder::find_tablets(RuntimeState* state, Block* block, int rows,
37
                                      std::vector<VOlapTablePartition*>& partitions,
38
                                      std::vector<uint32_t>& tablet_index, std::vector<bool>& skip,
39
41.0k
                                      std::vector<uint32_t>* miss_rows) {
40
37.3M
    for (int index = 0; index < rows; index++) {
41
37.3M
        _vpartition->find_partition(block, index, partitions[index]);
42
37.3M
    }
43
44
41.0k
    std::vector<uint32_t> qualified_rows;
45
41.0k
    qualified_rows.reserve(rows);
46
47
37.5M
    for (int row_index = 0; row_index < rows; row_index++) {
48
37.4M
        if (partitions[row_index] == nullptr) [[unlikely]] {
49
27.2k
            if (miss_rows != nullptr) {          // auto partition table
50
26.6k
                miss_rows->push_back(row_index); // already reserve memory outside
51
26.6k
                skip[row_index] = true;
52
26.6k
                continue;
53
26.6k
            }
54
529
            _num_filtered_rows++;
55
529
            _filter_bitmap.Set(row_index, true);
56
529
            skip[row_index] = true;
57
529
            RETURN_IF_ERROR(state->append_error_msg_to_file(
58
529
                    []() -> std::string { return ""; },
59
529
                    [&]() -> std::string {
60
529
                        fmt::memory_buffer buf;
61
529
                        fmt::format_to(buf, "no partition for this tuple. tuple={}",
62
529
                                       block->dump_data_json(row_index, 1));
63
529
                        return fmt::to_string(buf);
64
529
                    }));
65
528
            continue;
66
529
        }
67
37.4M
        if (!partitions[row_index]->is_mutable) [[unlikely]] {
68
12
            _num_immutable_partition_filtered_rows++;
69
12
            skip[row_index] = true;
70
12
            continue;
71
12
        }
72
37.4M
        if (partitions[row_index]->num_buckets <= 0) [[unlikely]] {
73
0
            std::stringstream ss;
74
0
            ss << "num_buckets must be greater than 0, num_buckets="
75
0
               << partitions[row_index]->num_buckets;
76
0
            return Status::InternalError(ss.str());
77
0
        }
78
79
37.4M
        _partition_ids.emplace(partitions[row_index]->id);
80
81
37.4M
        qualified_rows.push_back(row_index);
82
37.4M
    }
83
84
41.0k
    if (_find_tablet_mode == FindTabletMode::FIND_TABLET_EVERY_ROW) {
85
34.9k
        _vpartition->find_tablets(block, qualified_rows, partitions, tablet_index);
86
34.9k
    } else {
87
        // for random distribution
88
6.10k
        _vpartition->find_tablets(block, qualified_rows, partitions, tablet_index,
89
6.10k
                                  &_partition_to_tablet_map);
90
6.10k
        if (_find_tablet_mode == FindTabletMode::FIND_TABLET_EVERY_BATCH) {
91
6.20k
            for (auto it : _partition_to_tablet_map) {
92
                // do round-robin for next batch
93
6.20k
                if (it.first->load_tablet_idx != -1) {
94
6.20k
                    it.first->load_tablet_idx++;
95
6.20k
                }
96
6.20k
            }
97
6.10k
            _partition_to_tablet_map.clear();
98
6.10k
        }
99
6.10k
    }
100
101
41.0k
    return Status::OK();
102
41.0k
}
103
104
} // namespace doris