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