Coverage Report

Created: 2024-11-18 12:21

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