Coverage Report

Created: 2026-07-08 18:37

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 <algorithm>
26
#include <string>
27
#include <utility>
28
29
#include "common/compiler_util.h" // IWYU pragma: keep
30
#include "common/status.h"
31
#include "core/block/block.h"
32
#include "runtime/runtime_state.h"
33
#include "storage/tablet_info.h"
34
35
namespace doris {
36
37
Status OlapTabletFinder::find_tablets(RuntimeState* state, Block* block, int rows,
38
                                      std::vector<VOlapTablePartition*>& partitions,
39
                                      std::vector<uint32_t>& tablet_index, std::vector<bool>& skip,
40
38.3k
                                      std::vector<uint32_t>* miss_rows) {
41
35.8M
    for (int index = 0; index < rows; index++) {
42
35.8M
        _vpartition->find_partition(block, index, partitions[index]);
43
35.8M
    }
44
45
38.3k
    std::vector<uint32_t> qualified_rows;
46
38.3k
    qualified_rows.reserve(rows);
47
48
35.9M
    for (int row_index = 0; row_index < rows; row_index++) {
49
35.9M
        if (partitions[row_index] == nullptr) [[unlikely]] {
50
37.7k
            if (miss_rows != nullptr) {          // auto partition table
51
37.2k
                miss_rows->push_back(row_index); // already reserve memory outside
52
37.2k
                skip[row_index] = true;
53
37.2k
                continue;
54
37.2k
            }
55
547
            _num_filtered_rows++;
56
547
            _filter_bitmap.Set(row_index, true);
57
547
            skip[row_index] = true;
58
547
            RETURN_IF_ERROR(state->append_error_msg_to_file(
59
547
                    []() -> std::string { return ""; },
60
547
                    [&]() -> std::string {
61
547
                        fmt::memory_buffer buf;
62
547
                        fmt::format_to(buf, "no partition for this tuple. tuple={}",
63
547
                                       block->dump_data_json(row_index, 1));
64
547
                        return fmt::to_string(buf);
65
547
                    }));
66
546
            continue;
67
547
        }
68
35.8M
        if (!partitions[row_index]->is_mutable) [[unlikely]] {
69
12
            _num_immutable_partition_filtered_rows++;
70
12
            skip[row_index] = true;
71
12
            continue;
72
12
        }
73
35.8M
        if (partitions[row_index]->num_buckets <= 0) [[unlikely]] {
74
0
            std::stringstream ss;
75
0
            ss << "num_buckets must be greater than 0, num_buckets="
76
0
               << partitions[row_index]->num_buckets;
77
0
            return Status::InternalError(ss.str());
78
0
        }
79
80
35.8M
        _partition_ids.emplace(partitions[row_index]->id);
81
82
35.8M
        qualified_rows.push_back(row_index);
83
35.8M
    }
84
85
38.2k
    if (_find_tablet_mode == FindTabletMode::FIND_TABLET_EVERY_ROW) {
86
33.0k
        _vpartition->find_tablets(block, qualified_rows, partitions, tablet_index);
87
33.0k
    } else if (_find_tablet_mode == FindTabletMode::FIND_TABLET_RANDOM_BUCKET) {
88
        // Adaptive random bucket mode only needs partition ids on sender side.
89
        // The receiver decides the concrete tablet from its local ordered tablet list.
90
5.22k
    } else {
91
        // FIND_TABLET_EVERY_BATCH / FIND_TABLET_EVERY_SINK
92
10
        _vpartition->find_tablets(block, qualified_rows, partitions, tablet_index,
93
10
                                  &_partition_to_tablet_map);
94
10
        if (_find_tablet_mode == FindTabletMode::FIND_TABLET_EVERY_BATCH) {
95
3
            for (auto it : _partition_to_tablet_map) {
96
                // do round-robin for next batch
97
3
                if (it.first->load_tablet_idx != -1) {
98
3
                    it.first->load_tablet_idx++;
99
3
                }
100
3
            }
101
3
            _partition_to_tablet_map.clear();
102
3
        }
103
10
    }
104
105
38.2k
    return Status::OK();
106
38.3k
}
107
108
} // namespace doris