be/src/storage/rowset/segcompaction.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 <memory> |
21 | | #include <vector> |
22 | | |
23 | | #include "common/status.h" |
24 | | #include "io/fs/file_reader_writer_fwd.h" |
25 | | #include "storage/index/index_file_writer.h" |
26 | | #include "storage/merger.h" |
27 | | #include "storage/segment/segment.h" |
28 | | #include "storage/simple_rowid_conversion.h" |
29 | | #include "storage/tablet/tablet.h" |
30 | | |
31 | | namespace doris { |
32 | | class Schema; |
33 | | |
34 | | namespace segment_v2 { |
35 | | class SegmentWriter; |
36 | | } // namespace segment_v2 |
37 | | class RowSourcesBuffer; |
38 | | class VerticalBlockReader; |
39 | | struct OlapReaderStatistics; |
40 | | |
41 | | using SegCompactionCandidates = std::vector<segment_v2::SegmentSharedPtr>; |
42 | | using SegCompactionCandidatesSharedPtr = std::shared_ptr<SegCompactionCandidates>; |
43 | | |
44 | | class BetaRowsetWriter; |
45 | | |
46 | | class SegcompactionWorker { |
47 | | friend class BetaRowsetWriter; |
48 | | |
49 | | public: |
50 | | explicit SegcompactionWorker(BetaRowsetWriter* writer); |
51 | | |
52 | 1.16k | ~SegcompactionWorker() { |
53 | 1.16k | DCHECK(_seg_compact_mem_tracker != nullptr); |
54 | 1.16k | SCOPED_SWITCH_THREAD_MEM_TRACKER_LIMITER(_seg_compact_mem_tracker); |
55 | 1.16k | if (_rowid_conversion) { |
56 | 3 | _rowid_conversion.reset(); |
57 | 3 | } |
58 | 1.16k | } |
59 | | |
60 | | void compact_segments(SegCompactionCandidatesSharedPtr segments); |
61 | | |
62 | | bool need_convert_delete_bitmap(); |
63 | | |
64 | | void convert_segment_delete_bitmap(DeleteBitmapPtr src_delete_bitmap, uint32_t src_seg_id, |
65 | | uint32_t dest_seg_id); |
66 | | void convert_segment_delete_bitmap(DeleteBitmapPtr src_delete_bitmap, uint32_t src_begin, |
67 | | uint32_t src_end, uint32_t dest_seg_id); |
68 | 4 | DeleteBitmapPtr get_converted_delete_bitmap() { return _converted_delete_bitmap; } |
69 | | |
70 | 761 | io::FileWriterPtr& get_file_writer() { return _file_writer; } |
71 | 24 | IndexFileWriterPtr& get_inverted_index_file_writer() { return _index_file_writer; } |
72 | | |
73 | | // set the cancel flag, tasks already started will not be cancelled. |
74 | | bool cancel(); |
75 | | |
76 | | void init_mem_tracker(const RowsetWriterContext& rowset_writer_context); |
77 | | |
78 | | private: |
79 | | Status _create_segment_writer_for_segcompaction( |
80 | | std::unique_ptr<segment_v2::SegmentWriter>* writer, uint32_t begin, uint32_t end); |
81 | | Status _get_segcompaction_reader(SegCompactionCandidatesSharedPtr segments, |
82 | | TabletSharedPtr tablet, std::shared_ptr<Schema> schema, |
83 | | OlapReaderStatistics* stat, RowSourcesBuffer& row_sources_buf, |
84 | | bool is_key, std::vector<uint32_t>& return_columns, |
85 | | std::vector<uint32_t>& key_group_cluster_key_idxes, |
86 | | std::unique_ptr<VerticalBlockReader>* reader); |
87 | | std::unique_ptr<segment_v2::SegmentWriter> _create_segcompaction_writer(uint32_t begin, |
88 | | uint32_t end); |
89 | | Status _delete_original_segments(uint32_t begin, uint32_t end); |
90 | | Status _check_correctness(OlapReaderStatistics& reader_stat, Merger::Statistics& merger_stat, |
91 | | uint32_t begin, uint32_t end, bool is_mow_with_cluster_keys); |
92 | | Status _do_compact_segments(SegCompactionCandidatesSharedPtr segments); |
93 | | |
94 | | private: |
95 | | //TODO(zhengyu): current impl depends heavily on the access to feilds of BetaRowsetWriter |
96 | | // Currently cloud storage engine doesn't need segcompaction |
97 | | BetaRowsetWriter* _writer = nullptr; |
98 | | io::FileWriterPtr _file_writer; |
99 | | IndexFileWriterPtr _index_file_writer = nullptr; |
100 | | |
101 | | // for unique key mow table |
102 | | std::unique_ptr<SimpleRowIdConversion> _rowid_conversion = nullptr; |
103 | | DeleteBitmapPtr _converted_delete_bitmap; |
104 | | std::shared_ptr<MemTrackerLimiter> _seg_compact_mem_tracker = nullptr; |
105 | | |
106 | | // the state is not mutable when 1)actual compaction operation started or 2) cancelled |
107 | | std::atomic<bool> _is_compacting_state_mutable = true; |
108 | | }; |
109 | | } // namespace doris |