Coverage Report

Created: 2026-07-09 03:38

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
44.9k
                                      std::vector<uint32_t>* miss_rows) {
41
36.0M
    for (int index = 0; index < rows; index++) {
42
36.0M
        _vpartition->find_partition(block, index, partitions[index]);
43
36.0M
    }
44
45
44.9k
    std::vector<uint32_t> qualified_rows;
46
44.9k
    qualified_rows.reserve(rows);
47
48
36.1M
    for (int row_index = 0; row_index < rows; row_index++) {
49
36.1M
        if (partitions[row_index] == nullptr) [[unlikely]] {
50
30.7k
            if (miss_rows != nullptr) {          // auto partition table
51
29.5k
                miss_rows->push_back(row_index); // already reserve memory outside
52
29.5k
                skip[row_index] = true;
53
29.5k
                continue;
54
29.5k
            }
55
1.16k
            _num_filtered_rows++;
56
1.16k
            _filter_bitmap.Set(row_index, true);
57
1.16k
            skip[row_index] = true;
58
1.16k
            RETURN_IF_ERROR(state->append_error_msg_to_file(
59
1.16k
                    []() -> std::string { return ""; },
60
1.16k
                    [&]() -> std::string {
61
1.16k
                        fmt::memory_buffer buf;
62
1.16k
                        fmt::format_to(buf, "no partition for this tuple. tuple={}",
63
1.16k
                                       block->dump_data_json(row_index, 1));
64
1.16k
                        return fmt::to_string(buf);
65
1.16k
                    }));
66
1.16k
            continue;
67
1.16k
        }
68
36.1M
        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
36.1M
        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
36.1M
        _partition_ids.emplace(partitions[row_index]->id);
81
82
36.1M
        qualified_rows.push_back(row_index);
83
36.1M
    }
84
85
44.9k
    if (_find_tablet_mode == FindTabletMode::FIND_TABLET_EVERY_ROW) {
86
39.0k
        _vpartition->find_tablets(block, qualified_rows, partitions, tablet_index);
87
39.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.20k
    } else {
91
        // FIND_TABLET_EVERY_BATCH / FIND_TABLET_EVERY_SINK
92
732
        _vpartition->find_tablets(block, qualified_rows, partitions, tablet_index,
93
732
                                  &_partition_to_tablet_map);
94
735
        if (_find_tablet_mode == FindTabletMode::FIND_TABLET_EVERY_BATCH) {
95
735
            for (auto it : _partition_to_tablet_map) {
96
                // do round-robin for next batch
97
735
                if (it.first->load_tablet_idx != -1) {
98
735
                    it.first->load_tablet_idx++;
99
735
                }
100
735
            }
101
735
            _partition_to_tablet_map.clear();
102
735
        }
103
732
    }
104
105
44.9k
    return Status::OK();
106
44.9k
}
107
108
} // namespace doris