Coverage Report

Created: 2026-03-17 00:16

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/storage/task/engine_clone_task.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/Types_types.h>
21
22
#include <memory>
23
#include <string>
24
#include <vector>
25
26
#include "common/status.h"
27
#include "storage/rowset/pending_rowset_helper.h"
28
#include "storage/tablet/tablet_fwd.h"
29
#include "storage/task/engine_task.h"
30
31
namespace doris {
32
class DataDir;
33
class TCloneReq;
34
class TTabletInfo;
35
class Tablet;
36
struct Version;
37
class StorageEngine;
38
class ClusterInfo;
39
40
const std::string HTTP_REQUEST_PREFIX = "/api/_tablet/_download?";
41
const std::string HTTP_REQUEST_TOKEN_PARAM = "token=";
42
const std::string HTTP_REQUEST_FILE_PARAM = "&file=";
43
const uint32_t DOWNLOAD_FILE_MAX_RETRY = 3;
44
const uint32_t LIST_REMOTE_FILE_TIMEOUT = 15;
45
const uint32_t GET_LENGTH_TIMEOUT = 10;
46
47
// base class for storage engine
48
// add "Engine" as task prefix to prevent duplicate name with agent task
49
class EngineCloneTask final : public EngineTask {
50
public:
51
    Status execute() override;
52
53
    EngineCloneTask(StorageEngine& engine, const TCloneReq& clone_req,
54
                    const ClusterInfo* cluster_info, int64_t signature,
55
                    std::vector<TTabletInfo>* tablet_infos);
56
0
    ~EngineCloneTask() override = default;
57
58
0
    bool is_new_tablet() const { return _is_new_tablet; }
59
60
0
    int64_t get_copy_size() const { return _copy_size; }
61
0
    int64_t get_copy_time_ms() const { return _copy_time_ms; }
62
63
private:
64
    Status _do_clone();
65
66
    virtual Status _finish_clone(Tablet* tablet, const std::string& clone_dir, int64_t version,
67
                                 bool is_incremental_clone);
68
69
    Status _finish_incremental_clone(Tablet* tablet, const TabletMetaSharedPtr& cloned_tablet_meta,
70
                                     int64_t version);
71
72
    Status _finish_full_clone(Tablet* tablet, const TabletMetaSharedPtr& cloned_tablet_meta);
73
74
    Status _make_and_download_snapshots(DataDir& data_dir, const std::string& local_data_path,
75
                                        TBackend* src_host, std::string* src_file_path,
76
                                        const std::vector<Version>& missing_versions,
77
                                        bool* allow_incremental_clone);
78
79
    Status _set_tablet_info();
80
81
    // Download tablet files from
82
    Status _download_files(DataDir* data_dir, const std::string& remote_url_prefix,
83
                           const std::string& local_path);
84
85
    Status _batch_download_files(DataDir* data_dir, const std::string& endpoint,
86
                                 const std::string& remote_dir, const std::string& local_dir);
87
88
    Status _make_snapshot(const std::string& ip, int port, TTableId tablet_id,
89
                          TSchemaHash schema_hash, int timeout_s,
90
                          const std::vector<Version>& missing_versions, std::string* snapshot_path,
91
                          bool* allow_incremental_clone);
92
93
    Status _release_snapshot(const std::string& ip, int port, const std::string& snapshot_path);
94
95
private:
96
    StorageEngine& _engine;
97
    const TCloneReq& _clone_req;
98
    std::vector<TTabletInfo>* _tablet_infos = nullptr;
99
    int64_t _signature;
100
    const ClusterInfo* _cluster_info;
101
    int64_t _copy_size;
102
    int64_t _copy_time_ms;
103
    std::vector<PendingRowsetGuard> _pending_rs_guards;
104
    bool _is_new_tablet = false;
105
}; // EngineTask
106
107
} // namespace doris