Coverage Report

Created: 2026-03-12 17:07

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/load/channel/load_stream_writer.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/internal_service.pb.h>
21
22
#include <memory>
23
#include <mutex>
24
#include <vector>
25
26
#include "butil/iobuf.h"
27
#include "common/status.h"
28
#include "io/fs/file_reader_writer_fwd.h"
29
#include "load/delta_writer/delta_writer_context.h"
30
#include "runtime/workload_management/resource_context.h"
31
#include "storage/tablet/tablet_fwd.h"
32
33
namespace doris {
34
35
class StorageEngine;
36
class TupleDescriptor;
37
class SlotDescriptor;
38
class OlapTableSchemaParam;
39
class RowsetWriter;
40
class RuntimeProfile;
41
struct SegmentStatistics;
42
using SegmentStatisticsSharedPtr = std::shared_ptr<SegmentStatistics>;
43
class BaseRowsetBuilder;
44
45
class Block;
46
47
// Builder from segments (load, index, tablet).
48
class LoadStreamWriter {
49
public:
50
    LoadStreamWriter(WriteRequest* context, RuntimeProfile* profile);
51
52
    ~LoadStreamWriter();
53
54
    Status init();
55
56
    Status append_data(uint32_t segid, uint64_t offset, butil::IOBuf buf,
57
                       FileType file_type = FileType::SEGMENT_FILE);
58
59
    Status close_writer(uint32_t segid, FileType file_type);
60
61
    Status add_segment(uint32_t segid, const SegmentStatistics& stat);
62
63
100
    Status pre_close() {
64
100
        std::lock_guard<std::mutex> l(_lock);
65
100
        return _pre_close();
66
100
    }
67
68
    // wait for all memtables to be flushed.
69
    Status close();
70
71
private:
72
    Status _calc_file_size(uint32_t segid, FileType file_type, size_t* file_size);
73
74
    // without lock
75
    Status _pre_close();
76
77
    bool _is_init = false;
78
    bool _is_canceled = false;
79
    bool _pre_closed = false;
80
    WriteRequest _req;
81
    std::unique_ptr<BaseRowsetBuilder> _rowset_builder;
82
    std::shared_ptr<RowsetWriter> _rowset_writer;
83
    std::mutex _lock;
84
85
    std::unordered_map<uint32_t /*segid*/, SegmentStatisticsSharedPtr> _segment_stat_map;
86
    std::mutex _segment_stat_map_lock;
87
    std::vector<io::FileWriterPtr> _segment_file_writers;
88
    std::vector<io::FileWriterPtr> _inverted_file_writers;
89
    std::shared_ptr<ResourceContext> _resource_ctx;
90
};
91
92
using LoadStreamWriterSharedPtr = std::shared_ptr<LoadStreamWriter>;
93
94
} // namespace doris