/root/doris/be/src/exec/rowid_fetcher.h
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 | | #pragma once |
19 | | |
20 | | #include <brpc/controller.h> |
21 | | #include <bthread/countdown_event.h> |
22 | | #include <gen_cpp/DataSinks_types.h> |
23 | | #include <gen_cpp/internal_service.pb.h> |
24 | | |
25 | | #include <memory> |
26 | | #include <semaphore> |
27 | | #include <utility> |
28 | | #include <vector> |
29 | | |
30 | | #include "common/status.h" |
31 | | #include "core/block/block.h" |
32 | | #include "core/data_type/data_type.h" |
33 | | #include "storage/id_manager.h" |
34 | | #include "storage/tablet_info.h" // DorisNodesInfo |
35 | | |
36 | | namespace doris { |
37 | | |
38 | | class DorisNodesInfo; |
39 | | class RuntimeProfile; |
40 | | class RuntimeState; |
41 | | class TupleDescriptor; |
42 | | namespace io { |
43 | | enum class FileCacheMissPolicy : uint8_t; |
44 | | } |
45 | | |
46 | | struct FileMapping; |
47 | | struct SegKey; |
48 | | struct SegItem; |
49 | | struct HashOfSegKey; |
50 | | struct IteratorKey; |
51 | | struct IteratorItem; |
52 | | struct HashOfIteratorKey; |
53 | | |
54 | 0 | inline void fetch_callback(bthread::CountdownEvent* counter) { |
55 | 0 | Defer __defer([&] { counter->signal(); }); |
56 | 0 | } |
57 | | |
58 | | template <typename T> |
59 | | class ColumnStr; |
60 | | using ColumnString = ColumnStr<UInt32>; |
61 | | class MutableBlock; |
62 | | |
63 | | // fetch rows by global rowid |
64 | | // tablet_id/rowset_name/segment_id/ordinal_id |
65 | | |
66 | | struct FetchOption { |
67 | | TupleDescriptor* desc = nullptr; |
68 | | RuntimeState* runtime_state = nullptr; |
69 | | TFetchOption t_fetch_opt; |
70 | | }; |
71 | | |
72 | | class RowIDFetcher { |
73 | | public: |
74 | 0 | RowIDFetcher(FetchOption fetch_opt) : _fetch_option(std::move(fetch_opt)) {} |
75 | | Status init(); |
76 | | Status fetch(const ColumnPtr& row_ids, Block* block); |
77 | | |
78 | | private: |
79 | | PMultiGetRequest _init_fetch_request(const ColumnString& row_ids) const; |
80 | | Status _merge_rpc_results(const PMultiGetRequest& request, |
81 | | const std::vector<PMultiGetResponse>& rsps, |
82 | | const std::vector<brpc::Controller>& cntls, Block* output_block, |
83 | | std::vector<PRowLocation>* rows_id) const; |
84 | | |
85 | | std::vector<std::shared_ptr<PBackendService_Stub>> _stubs; |
86 | | FetchOption _fetch_option; |
87 | | }; |
88 | | |
89 | | struct RowStoreReadStruct { |
90 | 0 | RowStoreReadStruct(std::string& buffer) : row_store_buffer(buffer) {}; |
91 | | std::string& row_store_buffer; |
92 | | DataTypeSerDeSPtrs serdes; |
93 | | std::unordered_map<uint32_t, uint32_t> col_uid_to_idx; |
94 | | std::vector<std::string> default_values; |
95 | | }; |
96 | | |
97 | | class RowIdStorageReader { |
98 | | public: |
99 | | //external profile info key. |
100 | | static const std::string ScannersRunningTimeProfile; |
101 | | static const std::string InitReaderAvgTimeProfile; |
102 | | static const std::string GetBlockAvgTimeProfile; |
103 | | static const std::string FileReadLinesProfile; |
104 | | static const std::string TopNLazyMaterializationSecondPhaseLocalIOCount; |
105 | | static const std::string TopNLazyMaterializationSecondPhaseLocalIOBytes; |
106 | | static const std::string TopNLazyMaterializationSecondPhaseRemoteIOCount; |
107 | | static const std::string TopNLazyMaterializationSecondPhaseRemoteIOBytes; |
108 | | static const std::string TopNLazyMaterializationSecondPhaseSkipCacheIOCount; |
109 | | static const std::string TopNLazyMaterializationSecondPhaseWriteCacheBytes; |
110 | | static const std::string TopNLazyMaterializationSecondPhaseLocalIOTime; |
111 | | static const std::string TopNLazyMaterializationSecondPhaseRemoteIOTime; |
112 | | static const std::string TopNLazyMaterializationSecondPhaseWriteCacheIOTime; |
113 | | static const std::string TopNLazyMaterializationSecondPhaseRowsRead; |
114 | | static const std::string TopNLazyMaterializationSecondPhaseSegmentsRead; |
115 | | |
116 | | static Status read_by_rowids(const PMultiGetRequest& request, PMultiGetResponse* response); |
117 | | static Status read_by_rowids(const PMultiGetRequestV2& request, PMultiGetResponseV2* response); |
118 | | |
119 | | private: |
120 | | struct ExternalFetchStatistics; |
121 | | |
122 | | static Status read_doris_format_row( |
123 | | const std::shared_ptr<IdFileMap>& id_file_map, |
124 | | const std::shared_ptr<FileMapping>& file_mapping, const std::vector<uint32_t>& row_id, |
125 | | std::vector<SlotDescriptor>& slots, const TabletSchema& full_read_schema, |
126 | | RowStoreReadStruct& row_store_read_struct, OlapReaderStatistics& stats, |
127 | | int64_t* acquire_tablet_ms, int64_t* acquire_rowsets_ms, int64_t* acquire_segments_ms, |
128 | | int64_t* lookup_row_data_ms, std::unordered_map<SegKey, SegItem, HashOfSegKey>& seg_map, |
129 | | std::unordered_map<IteratorKey, IteratorItem, HashOfIteratorKey>& iterator_map, |
130 | | io::FileCacheMissPolicy file_cache_miss_policy, Block& result_block); |
131 | | |
132 | | static Status read_batch_doris_format_row( |
133 | | const PRequestBlockDesc& request_block_desc, std::shared_ptr<IdFileMap> id_file_map, |
134 | | std::vector<SlotDescriptor>& slots, const TUniqueId& query_id, Block& result_block, |
135 | | OlapReaderStatistics& stats, int64_t* acquire_tablet_ms, int64_t* acquire_rowsets_ms, |
136 | | int64_t* acquire_segments_ms, int64_t* lookup_row_data_ms, |
137 | | io::FileCacheMissPolicy file_cache_miss_policy); |
138 | | |
139 | | static Status read_batch_external_row( |
140 | | const uint64_t workload_group_id, const PRequestBlockDesc& request_block_desc, |
141 | | std::shared_ptr<IdFileMap> id_file_map, std::vector<SlotDescriptor>& slots, |
142 | | std::shared_ptr<FileMapping> first_file_mapping, const TUniqueId& query_id, |
143 | | Block& result_block, PRuntimeProfileTree* pprofile, int64_t* init_reader_avg_ms, |
144 | | int64_t* get_block_avg_ms, size_t* scan_range_cnt); |
145 | | |
146 | | static Status read_lance_rows_by_row_ids(const TFileRangeDesc& scan_range_desc, |
147 | | const std::vector<uint64_t>& row_ids, |
148 | | const std::vector<SlotDescriptor>& slots, |
149 | | RuntimeState* runtime_state, |
150 | | RuntimeProfile* runtime_profile, |
151 | | const TFileScanRangeParams& scan_params, Block* block, |
152 | | ExternalFetchStatistics* fetch_statistics); |
153 | | |
154 | | static Status read_external_row_from_file_mapping( |
155 | | size_t idx, const std::multimap<uint64_t, size_t>& row_ids, |
156 | | const std::shared_ptr<FileMapping>& file_mapping, |
157 | | const std::vector<SlotDescriptor>& slots, const TUniqueId& query_id, |
158 | | const std::shared_ptr<RuntimeState>& runtime_state, std::vector<Block>& scan_blocks, |
159 | | std::vector<std::pair<size_t, size_t>>& row_id_block_idx, |
160 | | std::vector<ExternalFetchStatistics>& fetch_statistics, |
161 | | const TFileScanRangeParams& rpc_scan_params, |
162 | | const std::unordered_map<std::string, int>& colname_to_slot_id, |
163 | | TupleDescriptor& tuple_desc); |
164 | | |
165 | | struct ExternalFetchStatistics { |
166 | | int64_t init_reader_ms = 0; |
167 | | int64_t get_block_ms = 0; |
168 | | std::string file_read_bytes; |
169 | | std::string file_read_times; |
170 | | }; |
171 | | }; |
172 | | |
173 | | template <typename Func> |
174 | 68 | auto scope_timer_run(Func fn, int64_t* cost) -> decltype(fn()) { |
175 | 68 | MonotonicStopWatch watch; |
176 | 68 | watch.start(); |
177 | 68 | auto res = fn(); |
178 | 68 | *cost += watch.elapsed_time() / 1000 / 1000; |
179 | 68 | return res; |
180 | 68 | } rowid_fetcher.cpp:_ZN5doris15scope_timer_runIZNS_18RowIdStorageReader14read_by_rowidsERKNS_16PMultiGetRequestEPNS_17PMultiGetResponseEE3$_1EEDTclfp_EET_Pl Line | Count | Source | 174 | 6 | auto scope_timer_run(Func fn, int64_t* cost) -> decltype(fn()) { | 175 | 6 | MonotonicStopWatch watch; | 176 | 6 | watch.start(); | 177 | 6 | auto res = fn(); | 178 | 6 | *cost += watch.elapsed_time() / 1000 / 1000; | 179 | 6 | return res; | 180 | 6 | } |
rowid_fetcher.cpp:_ZN5doris15scope_timer_runIZNS_18RowIdStorageReader14read_by_rowidsERKNS_16PMultiGetRequestEPNS_17PMultiGetResponseEE3$_2EEDTclfp_EET_Pl Line | Count | Source | 174 | 6 | auto scope_timer_run(Func fn, int64_t* cost) -> decltype(fn()) { | 175 | 6 | MonotonicStopWatch watch; | 176 | 6 | watch.start(); | 177 | 6 | auto res = fn(); | 178 | 6 | *cost += watch.elapsed_time() / 1000 / 1000; | 179 | 6 | return res; | 180 | 6 | } |
rowid_fetcher.cpp:_ZN5doris15scope_timer_runIZNS_18RowIdStorageReader14read_by_rowidsERKNS_16PMultiGetRequestEPNS_17PMultiGetResponseEE3$_4EEDTclfp_EET_Pl Line | Count | Source | 174 | 6 | auto scope_timer_run(Func fn, int64_t* cost) -> decltype(fn()) { | 175 | 6 | MonotonicStopWatch watch; | 176 | 6 | watch.start(); | 177 | 6 | auto res = fn(); | 178 | 6 | *cost += watch.elapsed_time() / 1000 / 1000; | 179 | 6 | return res; | 180 | 6 | } |
Unexecuted instantiation: rowid_fetcher.cpp:_ZN5doris15scope_timer_runIZNS_18RowIdStorageReader14read_by_rowidsERKNS_16PMultiGetRequestEPNS_17PMultiGetResponseEE3$_5EEDTclfp_EET_Pl Unexecuted instantiation: rowid_fetcher.cpp:_ZN5doris15scope_timer_runIZNS_18RowIdStorageReader26read_lance_rows_by_row_idsERKNS_14TFileRangeDescERKSt6vectorImSaImEERKS5_INS_14SlotDescriptorESaISA_EEPNS_12RuntimeStateEPNS_14RuntimeProfileERKNS_20TFileScanRangeParamsEPNS_5BlockEPNS1_23ExternalFetchStatisticsEE3$_0EEDTclfp_EET_Pl Unexecuted instantiation: rowid_fetcher.cpp:_ZN5doris15scope_timer_runIZNS_18RowIdStorageReader26read_lance_rows_by_row_idsERKNS_14TFileRangeDescERKSt6vectorImSaImEERKS5_INS_14SlotDescriptorESaISA_EEPNS_12RuntimeStateEPNS_14RuntimeProfileERKNS_20TFileScanRangeParamsEPNS_5BlockEPNS1_23ExternalFetchStatisticsEE3$_1EEDTclfp_EET_Pl Unexecuted instantiation: rowid_fetcher.cpp:_ZN5doris15scope_timer_runIZNS_18RowIdStorageReader23read_batch_external_rowEmRKNS_17PRequestBlockDescESt10shared_ptrINS_9IdFileMapEERSt6vectorINS_14SlotDescriptorESaIS9_EES5_INS_11FileMappingEERKNS_9TUniqueIdERNS_5BlockEPNS_19PRuntimeProfileTreeEPlSM_PmE3$_0EEDTclfp_EET_SM_ Unexecuted instantiation: rowid_fetcher.cpp:_ZN5doris15scope_timer_runIZNS_18RowIdStorageReader21read_doris_format_rowERKSt10shared_ptrINS_9IdFileMapEERKS2_INS_11FileMappingEERKSt6vectorIjSaIjEERSB_INS_14SlotDescriptorESaISG_EERKNS_12TabletSchemaERNS_18RowStoreReadStructERNS_20OlapReaderStatisticsEPlSR_SR_SR_RSt13unordered_mapINS_6SegKeyENS_7SegItemENS_12HashOfSegKeyESt8equal_toIST_ESaISt4pairIKST_SU_EEERSS_INS_11IteratorKeyENS_12IteratorItemENS_17HashOfIteratorKeyESW_IS14_ESaISY_IKS14_S15_EEENS_2io19FileCacheMissPolicyERNS_5BlockEE3$_1EEDTclfp_EET_SR_ Unexecuted instantiation: rowid_fetcher.cpp:_ZN5doris15scope_timer_runIZNS_18RowIdStorageReader21read_doris_format_rowERKSt10shared_ptrINS_9IdFileMapEERKS2_INS_11FileMappingEERKSt6vectorIjSaIjEERSB_INS_14SlotDescriptorESaISG_EERKNS_12TabletSchemaERNS_18RowStoreReadStructERNS_20OlapReaderStatisticsEPlSR_SR_SR_RSt13unordered_mapINS_6SegKeyENS_7SegItemENS_12HashOfSegKeyESt8equal_toIST_ESaISt4pairIKST_SU_EEERSS_INS_11IteratorKeyENS_12IteratorItemENS_17HashOfIteratorKeyESW_IS14_ESaISY_IKS14_S15_EEENS_2io19FileCacheMissPolicyERNS_5BlockEE3$_2EEDTclfp_EET_SR_ Unexecuted instantiation: rowid_fetcher.cpp:_ZN5doris15scope_timer_runIZNS_18RowIdStorageReader21read_doris_format_rowERKSt10shared_ptrINS_9IdFileMapEERKS2_INS_11FileMappingEERKSt6vectorIjSaIjEERSB_INS_14SlotDescriptorESaISG_EERKNS_12TabletSchemaERNS_18RowStoreReadStructERNS_20OlapReaderStatisticsEPlSR_SR_SR_RSt13unordered_mapINS_6SegKeyENS_7SegItemENS_12HashOfSegKeyESt8equal_toIST_ESaISt4pairIKST_SU_EEERSS_INS_11IteratorKeyENS_12IteratorItemENS_17HashOfIteratorKeyESW_IS14_ESaISY_IKS14_S15_EEENS_2io19FileCacheMissPolicyERNS_5BlockEE3$_3EEDTclfp_EET_SR_ Unexecuted instantiation: rowid_fetcher.cpp:_ZN5doris15scope_timer_runIZNS_18RowIdStorageReader21read_doris_format_rowERKSt10shared_ptrINS_9IdFileMapEERKS2_INS_11FileMappingEERKSt6vectorIjSaIjEERSB_INS_14SlotDescriptorESaISG_EERKNS_12TabletSchemaERNS_18RowStoreReadStructERNS_20OlapReaderStatisticsEPlSR_SR_SR_RSt13unordered_mapINS_6SegKeyENS_7SegItemENS_12HashOfSegKeyESt8equal_toIST_ESaISt4pairIKST_SU_EEERSS_INS_11IteratorKeyENS_12IteratorItemENS_17HashOfIteratorKeyESW_IS14_ESaISY_IKS14_S15_EEENS_2io19FileCacheMissPolicyERNS_5BlockEE3$_4EEDTclfp_EET_SR_ file_scanner.cpp:_ZN5doris15scope_timer_runIZNS_11FileScanner21read_lines_from_rangeERKNS_14TFileRangeDescERKNSt7__cxx114listIlSaIlEEEPNS_5BlockERKNS_23ExternalFileMappingInfoEPlSG_E3$_0EEDTclfp_EET_SG_ Line | Count | Source | 174 | 25 | auto scope_timer_run(Func fn, int64_t* cost) -> decltype(fn()) { | 175 | 25 | MonotonicStopWatch watch; | 176 | 25 | watch.start(); | 177 | 25 | auto res = fn(); | 178 | 25 | *cost += watch.elapsed_time() / 1000 / 1000; | 179 | 25 | return res; | 180 | 25 | } |
file_scanner.cpp:_ZN5doris15scope_timer_runIZNS_11FileScanner21read_lines_from_rangeERKNS_14TFileRangeDescERKNSt7__cxx114listIlSaIlEEEPNS_5BlockERKNS_23ExternalFileMappingInfoEPlSG_E3$_1EEDTclfp_EET_SG_ Line | Count | Source | 174 | 25 | auto scope_timer_run(Func fn, int64_t* cost) -> decltype(fn()) { | 175 | 25 | MonotonicStopWatch watch; | 176 | 25 | watch.start(); | 177 | 25 | auto res = fn(); | 178 | 25 | *cost += watch.elapsed_time() / 1000 / 1000; | 179 | 25 | return res; | 180 | 25 | } |
|
181 | | } // namespace doris |