Coverage Report

Created: 2026-02-11 11:15

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/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 "exec/tablet_info.h" // DorisNodesInfo
32
#include "olap/id_manager.h"
33
#include "vec/core/block.h"
34
#include "vec/data_types/data_type.h"
35
36
namespace doris {
37
38
class DorisNodesInfo;
39
class RuntimeState;
40
class TupleDescriptor;
41
42
struct FileMapping;
43
struct SegKey;
44
struct SegItem;
45
struct HashOfSegKey;
46
struct IteratorKey;
47
struct IteratorItem;
48
struct HashOfIteratorKey;
49
50
0
inline void fetch_callback(bthread::CountdownEvent* counter) {
51
0
    Defer __defer([&] { counter->signal(); });
52
0
}
53
54
namespace vectorized {
55
template <typename T>
56
class ColumnStr;
57
using ColumnString = ColumnStr<UInt32>;
58
class MutableBlock;
59
} // namespace vectorized
60
61
// fetch rows by global rowid
62
// tablet_id/rowset_name/segment_id/ordinal_id
63
64
struct FetchOption {
65
    TupleDescriptor* desc = nullptr;
66
    RuntimeState* runtime_state = nullptr;
67
    TFetchOption t_fetch_opt;
68
};
69
70
class RowIDFetcher {
71
public:
72
0
    RowIDFetcher(FetchOption fetch_opt) : _fetch_option(std::move(fetch_opt)) {}
73
    Status init();
74
    Status fetch(const vectorized::ColumnPtr& row_ids, vectorized::Block* block);
75
76
private:
77
    PMultiGetRequest _init_fetch_request(const vectorized::ColumnString& row_ids) const;
78
    Status _merge_rpc_results(const PMultiGetRequest& request,
79
                              const std::vector<PMultiGetResponse>& rsps,
80
                              const std::vector<brpc::Controller>& cntls,
81
                              vectorized::Block* output_block,
82
                              std::vector<PRowLocation>* rows_id) const;
83
84
    std::vector<std::shared_ptr<PBackendService_Stub>> _stubs;
85
    FetchOption _fetch_option;
86
};
87
88
struct RowStoreReadStruct {
89
0
    RowStoreReadStruct(std::string& buffer) : row_store_buffer(buffer) {};
90
    std::string& row_store_buffer;
91
    vectorized::DataTypeSerDeSPtrs serdes;
92
    std::unordered_map<uint32_t, uint32_t> col_uid_to_idx;
93
    std::vector<std::string> default_values;
94
};
95
96
class RowIdStorageReader {
97
public:
98
    //external profile info key.
99
    static const std::string ScannersRunningTimeProfile;
100
    static const std::string InitReaderAvgTimeProfile;
101
    static const std::string GetBlockAvgTimeProfile;
102
    static const std::string FileReadLinesProfile;
103
104
    static Status read_by_rowids(const PMultiGetRequest& request, PMultiGetResponse* response);
105
    static Status read_by_rowids(const PMultiGetRequestV2& request, PMultiGetResponseV2* response);
106
107
private:
108
    struct ExternalFetchStatistics;
109
110
    static Status read_doris_format_row(
111
            const std::shared_ptr<IdFileMap>& id_file_map,
112
            const std::shared_ptr<FileMapping>& file_mapping, const std::vector<uint32_t>& row_id,
113
            std::vector<SlotDescriptor>& slots, const TabletSchema& full_read_schema,
114
            RowStoreReadStruct& row_store_read_struct, OlapReaderStatistics& stats,
115
            int64_t* acquire_tablet_ms, int64_t* acquire_rowsets_ms, int64_t* acquire_segments_ms,
116
            int64_t* lookup_row_data_ms, std::unordered_map<SegKey, SegItem, HashOfSegKey>& seg_map,
117
            std::unordered_map<IteratorKey, IteratorItem, HashOfIteratorKey>& iterator_map,
118
            vectorized::Block& result_block);
119
120
    static Status read_batch_doris_format_row(
121
            const PRequestBlockDesc& request_block_desc, std::shared_ptr<IdFileMap> id_file_map,
122
            std::vector<SlotDescriptor>& slots, const TUniqueId& query_id,
123
            vectorized::Block& result_block, OlapReaderStatistics& stats,
124
            int64_t* acquire_tablet_ms, int64_t* acquire_rowsets_ms, int64_t* acquire_segments_ms,
125
            int64_t* lookup_row_data_ms);
126
127
    static Status read_batch_external_row(
128
            const uint64_t workload_group_id, const PRequestBlockDesc& request_block_desc,
129
            std::shared_ptr<IdFileMap> id_file_map, std::vector<SlotDescriptor>& slots,
130
            std::shared_ptr<FileMapping> first_file_mapping, const TUniqueId& query_id,
131
            vectorized::Block& result_block, PRuntimeProfileTree* pprofile,
132
            int64_t* init_reader_avg_ms, int64_t* get_block_avg_ms, size_t* scan_range_cnt);
133
134
    static Status read_external_row_from_file_mapping(
135
            size_t idx, const std::multimap<segment_v2::rowid_t, size_t>& row_ids,
136
            const std::shared_ptr<FileMapping>& file_mapping,
137
            const std::vector<SlotDescriptor>& slots, const TUniqueId& query_id,
138
            const std::shared_ptr<RuntimeState>& runtime_state,
139
            std::vector<vectorized::Block>& scan_blocks,
140
            std::vector<std::pair<size_t, size_t>>& row_id_block_idx,
141
            std::vector<ExternalFetchStatistics>& fetch_statistics,
142
            const TFileScanRangeParams& rpc_scan_params,
143
            const std::unordered_map<std::string, int>& colname_to_slot_id,
144
            std::atomic<int>& producer_count, size_t scan_rows_count,
145
            std::counting_semaphore<>& semaphore, std::condition_variable& cv, std::mutex& mtx,
146
            TupleDescriptor& tuple_desc);
147
148
    struct ExternalFetchStatistics {
149
        int64_t init_reader_ms = 0;
150
        int64_t get_block_ms = 0;
151
        std::string file_read_bytes;
152
        std::string file_read_times;
153
    };
154
};
155
156
template <typename Func>
157
48
auto scope_timer_run(Func fn, int64_t* cost) -> decltype(fn()) {
158
48
    MonotonicStopWatch watch;
159
48
    watch.start();
160
48
    auto res = fn();
161
48
    *cost += watch.elapsed_time() / 1000 / 1000;
162
48
    return res;
163
48
}
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
Unexecuted instantiation: rowid_fetcher.cpp:_ZN5doris15scope_timer_runIZNS_18RowIdStorageReader23read_batch_external_rowEmRKNS_17PRequestBlockDescESt10shared_ptrINS_9IdFileMapEERSt6vectorINS_14SlotDescriptorESaIS9_EES5_INS_11FileMappingEERKNS_9TUniqueIdERNS_10vectorized5BlockEPNS_19PRuntimeProfileTreeEPlSN_PmE3$_0EEDTclfp_EET_SN_
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_EEERNS_10vectorized5BlockEE3$_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_EEERNS_10vectorized5BlockEE3$_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_EEERNS_10vectorized5BlockEE3$_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_EEERNS_10vectorized5BlockEE3$_4EEDTclfp_EET_SR_
file_scanner.cpp:_ZN5doris15scope_timer_runIZNS_10vectorized11FileScanner21read_lines_from_rangeERKNS_14TFileRangeDescERKNSt7__cxx114listIlSaIlEEEPNS1_5BlockERKNS_23ExternalFileMappingInfoEPlSH_E3$_0EEDTclfp_EET_SH_
Line
Count
Source
157
24
auto scope_timer_run(Func fn, int64_t* cost) -> decltype(fn()) {
158
24
    MonotonicStopWatch watch;
159
24
    watch.start();
160
24
    auto res = fn();
161
24
    *cost += watch.elapsed_time() / 1000 / 1000;
162
24
    return res;
163
24
}
file_scanner.cpp:_ZN5doris15scope_timer_runIZNS_10vectorized11FileScanner21read_lines_from_rangeERKNS_14TFileRangeDescERKNSt7__cxx114listIlSaIlEEEPNS1_5BlockERKNS_23ExternalFileMappingInfoEPlSH_E3$_1EEDTclfp_EET_SH_
Line
Count
Source
157
24
auto scope_timer_run(Func fn, int64_t* cost) -> decltype(fn()) {
158
24
    MonotonicStopWatch watch;
159
24
    watch.start();
160
24
    auto res = fn();
161
24
    *cost += watch.elapsed_time() / 1000 / 1000;
162
24
    return res;
163
24
}
164
} // namespace doris