Coverage Report

Created: 2026-03-15 20:53

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/cloud/cloud_snapshot_mgr.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 <mutex>
22
#include <string>
23
#include <vector>
24
25
#include "cloud/cloud_tablet.h"
26
#include "common/status.h"
27
#include "storage/rowset/rowset_fwd.h"
28
#include "storage/storage_policy.h"
29
#include "storage/tablet/tablet_fwd.h"
30
31
namespace doris {
32
class CloudStorageEngine;
33
class RowsetMetaPB;
34
class MemTrackerLimiter;
35
36
// In cloud mode, snapshot only includes tablet metas.
37
class CloudSnapshotMgr {
38
public:
39
    CloudSnapshotMgr(CloudStorageEngine& engine);
40
41
2
    ~CloudSnapshotMgr() = default;
42
43
    /**
44
     * Creates a snapshot for the specified tablet.
45
     * Behavior:
46
     * - For restore, convert and upload snapshot.
47
     * - For backup, not implemented
48
     *
49
     * @param storage_resource. Used for set the resource id.
50
     * @param file_mapping. A map to store file mappings. (source files -> target files).
51
     * @param is_restore. Whether the snapshot is for a restore job. (default: false).
52
     * @param slice. For hdr data input, only used for restore job. (default: nullptr).
53
     * @return status.
54
     */
55
    Status make_snapshot(int64_t target_tablet_id, StorageResource& storage_resource,
56
                         std::unordered_map<std::string, std::string>& file_mapping,
57
                         bool is_restore = false, const Slice* slice = nullptr);
58
59
    /**
60
     * Releases a snapshot for the specified tablet.
61
     * Behavior:
62
     * - Marks the snapshot to final state.
63
     * - This method will only be called at the last step of completing or canceling
64
     *   the job, and FE will not care whether the status returned here is successful
65
     *   or failed. After the status is returned, the entire job will end.
66
     *
67
     * @param is_completed. True, indicates the job is completing.
68
     *                      False, indicates the job is canceling.
69
     * @return status.
70
     */
71
    Status release_snapshot(int64_t tablet_id, bool is_completed);
72
73
    /**
74
     * Commits a snapshot for the specified tablet, only used for restore job.
75
     * Behavior:
76
     * - Finalizes the uploaded snapshot and clear local tablet cache.
77
     *
78
     * @return status.
79
     */
80
    Status commit_snapshot(int64_t tablet_id);
81
82
    Status convert_rowsets(TabletMetaPB* out, const TabletMetaPB& in, int64_t tablet_id,
83
                           CloudTabletSPtr& target_tablet, StorageResource& storage_resource,
84
                           std::unordered_map<std::string, std::string>& file_mapping);
85
86
private:
87
    Status _create_rowset_meta(RowsetMetaPB* new_rowset_meta_pb, const RowsetMetaPB& source_meta,
88
                               int64_t target_tablet_id, CloudTabletSPtr& target_tablet,
89
                               StorageResource& storage_resource, TabletSchemaSPtr tablet_schema,
90
                               std::unordered_map<std::string, std::string>& file_mapping,
91
                               std::unordered_map<RowsetId, RowsetId>& rowset_id_mapping);
92
93
    Status _rename_index_ids(TabletSchemaPB& schema_pb,
94
                             const TabletSchemaSPtr& tablet_schema) const;
95
96
private:
97
    CloudStorageEngine& _engine;
98
    std::atomic<uint64_t> _snapshot_base_id {0};
99
    std::shared_ptr<MemTrackerLimiter> _mem_tracker;
100
}; // CloudSnapshotMgr
101
102
} // namespace doris