Coverage Report

Created: 2026-03-17 00:16

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/storage/compaction/single_replica_compaction.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 <vector>
21
22
#include "common/status.h"
23
#include "storage/compaction/compaction.h"
24
#include "storage/rowset/pending_rowset_helper.h"
25
26
namespace doris {
27
28
class DataDir;
29
30
//  SingleReplicaCompaction is used to fetch peer replica compaction result.
31
class SingleReplicaCompaction final : public CompactionMixin {
32
public:
33
    SingleReplicaCompaction(StorageEngine& engine, const TabletSharedPtr& tablet,
34
                            CompactionType compaction_type);
35
    ~SingleReplicaCompaction() override;
36
37
    Status prepare_compact() override;
38
    Status execute_compact() override;
39
40
0
    inline CompactionType real_compact_type() const { return _compaction_type; }
41
42
protected:
43
0
    std::string_view compaction_name() const override { return "single replica compaction"; }
44
0
    ReaderType compaction_type() const override {
45
0
        return (_compaction_type == CompactionType::CUMULATIVE_COMPACTION)
46
0
                       ? ReaderType::READER_CUMULATIVE_COMPACTION
47
0
                       : ReaderType::READER_BASE_COMPACTION;
48
0
    }
49
50
private:
51
    Status _do_single_replica_compaction();
52
    Status _do_single_replica_compaction_impl();
53
    bool _find_rowset_to_fetch(const std::vector<Version>& peer_versions, Version* proper_version);
54
    Status _get_rowset_verisons_from_peer(const TReplicaInfo& addr,
55
                                          std::vector<Version>* peer_versions);
56
    Status _fetch_rowset(const TReplicaInfo& addr, const std::string& token,
57
                         const Version& version);
58
    Status _make_snapshot(const std::string& ip, int port, TTableId tablet_id,
59
                          TSchemaHash schema_hash, int timeout_s, const Version& version,
60
                          std::string* snapshot_path);
61
    Status _download_files(DataDir* data_dir, const std::string& remote_url_prefix,
62
                           const std::string& local_path);
63
    Status _release_snapshot(const std::string& ip, int port, const std::string& snapshot_path);
64
    Status _finish_clone(const std::string& clone_dir, const Version& version);
65
    CompactionType _compaction_type;
66
67
    std::vector<PendingRowsetGuard> _pending_rs_guards;
68
};
69
70
} // namespace doris