be/src/storage/rowset/beta_rowset_reader.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 <gen_cpp/olap_file.pb.h> |
21 | | #include <stdint.h> |
22 | | |
23 | | #include <memory> |
24 | | #include <utility> |
25 | | #include <vector> |
26 | | |
27 | | #include "common/status.h" |
28 | | #include "core/block/block.h" |
29 | | #include "storage/iterators.h" |
30 | | #include "storage/olap_common.h" |
31 | | #include "storage/rowset/beta_rowset.h" |
32 | | #include "storage/rowset/rowset.h" |
33 | | #include "storage/rowset/rowset_reader.h" |
34 | | #include "storage/schema.h" |
35 | | #include "storage/segment/segment_loader.h" |
36 | | #include "util/once.h" |
37 | | |
38 | | namespace doris { |
39 | | class RuntimeProfile; |
40 | | class ReadSchema; |
41 | | struct RowLocation; |
42 | | struct RowsetReaderContext; |
43 | | |
44 | | class BetaRowsetReader : public RowsetReader { |
45 | | public: |
46 | | BetaRowsetReader(BetaRowsetSharedPtr rowset); |
47 | | |
48 | 1.16k | ~BetaRowsetReader() override { _rowset->release(); } |
49 | | |
50 | | Status init(RowsetReaderContext* read_context, const RowSetSplits& rs_splits) override; |
51 | | |
52 | | Status get_segment_iterators(RowsetReaderContext* read_context, |
53 | | std::vector<RowwiseIteratorUPtr>* out_iters, |
54 | | bool use_cache = false) override; |
55 | | void reset_read_options() override; |
56 | 6.79k | Status next_batch(Block* block) override { return _next_batch(block); } |
57 | 0 | Status next_batch(BlockView* block_view) override { return _next_batch(block_view); } |
58 | 209 | Status next_batch(BlockWithSameBit* block_with_same_bit) override { |
59 | 209 | return _next_batch(block_with_same_bit); |
60 | 209 | } |
61 | | |
62 | 542 | bool is_merge_iterator() const override { |
63 | 542 | return _read_context->need_ordered_result && _get_segment_num() > 1 && |
64 | 542 | (_rowset->rowset_meta()->is_segments_overlapping() || |
65 | 189 | _read_context->force_key_ordered_read); |
66 | 542 | } |
67 | | |
68 | 0 | bool delete_flag() override { return _rowset->delete_flag(); } |
69 | | |
70 | 1.03M | Version version() override { return _rowset->version(); } |
71 | | |
72 | 23 | int64_t newest_write_timestamp() override { return _rowset->newest_write_timestamp(); } |
73 | | |
74 | 592k | RowsetSharedPtr rowset() override { return std::dynamic_pointer_cast<Rowset>(_rowset); } |
75 | | |
76 | 0 | const ReadSchema& read_schema() const override { return *_read_context->read_schema; } |
77 | | |
78 | | // Return the total number of filtered rows, will be used for validation of schema change |
79 | 0 | int64_t filtered_rows() override { |
80 | 0 | return _stats->rows_del_filtered + _stats->rows_del_by_bitmap + |
81 | 0 | _stats->rows_conditions_filtered + _stats->rows_vec_del_cond_filtered + |
82 | 0 | _stats->rows_vec_cond_filtered + _stats->rows_short_circuit_cond_filtered; |
83 | 0 | } |
84 | | |
85 | 0 | uint64_t merged_rows() override { return *(_read_context->merged_rows); } |
86 | | |
87 | 144 | RowsetTypePB type() const override { return RowsetTypePB::BETA_ROWSET; } |
88 | | |
89 | 1.03k | Status current_block_row_locations(std::vector<RowLocation>* locations) override { |
90 | 1.03k | return _iterator->current_block_row_locations(locations); |
91 | 1.03k | } |
92 | | |
93 | | void update_profile(RuntimeProfile* profile) override; |
94 | | |
95 | | RowsetReaderSharedPtr clone() override; |
96 | | |
97 | 0 | void set_topn_limit(size_t topn_limit) override { _topn_limit = topn_limit; } |
98 | | |
99 | 0 | OlapReaderStatistics* get_stats() { return _stats; } |
100 | | |
101 | | private: |
102 | | template <typename T> |
103 | 7.00k | Status _next_batch(T* block) { |
104 | 7.00k | RETURN_IF_ERROR(_init_iterator_once()); |
105 | 7.00k | SCOPED_RAW_TIMER(&_stats->block_fetch_ns); |
106 | 7.00k | if (_empty) { |
107 | 0 | return Status::Error<ErrorCode::END_OF_FILE>("BetaRowsetReader is empty"); |
108 | 0 | } |
109 | | |
110 | 7.00k | RuntimeState* runtime_state = nullptr; |
111 | 7.00k | if (_read_context != nullptr) { |
112 | 7.00k | runtime_state = _read_context->runtime_state; |
113 | 7.00k | } |
114 | | |
115 | 7.02k | do { |
116 | 7.02k | Status s = _iterator->next_batch(block); |
117 | 7.02k | if (!s.ok()) { |
118 | 398 | if (!s.is<ErrorCode::END_OF_FILE>()) { |
119 | 0 | LOG(WARNING) << "failed to read next block: " << s.to_string(); |
120 | 0 | } |
121 | 398 | return s; |
122 | 398 | } |
123 | | |
124 | 6.62k | if (runtime_state != nullptr && runtime_state->is_cancelled()) [[unlikely]] { |
125 | 0 | return runtime_state->cancel_reason(); |
126 | 0 | } |
127 | 6.62k | } while (block->empty()); |
128 | | |
129 | 6.60k | return Status::OK(); |
130 | 7.00k | } _ZN5doris16BetaRowsetReader11_next_batchINS_5BlockEEENS_6StatusEPT_ Line | Count | Source | 103 | 6.79k | Status _next_batch(T* block) { | 104 | 6.79k | RETURN_IF_ERROR(_init_iterator_once()); | 105 | 6.79k | SCOPED_RAW_TIMER(&_stats->block_fetch_ns); | 106 | 6.79k | if (_empty) { | 107 | 0 | return Status::Error<ErrorCode::END_OF_FILE>("BetaRowsetReader is empty"); | 108 | 0 | } | 109 | | | 110 | 6.79k | RuntimeState* runtime_state = nullptr; | 111 | 6.79k | if (_read_context != nullptr) { | 112 | 6.79k | runtime_state = _read_context->runtime_state; | 113 | 6.79k | } | 114 | | | 115 | 6.81k | do { | 116 | 6.81k | Status s = _iterator->next_batch(block); | 117 | 6.81k | if (!s.ok()) { | 118 | 390 | if (!s.is<ErrorCode::END_OF_FILE>()) { | 119 | 0 | LOG(WARNING) << "failed to read next block: " << s.to_string(); | 120 | 0 | } | 121 | 390 | return s; | 122 | 390 | } | 123 | | | 124 | 6.42k | if (runtime_state != nullptr && runtime_state->is_cancelled()) [[unlikely]] { | 125 | 0 | return runtime_state->cancel_reason(); | 126 | 0 | } | 127 | 6.42k | } while (block->empty()); | 128 | | | 129 | 6.40k | return Status::OK(); | 130 | 6.79k | } |
Unexecuted instantiation: _ZN5doris16BetaRowsetReader11_next_batchISt6vectorINS_14IteratorRowRefESaIS3_EEEENS_6StatusEPT_ _ZN5doris16BetaRowsetReader11_next_batchINS_16BlockWithSameBitEEENS_6StatusEPT_ Line | Count | Source | 103 | 209 | Status _next_batch(T* block) { | 104 | 209 | RETURN_IF_ERROR(_init_iterator_once()); | 105 | 209 | SCOPED_RAW_TIMER(&_stats->block_fetch_ns); | 106 | 209 | if (_empty) { | 107 | 0 | return Status::Error<ErrorCode::END_OF_FILE>("BetaRowsetReader is empty"); | 108 | 0 | } | 109 | | | 110 | 209 | RuntimeState* runtime_state = nullptr; | 111 | 209 | if (_read_context != nullptr) { | 112 | 209 | runtime_state = _read_context->runtime_state; | 113 | 209 | } | 114 | | | 115 | 209 | do { | 116 | 209 | Status s = _iterator->next_batch(block); | 117 | 209 | if (!s.ok()) { | 118 | 8 | if (!s.is<ErrorCode::END_OF_FILE>()) { | 119 | 0 | LOG(WARNING) << "failed to read next block: " << s.to_string(); | 120 | 0 | } | 121 | 8 | return s; | 122 | 8 | } | 123 | | | 124 | 201 | if (runtime_state != nullptr && runtime_state->is_cancelled()) [[unlikely]] { | 125 | 0 | return runtime_state->cancel_reason(); | 126 | 0 | } | 127 | 201 | } while (block->empty()); | 128 | | | 129 | 201 | return Status::OK(); | 130 | 209 | } |
|
131 | | |
132 | | [[nodiscard]] Status _init_iterator_once(); |
133 | | [[nodiscard]] Status _init_iterator(); |
134 | | bool _should_push_down_value_predicates() const; |
135 | | |
136 | 346 | int64_t _get_segment_num() const { |
137 | 346 | auto [seg_start, seg_end] = _segment_offsets; |
138 | 346 | if (seg_start == seg_end) { |
139 | 346 | seg_start = 0; |
140 | 346 | seg_end = _rowset->num_segments(); |
141 | 346 | } |
142 | 346 | return seg_end - seg_start; |
143 | 346 | } |
144 | | |
145 | | DorisCallOnce<Status> _init_iter_once; |
146 | | |
147 | | std::pair<int64_t, int64_t> _segment_offsets; |
148 | | std::vector<RowRanges> _segment_row_ranges; |
149 | | |
150 | | RowsetReaderContext* _read_context = nullptr; |
151 | | BetaRowsetSharedPtr _rowset; |
152 | | |
153 | | OlapReaderStatistics _owned_stats; |
154 | | OlapReaderStatistics* _stats = nullptr; |
155 | | |
156 | | std::unique_ptr<RowwiseIterator> _iterator; |
157 | | |
158 | | StorageReadOptions _read_options; |
159 | | |
160 | | bool _empty = false; |
161 | | size_t _topn_limit = 0; |
162 | | uint64_t _merged_rows = 0; |
163 | | }; |
164 | | |
165 | | } // namespace doris |