Coverage Report

Created: 2026-03-13 09:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/io/fs/packed_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 <string>
21
#include <unordered_map>
22
23
#include "common/status.h"
24
#include "io/fs/file_system.h"
25
#include "io/fs/packed_file_manager.h"
26
27
namespace doris::io {
28
29
// FileSystem wrapper that handles packed file logic for small files
30
// When creating a file, it wraps the writer with PackedFileWriter
31
// When opening a file, it checks if the file is in a packed file and wraps with PackedFileReader
32
class PackedFileSystem final : public FileSystem {
33
public:
34
    PackedFileSystem(FileSystemSPtr inner_fs, PackedAppendContext append_info = {});
35
36
    PackedFileSystem(FileSystemSPtr inner_fs,
37
                     std::unordered_map<std::string, PackedSliceLocation> index_map,
38
                     PackedAppendContext append_info = {});
39
40
939k
    ~PackedFileSystem() override = default;
41
42
    PackedFileSystem(const PackedFileSystem&) = delete;
43
    PackedFileSystem& operator=(const PackedFileSystem&) = delete;
44
45
protected:
46
    // Create file and wrap writer with PackedFileWriter
47
    Status create_file_impl(const Path& file, FileWriterPtr* writer,
48
                            const FileWriterOptions* opts) override;
49
50
    // Open file and wrap reader with PackedFileReader if file is in packed file
51
    Status open_file_impl(const Path& file, FileReaderSPtr* reader,
52
                          const FileReaderOptions* opts) override;
53
54
    // Other operations not supported for PackedFileSystem
55
1
    Status create_directory_impl(const Path& dir, bool failed_if_exists = false) override {
56
1
        return Status::InternalError("PackedFileSystem does not support create_directory");
57
1
    }
58
59
1
    Status delete_file_impl(const Path& file) override {
60
1
        return Status::InternalError("PackedFileSystem does not support delete_file");
61
1
    }
62
63
0
    Status batch_delete_impl(const std::vector<Path>& files) override {
64
0
        return Status::InternalError("PackedFileSystem does not support batch_delete");
65
0
    }
66
67
1
    Status delete_directory_impl(const Path& dir) override {
68
1
        return Status::InternalError("PackedFileSystem does not support delete_directory");
69
1
    }
70
71
    Status exists_impl(const Path& path, bool* res) const override;
72
73
    Status file_size_impl(const Path& file, int64_t* file_size) const override;
74
75
    Status list_impl(const Path& dir, bool only_file, std::vector<FileInfo>* files,
76
1
                     bool* exists) override {
77
1
        return Status::InternalError("PackedFileSystem does not support list");
78
1
    }
79
80
1
    Status rename_impl(const Path& orig_name, const Path& new_name) override {
81
1
        return Status::InternalError("PackedFileSystem does not support rename");
82
1
    }
83
84
949k
    Status absolute_path(const Path& path, Path& abs_path) const override {
85
949k
        abs_path = path;
86
949k
        return Status::OK();
87
949k
    }
88
89
private:
90
    FileSystemSPtr _inner_fs;
91
    // Map from small file path to packed file slice location
92
    std::unordered_map<std::string, PackedSliceLocation> _index_map;
93
    bool _index_map_initialized = false;
94
    PackedAppendContext _append_info;
95
};
96
97
} // namespace doris::io