Coverage Report

Created: 2026-08-25 13:39

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
namespace io {
42
enum class FileCacheMissPolicy : uint8_t;
43
}
44
45
struct FileMapping;
46
struct SegKey;
47
struct SegItem;
48
struct HashOfSegKey;
49
struct IteratorKey;
50
struct IteratorItem;
51
struct HashOfIteratorKey;
52
53
0
inline void fetch_callback(bthread::CountdownEvent* counter) {
54
0
    Defer __defer([&] { counter->signal(); });
55
0
}
56
57
namespace vectorized {
58
template <typename T>
59
class ColumnStr;
60
using ColumnString = ColumnStr<UInt32>;
61
class MutableBlock;
62
} // namespace vectorized
63
64
// fetch rows by global rowid
65
// tablet_id/rowset_name/segment_id/ordinal_id
66
67
struct FetchOption {
68
    TupleDescriptor* desc = nullptr;
69
    RuntimeState* runtime_state = nullptr;
70
    TFetchOption t_fetch_opt;
71
};
72
73
class RowIDFetcher {
74
public:
75
0
    RowIDFetcher(FetchOption fetch_opt) : _fetch_option(std::move(fetch_opt)) {}
76
    Status init();
77
    Status fetch(const vectorized::ColumnPtr& row_ids, vectorized::Block* block);
78
79
private:
80
    PMultiGetRequest _init_fetch_request(const vectorized::ColumnString& row_ids) const;
81
    Status _merge_rpc_results(const PMultiGetRequest& request,
82
                              const std::vector<PMultiGetResponse>& rsps,
83
                              const std::vector<brpc::Controller>& cntls,
84
                              vectorized::Block* output_block,
85
                              std::vector<PRowLocation>* rows_id) const;
86
87
    std::vector<std::shared_ptr<PBackendService_Stub>> _stubs;
88
    FetchOption _fetch_option;
89
};
90
91
struct RowStoreReadStruct {
92
0
    RowStoreReadStruct(std::string& buffer) : row_store_buffer(buffer) {};
93
    std::string& row_store_buffer;
94
    vectorized::DataTypeSerDeSPtrs serdes;
95
    std::unordered_map<uint32_t, uint32_t> col_uid_to_idx;
96
    std::vector<std::string> default_values;
97
};
98
99
class RowIdStorageReader {
100
public:
101
    //external profile info key.
102
    static const std::string ScannersRunningTimeProfile;
103
    static const std::string InitReaderAvgTimeProfile;
104
    static const std::string GetBlockAvgTimeProfile;
105
    static const std::string FileReadLinesProfile;
106
    static const std::string TopNLazyMaterializationSecondPhaseLocalIOCount;
107
    static const std::string TopNLazyMaterializationSecondPhaseLocalIOBytes;
108
    static const std::string TopNLazyMaterializationSecondPhaseRemoteIOCount;
109
    static const std::string TopNLazyMaterializationSecondPhaseRemoteIOBytes;
110
    static const std::string TopNLazyMaterializationSecondPhaseSkipCacheIOCount;
111
    static const std::string TopNLazyMaterializationSecondPhaseWriteCacheBytes;
112
    static const std::string TopNLazyMaterializationSecondPhaseLocalIOTime;
113
    static const std::string TopNLazyMaterializationSecondPhaseRemoteIOTime;
114
    static const std::string TopNLazyMaterializationSecondPhaseWriteCacheIOTime;
115
    static const std::string TopNLazyMaterializationSecondPhaseRowsRead;
116
    static const std::string TopNLazyMaterializationSecondPhaseSegmentsRead;
117
118
    static Status read_by_rowids(const PMultiGetRequest& request, PMultiGetResponse* response);
119
    static Status read_by_rowids(const PMultiGetRequestV2& request, PMultiGetResponseV2* response);
120
121
private:
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, vectorized::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,
135
            vectorized::Block& result_block, OlapReaderStatistics& stats,
136
            int64_t* acquire_tablet_ms, int64_t* acquire_rowsets_ms, int64_t* acquire_segments_ms,
137
            int64_t* lookup_row_data_ms, 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
            vectorized::Block& result_block, PRuntimeProfileTree* pprofile,
144
            int64_t* init_reader_avg_ms, int64_t* get_block_avg_ms, size_t* scan_range_cnt);
145
146
    struct ExternalFetchStatistics {
147
        int64_t init_reader_ms = 0;
148
        int64_t get_block_ms = 0;
149
        std::string file_read_bytes;
150
        std::string file_read_times;
151
    };
152
};
153
154
template <typename Func>
155
50
auto scope_timer_run(Func fn, int64_t* cost) -> decltype(fn()) {
156
50
    MonotonicStopWatch watch;
157
50
    watch.start();
158
50
    auto res = fn();
159
50
    *cost += watch.elapsed_time() / 1000 / 1000;
160
50
    return res;
161
50
}
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_EEENS_2io19FileCacheMissPolicyERNS_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_EEENS_2io19FileCacheMissPolicyERNS_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_EEENS_2io19FileCacheMissPolicyERNS_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_EEENS_2io19FileCacheMissPolicyERNS_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
155
25
auto scope_timer_run(Func fn, int64_t* cost) -> decltype(fn()) {
156
25
    MonotonicStopWatch watch;
157
25
    watch.start();
158
25
    auto res = fn();
159
25
    *cost += watch.elapsed_time() / 1000 / 1000;
160
25
    return res;
161
25
}
file_scanner.cpp:_ZN5doris15scope_timer_runIZNS_10vectorized11FileScanner21read_lines_from_rangeERKNS_14TFileRangeDescERKNSt7__cxx114listIlSaIlEEEPNS1_5BlockERKNS_23ExternalFileMappingInfoEPlSH_E3$_1EEDTclfp_EET_SH_
Line
Count
Source
155
25
auto scope_timer_run(Func fn, int64_t* cost) -> decltype(fn()) {
156
25
    MonotonicStopWatch watch;
157
25
    watch.start();
158
25
    auto res = fn();
159
25
    *cost += watch.elapsed_time() / 1000 / 1000;
160
25
    return res;
161
25
}
162
} // namespace doris