Coverage Report

Created: 2026-03-13 09:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/io/fs/remote_file_system.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 <string>
22
#include <utility>
23
#include <vector>
24
25
#include "common/status.h"
26
#include "io/fs/file_system.h"
27
#include "io/fs/path.h"
28
29
namespace doris::io {
30
31
class RemoteFileSystem : public FileSystem {
32
public:
33
    RemoteFileSystem(Path&& root_path, std::string&& id, FileSystemType type)
34
4.39k
            : FileSystem(std::move(id), type), _root_path(std::move(root_path)) {}
35
4.36k
    ~RemoteFileSystem() override = default;
36
37
    Status upload(const Path& local_file, const Path& dest_file);
38
    Status batch_upload(const std::vector<Path>& local_files,
39
                        const std::vector<Path>& remote_files);
40
    Status download(const Path& remote_file, const Path& local);
41
42
    // the root path of this fs.
43
25
    const Path& root_path() const { return _root_path; }
44
45
protected:
46
    Status open_file_impl(const Path& file, FileReaderSPtr* reader,
47
                          const FileReaderOptions* opts) override;
48
    /// upload load_file to remote remote_file
49
    /// local_file should be an absolute path on local filesystem.
50
    virtual Status upload_impl(const Path& local_file, const Path& remote_file) = 0;
51
52
    /// upload all files in load_files to remote_files
53
    /// path in local_files should be an absolute path on local filesystem.
54
    /// the size of local_files and remote_files must be equal.
55
    virtual Status batch_upload_impl(const std::vector<Path>& local_files,
56
                                     const std::vector<Path>& remote_files) = 0;
57
58
    /// download remote_file to local_file
59
    /// local_file should be an absolute path on local filesystem.
60
    virtual Status download_impl(const Path& remote_file, const Path& local_file) = 0;
61
62
    // The derived class should implement this method.
63
    // if file_size < 0, the file size should be fetched from file system
64
    virtual Status open_file_internal(const Path& file, FileReaderSPtr* reader,
65
                                      const FileReaderOptions& opts) = 0;
66
67
2.83k
    Status absolute_path(const Path& path, Path& abs_path) const override {
68
2.83k
        if (path.is_absolute()) {
69
178
            abs_path = path;
70
2.65k
        } else {
71
2.65k
            abs_path = _root_path / path;
72
2.65k
        }
73
2.83k
        return Status::OK();
74
2.83k
    }
75
76
    Path _root_path;
77
};
78
79
using RemoteFileSystemSPtr = std::shared_ptr<RemoteFileSystem>;
80
81
} // namespace doris::io