be/src/storage/rowset/rowset_meta.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 | | #ifndef DORIS_BE_SRC_OLAP_ROWSET_ROWSET_META_H |
19 | | #define DORIS_BE_SRC_OLAP_ROWSET_ROWSET_META_H |
20 | | |
21 | | #include <gen_cpp/olap_file.pb.h> |
22 | | #include <glog/logging.h> |
23 | | |
24 | | #include <atomic> |
25 | | #include <chrono> |
26 | | #include <cstdint> |
27 | | #include <memory> |
28 | | #include <string> |
29 | | #include <vector> |
30 | | |
31 | | #include "common/cast_set.h" |
32 | | #include "common/config.h" |
33 | | #include "common/status.h" |
34 | | #include "io/fs/encrypted_fs_factory.h" |
35 | | #include "io/fs/file_system.h" |
36 | | #include "runtime/memory/lru_cache_policy.h" |
37 | | #include "storage/compaction/binlog_compaction_policy.h" |
38 | | #include "storage/metadata_adder.h" |
39 | | #include "storage/olap_common.h" |
40 | | #include "storage/rowset/rowset_fwd.h" |
41 | | #include "storage/storage_policy.h" |
42 | | #include "storage/tablet/tablet_fwd.h" |
43 | | #include "util/once.h" |
44 | | |
45 | | namespace doris { |
46 | | |
47 | | class RowsetMeta : public MetadataAdder<RowsetMeta> { |
48 | | public: |
49 | 1.17M | RowsetMeta() = default; |
50 | | ~RowsetMeta(); |
51 | | |
52 | | bool init(std::string_view pb_rowset_meta); |
53 | | |
54 | | bool init(const RowsetMeta* rowset_meta); |
55 | | |
56 | | bool init_from_pb(const RowsetMetaPB& rowset_meta_pb); |
57 | | |
58 | | bool init_from_json(const std::string& json_rowset_meta); |
59 | | |
60 | 6 | bool serialize(std::string* value) { return _serialize_to_pb(value); } |
61 | | |
62 | | bool json_rowset_meta(std::string* json_rowset_meta); |
63 | | |
64 | | // If the rowset is a local rowset, return the global local file system. |
65 | | // Otherwise, return the remote file system corresponding to rowset's resource id. |
66 | | // Note that if the resource id cannot be found for the corresponding remote file system, nullptr will be returned. |
67 | | MOCK_FUNCTION io::FileSystemSPtr fs(); |
68 | | |
69 | | io::FileSystemSPtr physical_fs(); |
70 | | |
71 | | Result<const StorageResource*> remote_storage_resource(); |
72 | | |
73 | | void set_remote_storage_resource(StorageResource resource); |
74 | | |
75 | 164k | const std::string& resource_id() const { return _rowset_meta_pb.resource_id(); } |
76 | | |
77 | 123k | void set_resource_id(const std::string& resource_id) { |
78 | 123k | _rowset_meta_pb.set_resource_id(resource_id); |
79 | 123k | } |
80 | | |
81 | 51.2M | bool is_local() const { return !_rowset_meta_pb.has_resource_id(); } |
82 | | |
83 | | bool has_variant_type_in_schema() const; |
84 | | |
85 | 39.7M | RowsetId rowset_id() const { return _rowset_id; } |
86 | | |
87 | 376k | void set_rowset_id(const RowsetId& rowset_id) { |
88 | | // rowset id is a required field, just set it to 0 |
89 | 376k | _rowset_meta_pb.set_rowset_id(0); |
90 | 376k | _rowset_id = rowset_id; |
91 | 376k | _rowset_meta_pb.set_rowset_id_v2(rowset_id.to_string()); |
92 | 376k | } |
93 | | |
94 | 10.3M | int64_t tablet_id() const { return _rowset_meta_pb.tablet_id(); } |
95 | | |
96 | 377k | void set_tablet_id(int64_t tablet_id) { _rowset_meta_pb.set_tablet_id(tablet_id); } |
97 | | |
98 | 940 | int64_t db_id() const { return _rowset_meta_pb.db_id(); } |
99 | | |
100 | 243k | void set_db_id(int64_t db_id) { _rowset_meta_pb.set_db_id(db_id); } |
101 | | |
102 | 940 | int64_t table_id() const { return _rowset_meta_pb.table_id(); } |
103 | | |
104 | 242k | void set_table_id(int64_t table_id) { _rowset_meta_pb.set_table_id(table_id); } |
105 | | |
106 | | int64_t index_id() const { return _rowset_meta_pb.index_id(); } |
107 | | |
108 | 365k | void set_index_id(int64_t index_id) { _rowset_meta_pb.set_index_id(index_id); } |
109 | | |
110 | 103k | TabletUid tablet_uid() const { return _rowset_meta_pb.tablet_uid(); } |
111 | | |
112 | 183k | void set_tablet_uid(TabletUid tablet_uid) { |
113 | 183k | *(_rowset_meta_pb.mutable_tablet_uid()) = tablet_uid.to_proto(); |
114 | 183k | } |
115 | | |
116 | 345k | int64_t txn_id() const { return _rowset_meta_pb.txn_id(); } |
117 | | |
118 | 352k | void set_txn_id(int64_t txn_id) { _rowset_meta_pb.set_txn_id(txn_id); } |
119 | | |
120 | 124k | int32_t tablet_schema_hash() const { return _rowset_meta_pb.tablet_schema_hash(); } |
121 | | |
122 | 366k | void set_tablet_schema_hash(int32_t tablet_schema_hash) { |
123 | 366k | _rowset_meta_pb.set_tablet_schema_hash(tablet_schema_hash); |
124 | 366k | } |
125 | | |
126 | 15 | void mark_row_binlog() { _rowset_meta_pb.set_is_row_binlog(true); } |
127 | | |
128 | 3.46M | bool is_row_binlog() const { |
129 | 3.46M | return _rowset_meta_pb.has_is_row_binlog() && _rowset_meta_pb.is_row_binlog(); |
130 | 3.46M | } |
131 | | |
132 | 2.21M | RowsetTypePB rowset_type() const { return _rowset_meta_pb.rowset_type(); } |
133 | | |
134 | 367k | void set_rowset_type(RowsetTypePB rowset_type) { _rowset_meta_pb.set_rowset_type(rowset_type); } |
135 | | |
136 | 631k | RowsetStatePB rowset_state() const { return _rowset_meta_pb.rowset_state(); } |
137 | | |
138 | 647k | void set_rowset_state(RowsetStatePB rowset_state) { |
139 | 647k | _rowset_meta_pb.set_rowset_state(rowset_state); |
140 | 647k | } |
141 | | |
142 | 60.8M | Version version() const { |
143 | 60.8M | return {_rowset_meta_pb.start_version(), _rowset_meta_pb.end_version()}; |
144 | 60.8M | } |
145 | | |
146 | 308k | void set_version(Version version) { |
147 | 308k | _rowset_meta_pb.set_start_version(version.first); |
148 | 308k | _rowset_meta_pb.set_end_version(version.second); |
149 | 308k | } |
150 | | |
151 | 1.05M | bool has_version() const { |
152 | 1.05M | return _rowset_meta_pb.has_start_version() && _rowset_meta_pb.has_end_version(); |
153 | 1.05M | } |
154 | | |
155 | 7.65M | int64_t start_version() const { return _rowset_meta_pb.start_version(); } |
156 | | |
157 | 9.83M | int64_t end_version() const { return _rowset_meta_pb.end_version(); } |
158 | | |
159 | 13.3M | int64_t num_rows() const { return _rowset_meta_pb.num_rows(); } |
160 | | |
161 | 401k | void set_num_rows(int64_t num_rows) { _rowset_meta_pb.set_num_rows(num_rows); } |
162 | | |
163 | 275k | void set_num_segment_rows(const std::vector<uint32_t>& num_segment_rows) { |
164 | 275k | _rowset_meta_pb.mutable_num_segment_rows()->Assign(num_segment_rows.cbegin(), |
165 | 275k | num_segment_rows.cend()); |
166 | 275k | } |
167 | | |
168 | 4.15k | void get_num_segment_rows(std::vector<uint32_t>* num_segment_rows) const { |
169 | 4.15k | num_segment_rows->assign(_rowset_meta_pb.num_segment_rows().cbegin(), |
170 | 4.15k | _rowset_meta_pb.num_segment_rows().cend()); |
171 | 4.15k | } |
172 | | |
173 | 203k | auto& get_num_segment_rows() const { return _rowset_meta_pb.num_segment_rows(); } |
174 | | |
175 | 12.1M | int64_t total_disk_size() const { return _rowset_meta_pb.total_disk_size(); } |
176 | | |
177 | 409k | void set_total_disk_size(int64_t total_disk_size) { |
178 | 409k | _rowset_meta_pb.set_total_disk_size(total_disk_size); |
179 | 409k | } |
180 | | |
181 | 9.31M | int64_t data_disk_size() const { return _rowset_meta_pb.data_disk_size(); } |
182 | | |
183 | 400k | void set_data_disk_size(int64_t data_disk_size) { |
184 | 400k | _rowset_meta_pb.set_data_disk_size(data_disk_size); |
185 | 400k | } |
186 | | |
187 | 2.49M | int64_t index_disk_size() const { return _rowset_meta_pb.index_disk_size(); } |
188 | | |
189 | 400k | void set_index_disk_size(int64_t index_disk_size) { |
190 | 400k | _rowset_meta_pb.set_index_disk_size(index_disk_size); |
191 | 400k | } |
192 | | |
193 | 0 | void zone_maps(std::vector<ZoneMap>* zone_maps) { |
194 | 0 | for (const ZoneMap& zone_map : _rowset_meta_pb.zone_maps()) { |
195 | 0 | zone_maps->push_back(zone_map); |
196 | 0 | } |
197 | 0 | } |
198 | | |
199 | 0 | void set_zone_maps(const std::vector<ZoneMap>& zone_maps) { |
200 | 0 | for (const ZoneMap& zone_map : zone_maps) { |
201 | 0 | ZoneMap* new_zone_map = _rowset_meta_pb.add_zone_maps(); |
202 | 0 | *new_zone_map = zone_map; |
203 | 0 | } |
204 | 0 | } |
205 | | |
206 | 0 | void add_zone_map(const ZoneMap& zone_map) { |
207 | 0 | ZoneMap* new_zone_map = _rowset_meta_pb.add_zone_maps(); |
208 | 0 | *new_zone_map = zone_map; |
209 | 0 | } |
210 | | |
211 | 7.67M | bool has_delete_predicate() const { return _rowset_meta_pb.has_delete_predicate(); } |
212 | | |
213 | 7.42k | const DeletePredicatePB& delete_predicate() const { return _rowset_meta_pb.delete_predicate(); } |
214 | | |
215 | 22 | DeletePredicatePB* mutable_delete_predicate() { |
216 | 22 | return _rowset_meta_pb.mutable_delete_predicate(); |
217 | 22 | } |
218 | | |
219 | 3.29k | void set_delete_predicate(DeletePredicatePB delete_predicate) { |
220 | 3.29k | DeletePredicatePB* new_delete_condition = _rowset_meta_pb.mutable_delete_predicate(); |
221 | 3.29k | *new_delete_condition = std::move(delete_predicate); |
222 | 3.29k | } |
223 | | |
224 | 9.74k | bool empty() const { return _rowset_meta_pb.empty(); } |
225 | | |
226 | 398k | void set_empty(bool empty) { _rowset_meta_pb.set_empty(empty); } |
227 | | |
228 | 52 | PUniqueId load_id() const { return _rowset_meta_pb.load_id(); } |
229 | | |
230 | 335k | void set_load_id(PUniqueId load_id) { |
231 | 335k | PUniqueId* new_load_id = _rowset_meta_pb.mutable_load_id(); |
232 | 335k | new_load_id->set_hi(load_id.hi()); |
233 | 335k | new_load_id->set_lo(load_id.lo()); |
234 | 335k | } |
235 | | |
236 | 194k | void set_job_id(const std::string& job_id) { _rowset_meta_pb.set_job_id(job_id); } |
237 | | |
238 | 0 | const std::string& job_id() const { return _rowset_meta_pb.job_id(); } |
239 | | |
240 | 0 | bool delete_flag() const { return _rowset_meta_pb.delete_flag(); } |
241 | | |
242 | 143k | int64_t creation_time() const { return _rowset_meta_pb.creation_time(); } |
243 | | |
244 | 435k | void set_creation_time(int64_t creation_time) { |
245 | 435k | return _rowset_meta_pb.set_creation_time(creation_time); |
246 | 435k | } |
247 | | |
248 | 568k | int64_t stale_at() const { |
249 | 568k | int64_t stale_time = _stale_at_s.load(); |
250 | 568k | return stale_time > 0 ? stale_time : _rowset_meta_pb.creation_time(); |
251 | 568k | } |
252 | | |
253 | 4.57k | bool has_stale_at() const { return _stale_at_s.load() > 0; } |
254 | | |
255 | 89.6k | void set_stale_at(int64_t stale_at) { _stale_at_s.store(stale_at); } |
256 | | |
257 | 5.14k | int64_t partition_id() const { return _rowset_meta_pb.partition_id(); } |
258 | | |
259 | 366k | void set_partition_id(int64_t partition_id) { |
260 | 366k | return _rowset_meta_pb.set_partition_id(partition_id); |
261 | 366k | } |
262 | | |
263 | 37.2M | int64_t num_segments() const { return _rowset_meta_pb.num_segments(); } |
264 | | |
265 | 404k | void set_num_segments(int64_t num_segments) { _rowset_meta_pb.set_num_segments(num_segments); } |
266 | | |
267 | | // Convert to RowsetMetaPB, skip_schema is only used by cloud to separate schema from rowset meta. |
268 | | void to_rowset_pb(RowsetMetaPB* rs_meta_pb, bool skip_schema = false) const; |
269 | | |
270 | | // Convert to RowsetMetaPB, skip_schema is only used by cloud to separate schema from rowset meta. |
271 | | RowsetMetaPB get_rowset_pb(bool skip_schema = false) const; |
272 | | |
273 | 56 | inline DeletePredicatePB* mutable_delete_pred_pb() { |
274 | 56 | return _rowset_meta_pb.mutable_delete_predicate(); |
275 | 56 | } |
276 | | |
277 | 2.11k | bool is_singleton_delta() const { |
278 | 2.11k | return has_version() && _rowset_meta_pb.start_version() == _rowset_meta_pb.end_version(); |
279 | 2.11k | } |
280 | | |
281 | | // Some time, we may check if this rowset is in rowset meta manager's meta by using RowsetMetaManager::check_rowset_meta. |
282 | | // But, this check behavior may cost a lot of time when it is frequent. |
283 | | // If we explicitly remove this rowset from rowset meta manager's meta, we can set _is_removed_from_rowset_meta to true, |
284 | | // And next time when we want to check if this rowset is in rowset mata manager's meta, we can |
285 | | // check is_remove_from_rowset_meta() first. |
286 | 45.8k | void set_remove_from_rowset_meta() { _is_removed_from_rowset_meta = true; } |
287 | | |
288 | 47.7k | bool is_remove_from_rowset_meta() const { return _is_removed_from_rowset_meta; } |
289 | | |
290 | 37.7k | SegmentsOverlapPB segments_overlap() const { return _rowset_meta_pb.segments_overlap_pb(); } |
291 | | |
292 | 478k | void set_segments_overlap(SegmentsOverlapPB segments_overlap) { |
293 | 478k | _rowset_meta_pb.set_segments_overlap_pb(segments_overlap); |
294 | 478k | } |
295 | | |
296 | 822k | static bool comparator(const RowsetMetaSharedPtr& left, const RowsetMetaSharedPtr& right) { |
297 | 822k | return left->end_version() < right->end_version(); |
298 | 822k | } |
299 | | |
300 | | // return true if segments in this rowset has overlapping data. |
301 | | // this is not same as `segments_overlap()` method. |
302 | | // `segments_overlap()` only return the value of "segments_overlap" field in rowset meta, |
303 | | // but "segments_overlap" may be UNKNOWN. |
304 | | // |
305 | | // Returns true if all of the following conditions are met |
306 | | // 1. the rowset contains more than one segment |
307 | | // 2. the rowset's start version == end version (non-singleton rowset was generated by compaction process |
308 | | // which always produces non-overlapped segments) |
309 | | // 3. segments_overlap() flag is not NONOVERLAPPING (OVERLAP_UNKNOWN and OVERLAPPING are OK) |
310 | 6.73M | bool is_segments_overlapping() const { |
311 | 6.73M | return num_segments() > 1 && is_singleton_delta() && segments_overlap() != NONOVERLAPPING; |
312 | 6.73M | } |
313 | | |
314 | 27 | bool produced_by_compaction() const { |
315 | 27 | return has_version() && |
316 | 28 | (start_version() < end_version() || |
317 | 28 | (start_version() == end_version() && segments_overlap() == NONOVERLAPPING)); |
318 | 27 | } |
319 | | |
320 | | // get the compaction score of this rowset. |
321 | | // if segments are overlapping, the score equals to the number of segments, |
322 | | // otherwise, score is 1. |
323 | 2.97M | uint32_t get_compaction_score() const { |
324 | | // Row binlog LMax Base([0-x]) only performs meta-only merge, so treat it as score 1. |
325 | 2.97M | if (is_row_binlog() && |
326 | 2.97M | _rowset_meta_pb.compaction_level() == |
327 | 1.48k | BinlogCompactionPolicy::kBinlogCompactionMaxLevel - 1 && |
328 | 2.97M | start_version() == 0) { |
329 | 0 | return 1; |
330 | 0 | } |
331 | | |
332 | 2.97M | uint32_t score = 0; |
333 | 2.97M | if (!is_segments_overlapping()) { |
334 | 2.97M | score = 1; |
335 | 2.97M | } else { |
336 | 320 | auto num_seg = num_segments(); |
337 | 320 | DCHECK_GT(num_seg, 0); |
338 | 320 | score = cast_set<uint32_t>(num_seg); |
339 | 320 | CHECK(score > 0); |
340 | 320 | } |
341 | 2.97M | return score; |
342 | 2.97M | } |
343 | | |
344 | 82.0k | uint32_t get_merge_way_num() const { |
345 | 82.0k | uint32_t way_num = 0; |
346 | 82.2k | if (!is_segments_overlapping()) { |
347 | 82.2k | if (num_segments() == 0) { |
348 | 44.1k | way_num = 0; |
349 | 44.1k | } else { |
350 | 38.0k | way_num = 1; |
351 | 38.0k | } |
352 | 18.4E | } else { |
353 | 18.4E | auto num_seg = num_segments(); |
354 | 18.4E | DCHECK_GT(num_seg, 0); |
355 | | |
356 | 18.4E | way_num = cast_set<uint32_t>(num_seg); |
357 | 18.4E | CHECK(way_num > 0); |
358 | 18.4E | } |
359 | 82.0k | return way_num; |
360 | 82.0k | } |
361 | | |
362 | 4.51M | void get_segments_key_bounds(std::vector<KeyBoundsPB>* segments_key_bounds) const { |
363 | 4.51M | for (const KeyBoundsPB& key_range : _rowset_meta_pb.segments_key_bounds()) { |
364 | 4.30M | segments_key_bounds->push_back(key_range); |
365 | 4.30M | } |
366 | 4.51M | } |
367 | | |
368 | 1.80k | auto& get_segments_key_bounds() const { return _rowset_meta_pb.segments_key_bounds(); } |
369 | | |
370 | 6.11M | bool is_segments_key_bounds_truncated() const { |
371 | 6.11M | return _rowset_meta_pb.has_segments_key_bounds_truncated() && |
372 | 6.11M | _rowset_meta_pb.segments_key_bounds_truncated(); |
373 | 6.11M | } |
374 | | |
375 | 338k | void set_segments_key_bounds_truncated(bool truncated) { |
376 | 338k | _rowset_meta_pb.set_segments_key_bounds_truncated(truncated); |
377 | 338k | } |
378 | | |
379 | | // When true, `segments_key_bounds` holds a single aggregated |
380 | | // [rowset_min, rowset_max] entry instead of per-segment bounds. |
381 | 4.50M | bool is_segments_key_bounds_aggregated() const { |
382 | 4.50M | return _rowset_meta_pb.has_segments_key_bounds_aggregated() && |
383 | 4.50M | _rowset_meta_pb.segments_key_bounds_aggregated(); |
384 | 4.50M | } |
385 | | |
386 | 275k | void set_segments_key_bounds_aggregated(bool aggregated) { |
387 | 275k | _rowset_meta_pb.set_segments_key_bounds_aggregated(aggregated); |
388 | 275k | } |
389 | | |
390 | 1.55M | bool get_first_segment_key_bound(KeyBoundsPB* key_bounds) { |
391 | | // for compatibility, old version has not segment key bounds |
392 | 1.55M | if (_rowset_meta_pb.segments_key_bounds_size() == 0) { |
393 | 0 | return false; |
394 | 0 | } |
395 | 1.55M | *key_bounds = *_rowset_meta_pb.segments_key_bounds().begin(); |
396 | 1.55M | return true; |
397 | 1.55M | } |
398 | | |
399 | 1.02M | bool get_last_segment_key_bound(KeyBoundsPB* key_bounds) { |
400 | 1.02M | if (_rowset_meta_pb.segments_key_bounds_size() == 0) { |
401 | 0 | return false; |
402 | 0 | } |
403 | 1.02M | *key_bounds = *_rowset_meta_pb.segments_key_bounds().rbegin(); |
404 | 1.02M | return true; |
405 | 1.02M | } |
406 | | |
407 | | // If `aggregate_into_single` is true, collapse per-segment bounds into a single |
408 | | // [rowset_min, rowset_max] entry and mark this rowset as aggregated. |
409 | | void set_segments_key_bounds(const std::vector<KeyBoundsPB>& segments_key_bounds, |
410 | | bool aggregate_into_single = false); |
411 | | |
412 | 20 | void add_segment_key_bounds(KeyBoundsPB segments_key_bounds) { |
413 | 20 | *_rowset_meta_pb.add_segments_key_bounds() = std::move(segments_key_bounds); |
414 | 20 | set_segments_overlap(OVERLAPPING); |
415 | 20 | } |
416 | | |
417 | 368k | void set_newest_write_timestamp(int64_t timestamp) { |
418 | 368k | _rowset_meta_pb.set_newest_write_timestamp(timestamp); |
419 | 368k | } |
420 | | |
421 | 581k | int64_t newest_write_timestamp() const { return _rowset_meta_pb.newest_write_timestamp(); } |
422 | | |
423 | | // for cloud only |
424 | 395 | bool has_visible_ts_ms() const { return _rowset_meta_pb.has_visible_ts_ms(); } |
425 | 388 | int64_t visible_ts_ms() const { return _rowset_meta_pb.visible_ts_ms(); } |
426 | 395 | std::chrono::time_point<std::chrono::system_clock> visible_timestamp() const { |
427 | 395 | using namespace std::chrono; |
428 | 395 | if (has_visible_ts_ms()) { |
429 | 388 | return time_point<system_clock>(milliseconds(visible_ts_ms())); |
430 | 388 | } |
431 | 7 | return system_clock::from_time_t(newest_write_timestamp()); |
432 | 395 | } |
433 | 86.7k | void set_visible_ts_ms(int64_t visible_ts_ms) { |
434 | 86.7k | _rowset_meta_pb.set_visible_ts_ms(visible_ts_ms); |
435 | 86.7k | } |
436 | | |
437 | | void set_tablet_schema(const TabletSchemaSPtr& tablet_schema); |
438 | | void set_tablet_schema(const TabletSchemaPB& tablet_schema); |
439 | | |
440 | 6.62M | const TabletSchemaSPtr& tablet_schema() const { return _schema; } |
441 | | |
442 | 192k | void set_txn_expiration(int64_t expiration) { _rowset_meta_pb.set_txn_expiration(expiration); } |
443 | | |
444 | 242k | void set_compaction_level(int64_t compaction_level) { |
445 | 242k | _rowset_meta_pb.set_compaction_level(compaction_level); |
446 | 242k | } |
447 | | |
448 | 8.23k | int64_t compaction_level() { return _rowset_meta_pb.compaction_level(); } |
449 | | |
450 | | // `seg_file_size` MUST ordered by segment id |
451 | | void add_segments_file_size(const std::vector<size_t>& seg_file_size); |
452 | | |
453 | | // Return -1 if segment file size is unknown |
454 | | int64_t segment_file_size(int seg_id) const; |
455 | | |
456 | 1.39k | const auto& segments_file_size() const { return _rowset_meta_pb.segments_file_size(); } |
457 | | |
458 | | // Used for partial update, when publish, partial update may add a new rowset and we should update rowset meta |
459 | | void merge_rowset_meta(const RowsetMeta& other); |
460 | | |
461 | | InvertedIndexFileInfo inverted_index_file_info(int seg_id); |
462 | | |
463 | 177 | const auto& inverted_index_file_info() const { |
464 | 177 | return _rowset_meta_pb.inverted_index_file_info(); |
465 | 177 | } |
466 | | |
467 | | void add_inverted_index_files_info( |
468 | | const std::vector<const InvertedIndexFileInfo*>& idx_file_info); |
469 | | |
470 | | int64_t get_metadata_size() const override; |
471 | | |
472 | | // Because the member field '_handle' is a raw pointer, use member func 'init' to replace copy ctor |
473 | | RowsetMeta(const RowsetMeta&) = delete; |
474 | | RowsetMeta operator=(const RowsetMeta&) = delete; |
475 | | |
476 | | void add_packed_slice_location(const std::string& segment_path, |
477 | | const std::string& packed_file_path, int64_t offset, |
478 | 0 | int64_t size, int64_t packed_file_size) { |
479 | 0 | auto* index_map = _rowset_meta_pb.mutable_packed_slice_locations(); |
480 | 0 | auto& index_pb = (*index_map)[segment_path]; |
481 | 0 | index_pb.set_packed_file_path(packed_file_path); |
482 | 0 | index_pb.set_offset(offset); |
483 | 0 | index_pb.set_size(size); |
484 | 0 | index_pb.set_packed_file_size(packed_file_size); |
485 | 0 | } |
486 | | |
487 | 31.3k | int32_t schema_version() const { return _rowset_meta_pb.schema_version(); } |
488 | | |
489 | 0 | std::string debug_string() const { return _rowset_meta_pb.ShortDebugString(); } |
490 | | |
491 | | // Pre-set the encryption algorithm to avoid re-entrant get_tablet calls |
492 | | // that can cause SingleFlight deadlock during tablet loading. |
493 | 169k | void set_encryption_algorithm(EncryptionAlgorithmPB algorithm) { |
494 | 169k | _determine_encryption_once.call( |
495 | 169k | [algorithm]() -> Result<EncryptionAlgorithmPB> { return algorithm; }); |
496 | 169k | } |
497 | | |
498 | 4.35M | TsoRange commit_tso() const { |
499 | 4.35M | const auto& commit_tso_pb = _rowset_meta_pb.commit_tso(); |
500 | 4.35M | return {commit_tso_pb.start_tso(), commit_tso_pb.end_tso()}; |
501 | 4.35M | } |
502 | | |
503 | 534 | bool has_commit_tso() const { return _rowset_meta_pb.has_commit_tso(); } |
504 | | |
505 | 47.3k | void set_commit_tso(const TsoRange& commit_tso) { |
506 | 47.3k | auto* commit_tso_pb = _rowset_meta_pb.mutable_commit_tso(); |
507 | 47.3k | commit_tso_pb->set_start_tso(commit_tso.start_tso()); |
508 | 47.3k | commit_tso_pb->set_end_tso(commit_tso.end_tso()); |
509 | 47.3k | } |
510 | | |
511 | 36.5k | void set_commit_tso(int64_t commit_tso) { set_commit_tso({commit_tso, commit_tso}); } |
512 | | |
513 | 85.9k | void set_cloud_fields_after_visible(int64_t visible_version, int64_t version_update_time_ms) { |
514 | | // Update rowset meta with correct version and visible_ts |
515 | | // !!ATTENTION!!: this code should be updated if there are more fields |
516 | | // in rowset meta which will be modified in meta-service when commit_txn in the future |
517 | 85.9k | set_version({visible_version, visible_version}); |
518 | 85.9k | if (version_update_time_ms > 0) { |
519 | 85.9k | set_visible_ts_ms(version_update_time_ms); |
520 | 85.9k | } |
521 | 85.9k | } |
522 | | |
523 | | private: |
524 | | bool _deserialize_from_pb(std::string_view value); |
525 | | |
526 | | bool _serialize_to_pb(std::string* value); |
527 | | |
528 | | void _init(); |
529 | | |
530 | | friend bool operator==(const RowsetMeta& a, const RowsetMeta& b); |
531 | | |
532 | 0 | friend bool operator!=(const RowsetMeta& a, const RowsetMeta& b) { return !(a == b); } |
533 | | |
534 | | private: |
535 | | RowsetMetaPB _rowset_meta_pb; |
536 | | TabletSchemaSPtr _schema; |
537 | | Cache::Handle* _handle = nullptr; |
538 | | RowsetId _rowset_id; |
539 | | StorageResource _storage_resource; |
540 | | bool _is_removed_from_rowset_meta = false; |
541 | | DorisCallOnce<Result<EncryptionAlgorithmPB>> _determine_encryption_once; |
542 | | std::atomic<int64_t> _stale_at_s {0}; |
543 | | }; |
544 | | |
545 | | using RowsetMetaMapContainer = std::unordered_map<Version, RowsetMetaSharedPtr, HashOfVersion>; |
546 | | |
547 | | } // namespace doris |
548 | | |
549 | | #endif // DORIS_BE_SRC_OLAP_ROWSET_ROWSET_META_H |