/root/doris/be/src/exec/rowid_fetcher.cpp
Line | Count | Source (jump to first uncovered line) |
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/rowid_fetcher.h" |
19 | | |
20 | | #include <brpc/callback.h> |
21 | | #include <butil/endpoint.h> |
22 | | #include <fmt/format.h> |
23 | | #include <gen_cpp/data.pb.h> |
24 | | #include <gen_cpp/internal_service.pb.h> |
25 | | #include <gen_cpp/olap_file.pb.h> |
26 | | #include <gen_cpp/types.pb.h> |
27 | | #include <glog/logging.h> |
28 | | #include <stddef.h> |
29 | | #include <stdint.h> |
30 | | |
31 | | #include <algorithm> |
32 | | #include <cstdint> |
33 | | #include <memory> |
34 | | #include <ostream> |
35 | | #include <string> |
36 | | #include <unordered_map> |
37 | | #include <utility> |
38 | | #include <vector> |
39 | | |
40 | | #include "bthread/countdown_event.h" |
41 | | #include "cloud/cloud_storage_engine.h" |
42 | | #include "cloud/cloud_tablet.h" |
43 | | #include "cloud/cloud_tablet_mgr.h" |
44 | | #include "cloud/config.h" |
45 | | #include "common/config.h" |
46 | | #include "common/consts.h" |
47 | | #include "common/exception.h" |
48 | | #include "exec/tablet_info.h" // DorisNodesInfo |
49 | | #include "olap/olap_common.h" |
50 | | #include "olap/rowset/beta_rowset.h" |
51 | | #include "olap/storage_engine.h" |
52 | | #include "olap/tablet_fwd.h" |
53 | | #include "olap/tablet_manager.h" |
54 | | #include "olap/tablet_schema.h" |
55 | | #include "olap/utils.h" |
56 | | #include "runtime/descriptors.h" |
57 | | #include "runtime/exec_env.h" // ExecEnv |
58 | | #include "runtime/runtime_state.h" // RuntimeState |
59 | | #include "runtime/types.h" |
60 | | #include "util/brpc_client_cache.h" // BrpcClientCache |
61 | | #include "util/defer_op.h" |
62 | | #include "vec/columns/column.h" |
63 | | #include "vec/columns/column_nullable.h" |
64 | | #include "vec/columns/column_string.h" |
65 | | #include "vec/common/assert_cast.h" |
66 | | #include "vec/common/string_ref.h" |
67 | | #include "vec/core/block.h" // Block |
68 | | #include "vec/data_types/data_type_factory.hpp" |
69 | | #include "vec/data_types/serde/data_type_serde.h" |
70 | | #include "vec/jsonb/serialize.h" |
71 | | |
72 | | namespace doris { |
73 | | |
74 | 0 | Status RowIDFetcher::init() { |
75 | 0 | DorisNodesInfo nodes_info; |
76 | 0 | nodes_info.setNodes(_fetch_option.t_fetch_opt.nodes_info); |
77 | 0 | for (auto [node_id, node_info] : nodes_info.nodes_info()) { |
78 | 0 | auto client = ExecEnv::GetInstance()->brpc_internal_client_cache()->get_client( |
79 | 0 | node_info.host, node_info.brpc_port); |
80 | 0 | if (!client) { |
81 | 0 | LOG(WARNING) << "Get rpc stub failed, host=" << node_info.host |
82 | 0 | << ", port=" << node_info.brpc_port; |
83 | 0 | return Status::InternalError("RowIDFetcher failed to init rpc client, host={}, port={}", |
84 | 0 | node_info.host, node_info.brpc_port); |
85 | 0 | } |
86 | 0 | _stubs.push_back(client); |
87 | 0 | } |
88 | 0 | return Status::OK(); |
89 | 0 | } |
90 | | |
91 | 0 | PMultiGetRequest RowIDFetcher::_init_fetch_request(const vectorized::ColumnString& row_locs) const { |
92 | 0 | PMultiGetRequest mget_req; |
93 | 0 | _fetch_option.desc->to_protobuf(mget_req.mutable_desc()); |
94 | 0 | for (SlotDescriptor* slot : _fetch_option.desc->slots()) { |
95 | | // ignore rowid |
96 | 0 | if (slot->col_name() == BeConsts::ROWID_COL) { |
97 | 0 | continue; |
98 | 0 | } |
99 | 0 | slot->to_protobuf(mget_req.add_slots()); |
100 | 0 | } |
101 | 0 | for (size_t i = 0; i < row_locs.size(); ++i) { |
102 | 0 | PRowLocation row_loc; |
103 | 0 | StringRef row_id_rep = row_locs.get_data_at(i); |
104 | | // TODO: When transferring data between machines with different byte orders (endianness), |
105 | | // not performing proper handling may lead to issues in parsing and exchanging the data. |
106 | 0 | auto location = reinterpret_cast<const GlobalRowLoacation*>(row_id_rep.data); |
107 | 0 | row_loc.set_tablet_id(location->tablet_id); |
108 | 0 | row_loc.set_rowset_id(location->row_location.rowset_id.to_string()); |
109 | 0 | row_loc.set_segment_id(location->row_location.segment_id); |
110 | 0 | row_loc.set_ordinal_id(location->row_location.row_id); |
111 | 0 | *mget_req.add_row_locs() = std::move(row_loc); |
112 | 0 | } |
113 | | // Set column desc |
114 | 0 | for (const TColumn& tcolumn : _fetch_option.t_fetch_opt.column_desc) { |
115 | 0 | TabletColumn column(tcolumn); |
116 | 0 | column.to_schema_pb(mget_req.add_column_desc()); |
117 | 0 | } |
118 | 0 | PUniqueId& query_id = *mget_req.mutable_query_id(); |
119 | 0 | query_id.set_hi(_fetch_option.runtime_state->query_id().hi); |
120 | 0 | query_id.set_lo(_fetch_option.runtime_state->query_id().lo); |
121 | 0 | mget_req.set_be_exec_version(_fetch_option.runtime_state->be_exec_version()); |
122 | 0 | mget_req.set_fetch_row_store(_fetch_option.t_fetch_opt.fetch_row_store); |
123 | 0 | return mget_req; |
124 | 0 | } |
125 | | |
126 | 0 | static void fetch_callback(bthread::CountdownEvent* counter) { |
127 | 0 | Defer __defer([&] { counter->signal(); }); |
128 | 0 | } |
129 | | |
130 | | Status RowIDFetcher::_merge_rpc_results(const PMultiGetRequest& request, |
131 | | const std::vector<PMultiGetResponse>& rsps, |
132 | | const std::vector<brpc::Controller>& cntls, |
133 | | vectorized::Block* output_block, |
134 | 0 | std::vector<PRowLocation>* rows_id) const { |
135 | 0 | output_block->clear(); |
136 | 0 | for (const auto& cntl : cntls) { |
137 | 0 | if (cntl.Failed()) { |
138 | 0 | LOG(WARNING) << "Failed to fetch meet rpc error:" << cntl.ErrorText() |
139 | 0 | << ", host:" << cntl.remote_side(); |
140 | 0 | return Status::InternalError(cntl.ErrorText()); |
141 | 0 | } |
142 | 0 | } |
143 | 0 | vectorized::DataTypeSerDeSPtrs serdes; |
144 | 0 | std::unordered_map<uint32_t, uint32_t> col_uid_to_idx; |
145 | 0 | std::vector<std::string> default_values; |
146 | 0 | default_values.resize(_fetch_option.desc->slots().size()); |
147 | 0 | auto merge_function = [&](const PMultiGetResponse& resp) { |
148 | 0 | Status st(Status::create(resp.status())); |
149 | 0 | if (!st.ok()) { |
150 | 0 | LOG(WARNING) << "Failed to fetch " << st.to_string(); |
151 | 0 | return st; |
152 | 0 | } |
153 | 0 | for (const PRowLocation& row_id : resp.row_locs()) { |
154 | 0 | rows_id->push_back(row_id); |
155 | 0 | } |
156 | | // Merge binary rows |
157 | 0 | if (request.fetch_row_store()) { |
158 | 0 | CHECK(resp.row_locs().size() == resp.binary_row_data_size()); |
159 | 0 | if (output_block->is_empty_column()) { |
160 | 0 | *output_block = vectorized::Block(_fetch_option.desc->slots(), 1); |
161 | 0 | } |
162 | 0 | if (serdes.empty() && col_uid_to_idx.empty()) { |
163 | 0 | serdes = vectorized::create_data_type_serdes(_fetch_option.desc->slots()); |
164 | 0 | for (int i = 0; i < _fetch_option.desc->slots().size(); ++i) { |
165 | 0 | col_uid_to_idx[_fetch_option.desc->slots()[i]->col_unique_id()] = i; |
166 | 0 | default_values[i] = _fetch_option.desc->slots()[i]->col_default_value(); |
167 | 0 | } |
168 | 0 | } |
169 | 0 | for (int i = 0; i < resp.binary_row_data_size(); ++i) { |
170 | 0 | vectorized::JsonbSerializeUtil::jsonb_to_block( |
171 | 0 | serdes, resp.binary_row_data(i).data(), resp.binary_row_data(i).size(), |
172 | 0 | col_uid_to_idx, *output_block, default_values, {}); |
173 | 0 | } |
174 | 0 | return Status::OK(); |
175 | 0 | } |
176 | | // Merge partial blocks |
177 | 0 | vectorized::Block partial_block; |
178 | 0 | RETURN_IF_ERROR(partial_block.deserialize(resp.block())); |
179 | 0 | if (partial_block.is_empty_column()) { |
180 | 0 | return Status::OK(); |
181 | 0 | } |
182 | 0 | CHECK(resp.row_locs().size() == partial_block.rows()); |
183 | 0 | if (output_block->is_empty_column()) { |
184 | 0 | output_block->swap(partial_block); |
185 | 0 | } else if (partial_block.columns() != output_block->columns()) { |
186 | 0 | return Status::Error<ErrorCode::INTERNAL_ERROR>( |
187 | 0 | "Merge block not match, self:[{}], input:[{}], ", output_block->dump_types(), |
188 | 0 | partial_block.dump_types()); |
189 | 0 | } else { |
190 | 0 | for (int i = 0; i < output_block->columns(); ++i) { |
191 | 0 | output_block->get_by_position(i).column->assume_mutable()->insert_range_from( |
192 | 0 | *partial_block.get_by_position(i) |
193 | 0 | .column->convert_to_full_column_if_const() |
194 | 0 | .get(), |
195 | 0 | 0, partial_block.rows()); |
196 | 0 | } |
197 | 0 | } |
198 | 0 | return Status::OK(); |
199 | 0 | }; |
200 | |
|
201 | 0 | for (const auto& resp : rsps) { |
202 | 0 | RETURN_IF_ERROR(merge_function(resp)); |
203 | 0 | } |
204 | 0 | return Status::OK(); |
205 | 0 | } |
206 | | |
207 | 0 | bool _has_char_type(const TypeDescriptor& desc) { |
208 | 0 | switch (desc.type) { |
209 | 0 | case TYPE_CHAR: |
210 | 0 | return true; |
211 | 0 | case TYPE_ARRAY: |
212 | 0 | case TYPE_MAP: |
213 | 0 | case TYPE_STRUCT: |
214 | 0 | for (int idx = 0; idx < desc.children.size(); ++idx) { |
215 | 0 | if (_has_char_type(desc.children[idx])) { |
216 | 0 | return true; |
217 | 0 | } |
218 | 0 | } |
219 | 0 | return false; |
220 | 0 | default: |
221 | 0 | return false; |
222 | 0 | } |
223 | 0 | } |
224 | | |
225 | | Status RowIDFetcher::fetch(const vectorized::ColumnPtr& column_row_ids, |
226 | 0 | vectorized::Block* res_block) { |
227 | 0 | CHECK(!_stubs.empty()); |
228 | 0 | PMultiGetRequest mget_req = _init_fetch_request(assert_cast<const vectorized::ColumnString&>( |
229 | 0 | *vectorized::remove_nullable(column_row_ids).get())); |
230 | 0 | std::vector<PMultiGetResponse> resps(_stubs.size()); |
231 | 0 | std::vector<brpc::Controller> cntls(_stubs.size()); |
232 | 0 | bthread::CountdownEvent counter(_stubs.size()); |
233 | 0 | for (size_t i = 0; i < _stubs.size(); ++i) { |
234 | 0 | cntls[i].set_timeout_ms(config::fetch_rpc_timeout_seconds * 1000); |
235 | 0 | auto callback = brpc::NewCallback(fetch_callback, &counter); |
236 | 0 | _stubs[i]->multiget_data(&cntls[i], &mget_req, &resps[i], callback); |
237 | 0 | } |
238 | 0 | counter.wait(); |
239 | | |
240 | | // Merge |
241 | 0 | std::vector<PRowLocation> rows_locs; |
242 | 0 | rows_locs.reserve(rows_locs.size()); |
243 | 0 | RETURN_IF_ERROR(_merge_rpc_results(mget_req, resps, cntls, res_block, &rows_locs)); |
244 | 0 | if (rows_locs.size() < column_row_ids->size()) { |
245 | 0 | return Status::InternalError("Miss matched return row loc count {}, expected {}, input {}", |
246 | 0 | rows_locs.size(), res_block->rows(), column_row_ids->size()); |
247 | 0 | } |
248 | | // Final sort by row_ids sequence, since row_ids is already sorted if need |
249 | 0 | std::map<GlobalRowLoacation, size_t> positions; |
250 | 0 | for (size_t i = 0; i < rows_locs.size(); ++i) { |
251 | 0 | RowsetId rowset_id; |
252 | 0 | rowset_id.init(rows_locs[i].rowset_id()); |
253 | 0 | GlobalRowLoacation grl(rows_locs[i].tablet_id(), rowset_id, rows_locs[i].segment_id(), |
254 | 0 | rows_locs[i].ordinal_id()); |
255 | 0 | positions[grl] = i; |
256 | 0 | }; |
257 | | // TODO remove this warning code |
258 | 0 | if (positions.size() < rows_locs.size()) { |
259 | 0 | LOG(WARNING) << "contains duplicated row entry"; |
260 | 0 | } |
261 | 0 | vectorized::IColumn::Permutation permutation; |
262 | 0 | permutation.reserve(column_row_ids->size()); |
263 | 0 | for (size_t i = 0; i < column_row_ids->size(); ++i) { |
264 | 0 | auto location = |
265 | 0 | reinterpret_cast<const GlobalRowLoacation*>(column_row_ids->get_data_at(i).data); |
266 | 0 | permutation.push_back(positions[*location]); |
267 | 0 | } |
268 | 0 | for (size_t i = 0; i < res_block->columns(); ++i) { |
269 | 0 | res_block->get_by_position(i).column = |
270 | 0 | res_block->get_by_position(i).column->permute(permutation, permutation.size()); |
271 | 0 | } |
272 | | // Check row consistency |
273 | 0 | RETURN_IF_CATCH_EXCEPTION(res_block->check_number_of_rows()); |
274 | | // shrink for char type |
275 | 0 | std::vector<size_t> char_type_idx; |
276 | 0 | for (size_t i = 0; i < _fetch_option.desc->slots().size(); i++) { |
277 | 0 | const auto& column_desc = _fetch_option.desc->slots()[i]; |
278 | 0 | const TypeDescriptor& type_desc = column_desc->type(); |
279 | 0 | if (_has_char_type(type_desc)) { |
280 | 0 | char_type_idx.push_back(i); |
281 | 0 | } |
282 | 0 | } |
283 | 0 | res_block->shrink_char_type_column_suffix_zero(char_type_idx); |
284 | 0 | VLOG_DEBUG << "dump block:" << res_block->dump_data(0, 10); |
285 | 0 | return Status::OK(); |
286 | 0 | } |
287 | | |
288 | | template <typename Func> |
289 | 0 | auto scope_timer_run(Func fn, int64_t* cost) -> decltype(fn()) { |
290 | 0 | MonotonicStopWatch watch; |
291 | 0 | watch.start(); |
292 | 0 | auto res = fn(); |
293 | 0 | *cost += watch.elapsed_time() / 1000 / 1000; |
294 | 0 | return res; |
295 | 0 | } Unexecuted instantiation: rowid_fetcher.cpp:_ZN5doris15scope_timer_runIZNS_18RowIdStorageReader14read_by_rowidsERKNS_16PMultiGetRequestEPNS_17PMultiGetResponseEE3$_1EEDTclfp_EET_Pl Unexecuted instantiation: rowid_fetcher.cpp:_ZN5doris15scope_timer_runIZNS_18RowIdStorageReader14read_by_rowidsERKNS_16PMultiGetRequestEPNS_17PMultiGetResponseEE3$_2EEDTclfp_EET_Pl Unexecuted instantiation: rowid_fetcher.cpp:_ZN5doris15scope_timer_runIZNS_18RowIdStorageReader14read_by_rowidsERKNS_16PMultiGetRequestEPNS_17PMultiGetResponseEE3$_4EEDTclfp_EET_Pl Unexecuted instantiation: rowid_fetcher.cpp:_ZN5doris15scope_timer_runIZNS_18RowIdStorageReader14read_by_rowidsERKNS_16PMultiGetRequestEPNS_17PMultiGetResponseEE3$_5EEDTclfp_EET_Pl |
296 | | |
297 | | struct IteratorKey { |
298 | | int64_t tablet_id; |
299 | | RowsetId rowset_id; |
300 | | uint64_t segment_id; |
301 | | int slot_id; |
302 | | |
303 | | // unordered map std::equal_to |
304 | 0 | bool operator==(const IteratorKey& rhs) const { |
305 | 0 | return tablet_id == rhs.tablet_id && rowset_id == rhs.rowset_id && |
306 | 0 | segment_id == rhs.segment_id && slot_id == rhs.slot_id; |
307 | 0 | } |
308 | | }; |
309 | | |
310 | | struct HashOfIteratorKey { |
311 | 0 | size_t operator()(const IteratorKey& key) const { |
312 | 0 | size_t seed = 0; |
313 | 0 | seed = HashUtil::hash64(&key.tablet_id, sizeof(key.tablet_id), seed); |
314 | 0 | seed = HashUtil::hash64(&key.rowset_id.hi, sizeof(key.rowset_id.hi), seed); |
315 | 0 | seed = HashUtil::hash64(&key.rowset_id.mi, sizeof(key.rowset_id.mi), seed); |
316 | 0 | seed = HashUtil::hash64(&key.rowset_id.lo, sizeof(key.rowset_id.lo), seed); |
317 | 0 | seed = HashUtil::hash64(&key.segment_id, sizeof(key.segment_id), seed); |
318 | 0 | seed = HashUtil::hash64(&key.slot_id, sizeof(key.slot_id), seed); |
319 | 0 | return seed; |
320 | 0 | } |
321 | | }; |
322 | | |
323 | | struct IteratorItem { |
324 | | std::unique_ptr<ColumnIterator> iterator; |
325 | | // for holding the reference of segment to avoid use after release |
326 | | SegmentSharedPtr segment; |
327 | | }; |
328 | | |
329 | | Status RowIdStorageReader::read_by_rowids(const PMultiGetRequest& request, |
330 | 0 | PMultiGetResponse* response) { |
331 | | // read from storage engine row id by row id |
332 | 0 | OlapReaderStatistics stats; |
333 | 0 | vectorized::Block result_block; |
334 | 0 | int64_t acquire_tablet_ms = 0; |
335 | 0 | int64_t acquire_rowsets_ms = 0; |
336 | 0 | int64_t acquire_segments_ms = 0; |
337 | 0 | int64_t lookup_row_data_ms = 0; |
338 | | |
339 | | // init desc |
340 | 0 | TupleDescriptor desc(request.desc()); |
341 | 0 | std::vector<SlotDescriptor> slots; |
342 | 0 | slots.reserve(request.slots().size()); |
343 | 0 | for (const auto& pslot : request.slots()) { |
344 | 0 | slots.push_back(SlotDescriptor(pslot)); |
345 | 0 | desc.add_slot(&slots.back()); |
346 | 0 | } |
347 | | |
348 | | // init read schema |
349 | 0 | TabletSchema full_read_schema; |
350 | 0 | for (const ColumnPB& column_pb : request.column_desc()) { |
351 | 0 | full_read_schema.append_column(TabletColumn(column_pb)); |
352 | 0 | } |
353 | |
|
354 | 0 | std::unordered_map<IteratorKey, IteratorItem, HashOfIteratorKey> iterator_map; |
355 | | // read row by row |
356 | 0 | for (size_t i = 0; i < request.row_locs_size(); ++i) { |
357 | 0 | const auto& row_loc = request.row_locs(i); |
358 | 0 | MonotonicStopWatch watch; |
359 | 0 | watch.start(); |
360 | 0 | BaseTabletSPtr tablet = scope_timer_run( |
361 | 0 | [&]() { |
362 | 0 | auto res = ExecEnv::get_tablet(row_loc.tablet_id()); |
363 | 0 | return !res.has_value() ? nullptr |
364 | 0 | : std::dynamic_pointer_cast<BaseTablet>(res.value()); |
365 | 0 | }, |
366 | 0 | &acquire_tablet_ms); |
367 | 0 | RowsetId rowset_id; |
368 | 0 | rowset_id.init(row_loc.rowset_id()); |
369 | 0 | if (!tablet) { |
370 | 0 | continue; |
371 | 0 | } |
372 | | // We ensured it's rowset is not released when init Tablet reader param, rowset->update_delayed_expired_timestamp(); |
373 | 0 | BetaRowsetSharedPtr rowset = std::static_pointer_cast<BetaRowset>(scope_timer_run( |
374 | 0 | [&]() { |
375 | 0 | return ExecEnv::GetInstance()->storage_engine().get_quering_rowset(rowset_id); |
376 | 0 | }, |
377 | 0 | &acquire_rowsets_ms)); |
378 | 0 | if (!rowset) { |
379 | 0 | LOG(INFO) << "no such rowset " << rowset_id; |
380 | 0 | continue; |
381 | 0 | } |
382 | 0 | size_t row_size = 0; |
383 | 0 | Defer _defer([&]() { |
384 | 0 | LOG_EVERY_N(INFO, 100) |
385 | 0 | << "multiget_data single_row, cost(us):" << watch.elapsed_time() / 1000 |
386 | 0 | << ", row_size:" << row_size; |
387 | 0 | *response->add_row_locs() = row_loc; |
388 | 0 | }); |
389 | | // TODO: supoort session variable enable_page_cache and disable_file_cache if necessary. |
390 | 0 | SegmentCacheHandle segment_cache; |
391 | 0 | RETURN_IF_ERROR(scope_timer_run( |
392 | 0 | [&]() { |
393 | 0 | return SegmentLoader::instance()->load_segments(rowset, &segment_cache, true); |
394 | 0 | }, |
395 | 0 | &acquire_segments_ms)); |
396 | | // find segment |
397 | 0 | auto it = std::find_if(segment_cache.get_segments().cbegin(), |
398 | 0 | segment_cache.get_segments().cend(), |
399 | 0 | [&row_loc](const segment_v2::SegmentSharedPtr& seg) { |
400 | 0 | return seg->id() == row_loc.segment_id(); |
401 | 0 | }); |
402 | 0 | if (it == segment_cache.get_segments().end()) { |
403 | 0 | continue; |
404 | 0 | } |
405 | 0 | segment_v2::SegmentSharedPtr segment = *it; |
406 | 0 | GlobalRowLoacation row_location(row_loc.tablet_id(), rowset->rowset_id(), |
407 | 0 | row_loc.segment_id(), row_loc.ordinal_id()); |
408 | | // fetch by row store, more effcient way |
409 | 0 | if (request.fetch_row_store()) { |
410 | 0 | CHECK(tablet->tablet_schema()->has_row_store_for_all_columns()); |
411 | 0 | RowLocation loc(rowset_id, segment->id(), row_loc.ordinal_id()); |
412 | 0 | string* value = response->add_binary_row_data(); |
413 | 0 | RETURN_IF_ERROR(scope_timer_run( |
414 | 0 | [&]() { |
415 | 0 | return tablet->lookup_row_data({}, loc, rowset, &desc, stats, *value); |
416 | 0 | }, |
417 | 0 | &lookup_row_data_ms)); |
418 | 0 | row_size = value->size(); |
419 | 0 | continue; |
420 | 0 | } |
421 | | |
422 | | // fetch by column store |
423 | 0 | if (result_block.is_empty_column()) { |
424 | 0 | result_block = vectorized::Block(desc.slots(), request.row_locs().size()); |
425 | 0 | } |
426 | 0 | VLOG_DEBUG << "Read row location " |
427 | 0 | << fmt::format("{}, {}, {}, {}", row_location.tablet_id, |
428 | 0 | row_location.row_location.rowset_id.to_string(), |
429 | 0 | row_location.row_location.segment_id, |
430 | 0 | row_location.row_location.row_id); |
431 | 0 | for (int x = 0; x < desc.slots().size(); ++x) { |
432 | 0 | auto row_id = static_cast<segment_v2::rowid_t>(row_loc.ordinal_id()); |
433 | 0 | vectorized::MutableColumnPtr column = |
434 | 0 | result_block.get_by_position(x).column->assume_mutable(); |
435 | 0 | IteratorKey iterator_key {.tablet_id = tablet->tablet_id(), |
436 | 0 | .rowset_id = rowset_id, |
437 | 0 | .segment_id = row_loc.segment_id(), |
438 | 0 | .slot_id = desc.slots()[x]->id()}; |
439 | 0 | IteratorItem& iterator_item = iterator_map[iterator_key]; |
440 | 0 | if (iterator_item.segment == nullptr) { |
441 | | // hold the reference |
442 | 0 | iterator_map[iterator_key].segment = segment; |
443 | 0 | } |
444 | 0 | segment = iterator_item.segment; |
445 | 0 | RETURN_IF_ERROR(segment->seek_and_read_by_rowid(full_read_schema, desc.slots()[x], |
446 | 0 | row_id, column, stats, |
447 | 0 | iterator_item.iterator)); |
448 | 0 | } |
449 | 0 | } |
450 | | // serialize block if not empty |
451 | 0 | if (!result_block.is_empty_column()) { |
452 | 0 | VLOG_DEBUG << "dump block:" << result_block.dump_data(0, 10) |
453 | 0 | << ", be_exec_version:" << request.be_exec_version(); |
454 | 0 | [[maybe_unused]] size_t compressed_size = 0; |
455 | 0 | [[maybe_unused]] size_t uncompressed_size = 0; |
456 | 0 | int be_exec_version = request.has_be_exec_version() ? request.be_exec_version() : 0; |
457 | 0 | RETURN_IF_ERROR(result_block.serialize(be_exec_version, response->mutable_block(), |
458 | 0 | &uncompressed_size, &compressed_size, |
459 | 0 | segment_v2::CompressionTypePB::LZ4)); |
460 | 0 | } |
461 | | |
462 | 0 | LOG(INFO) << "Query stats: " |
463 | 0 | << fmt::format( |
464 | 0 | "hit_cached_pages:{}, total_pages_read:{}, compressed_bytes_read:{}, " |
465 | 0 | "io_latency:{}ns, " |
466 | 0 | "uncompressed_bytes_read:{}," |
467 | 0 | "bytes_read:{}," |
468 | 0 | "acquire_tablet_ms:{}, acquire_rowsets_ms:{}, acquire_segments_ms:{}, " |
469 | 0 | "lookup_row_data_ms:{}", |
470 | 0 | stats.cached_pages_num, stats.total_pages_num, stats.compressed_bytes_read, |
471 | 0 | stats.io_ns, stats.uncompressed_bytes_read, stats.bytes_read, |
472 | 0 | acquire_tablet_ms, acquire_rowsets_ms, acquire_segments_ms, |
473 | 0 | lookup_row_data_ms); |
474 | 0 | return Status::OK(); |
475 | 0 | } |
476 | | |
477 | | } // namespace doris |