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 | 2.97k | std::vector<uint32_t>* miss_rows) { |
40 | 137k | for (int index = 0; index < rows; index++) { |
41 | 134k | _vpartition->find_partition(block, index, partitions[index]); |
42 | 134k | } |
43 | | |
44 | 2.97k | std::vector<uint32_t> qualified_rows; |
45 | 2.97k | qualified_rows.reserve(rows); |
46 | | |
47 | 137k | for (int row_index = 0; row_index < rows; row_index++) { |
48 | 134k | if (partitions[row_index] == nullptr) [[unlikely]] { |
49 | 14 | if (miss_rows != nullptr) { // auto partition table |
50 | 10 | miss_rows->push_back(row_index); // already reserve memory outside |
51 | 10 | skip[row_index] = true; |
52 | 10 | continue; |
53 | 10 | } |
54 | 4 | _num_filtered_rows++; |
55 | 4 | _filter_bitmap.Set(row_index, true); |
56 | 4 | skip[row_index] = true; |
57 | 4 | RETURN_IF_ERROR(state->append_error_msg_to_file( |
58 | 4 | []() -> std::string { return ""; }, |
59 | 4 | [&]() -> std::string { |
60 | 4 | fmt::memory_buffer buf; |
61 | 4 | fmt::format_to(buf, "no partition for this tuple. tuple={}", |
62 | 4 | block->dump_data_json(row_index, 1)); |
63 | 4 | return fmt::to_string(buf); |
64 | 4 | })); |
65 | 4 | continue; |
66 | 4 | } |
67 | 134k | if (!partitions[row_index]->is_mutable) [[unlikely]] { |
68 | 2 | _num_immutable_partition_filtered_rows++; |
69 | 2 | skip[row_index] = true; |
70 | 2 | continue; |
71 | 2 | } |
72 | 134k | 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 | 134k | _partition_ids.emplace(partitions[row_index]->id); |
80 | | |
81 | 134k | qualified_rows.push_back(row_index); |
82 | 134k | } |
83 | | |
84 | 2.97k | if (_find_tablet_mode == FindTabletMode::FIND_TABLET_EVERY_ROW) { |
85 | 2.19k | _vpartition->find_tablets(block, qualified_rows, partitions, tablet_index); |
86 | 2.19k | } else { |
87 | | // for random distribution |
88 | 785 | _vpartition->find_tablets(block, qualified_rows, partitions, tablet_index, |
89 | 785 | &_partition_to_tablet_map); |
90 | 785 | if (_find_tablet_mode == FindTabletMode::FIND_TABLET_EVERY_BATCH) { |
91 | 785 | for (auto it : _partition_to_tablet_map) { |
92 | | // do round-robin for next batch |
93 | 785 | if (it.first->load_tablet_idx != -1) { |
94 | 785 | it.first->load_tablet_idx++; |
95 | 785 | } |
96 | 785 | } |
97 | 785 | _partition_to_tablet_map.clear(); |
98 | 785 | } |
99 | 785 | } |
100 | | |
101 | 2.97k | return Status::OK(); |
102 | 2.97k | } |
103 | | |
104 | | } // namespace doris |