Coverage Report

Created: 2024-11-21 13:02

/root/doris/be/src/olap/snapshot_manager.h
Line
Count
Source (jump to first uncovered line)
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 <stdint.h>
21
22
#include <memory>
23
#include <mutex>
24
#include <string>
25
#include <vector>
26
27
#include "common/status.h"
28
#include "olap/rowset/pending_rowset_helper.h"
29
#include "olap/rowset/rowset.h"
30
#include "olap/tablet.h"
31
#include "olap/tablet_schema.h"
32
#include "runtime/memory/mem_tracker_limiter.h"
33
34
namespace doris {
35
class RowsetMetaPB;
36
class TSnapshotRequest;
37
struct RowsetId;
38
39
class SnapshotManager {
40
public:
41
0
    ~SnapshotManager() {}
42
43
    /// Create a snapshot
44
    /// snapshot_path: out param, the dir of snapshot
45
    /// allow_incremental_clone: out param, true if it is an incremental clone
46
    Status make_snapshot(const TSnapshotRequest& request, std::string* snapshot_path,
47
                         bool* allow_incremental_clone);
48
49
    std::string static get_schema_hash_full_path(const TabletSharedPtr& ref_tablet,
50
                                                 const std::string& prefix);
51
52
    // @brief 释放snapshot
53
    // @param snapshot_path [in] 要被释放的snapshot的路径,只包含到ID
54
    Status release_snapshot(const std::string& snapshot_path);
55
56
    static SnapshotManager* instance();
57
58
    Result<std::vector<PendingRowsetGuard>> convert_rowset_ids(const std::string& clone_dir,
59
                                                               int64_t tablet_id,
60
                                                               int64_t replica_id,
61
                                                               int64_t partition_id,
62
                                                               int32_t schema_hash);
63
64
private:
65
1
    SnapshotManager() : _snapshot_base_id(0) {
66
1
        _mem_tracker =
67
1
                MemTrackerLimiter::create_shared(MemTrackerLimiter::Type::OTHER, "SnapshotManager");
68
1
    }
69
70
    Status _calc_snapshot_id_path(const TabletSharedPtr& tablet, int64_t timeout_s,
71
                                  std::string* out_path);
72
73
    std::string _get_header_full_path(const TabletSharedPtr& ref_tablet,
74
                                      const std::string& schema_hash_path) const;
75
76
    std::string _get_json_header_full_path(const TabletSharedPtr& ref_tablet,
77
                                           const std::string& schema_hash_path) const;
78
79
    Status _link_index_and_data_files(const std::string& header_path,
80
                                      const TabletSharedPtr& ref_tablet,
81
                                      const std::vector<RowsetSharedPtr>& consistent_rowsets);
82
83
    Status _create_snapshot_files(const TabletSharedPtr& ref_tablet,
84
                                  const TabletSharedPtr& target_tablet,
85
                                  const TSnapshotRequest& request, std::string* snapshot_path,
86
                                  bool* allow_incremental_clone);
87
88
    Status _prepare_snapshot_dir(const TabletSharedPtr& ref_tablet, std::string* snapshot_id_path);
89
90
    Status _rename_rowset_id(const RowsetMetaPB& rs_meta_pb, const std::string& new_tablet_path,
91
                             TabletSchemaSPtr tablet_schema, const RowsetId& next_id,
92
                             RowsetMetaPB* new_rs_meta_pb);
93
94
private:
95
    static SnapshotManager* _s_instance;
96
    static std::mutex _mlock;
97
98
    // snapshot
99
    std::mutex _snapshot_mutex;
100
    uint64_t _snapshot_base_id;
101
102
    std::shared_ptr<MemTrackerLimiter> _mem_tracker;
103
}; // SnapshotManager
104
105
} // namespace doris