be/src/io/fs/packed_file_reader.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 | | |
22 | | #include "butil/macros.h" |
23 | | #include "common/status.h" |
24 | | #include "io/fs/file_reader.h" |
25 | | #include "io/fs/file_reader_writer_fwd.h" |
26 | | #include "io/fs/path.h" |
27 | | |
28 | | namespace doris::io { |
29 | | |
30 | | struct IOContext; |
31 | | |
32 | | // FileReader wrapper that reads data from packed file using offset and size |
33 | | // It wraps an inner reader that points to the packed file, |
34 | | // and adjusts read offsets based on the slice's position in the packed file |
35 | | class PackedFileReader final : public FileReader { |
36 | | public: |
37 | | PackedFileReader(FileReaderSPtr inner_reader, Path path, int64_t offset, int64_t size); |
38 | | ~PackedFileReader() override; |
39 | | |
40 | | PackedFileReader(const PackedFileReader&) = delete; |
41 | | const PackedFileReader& operator=(const PackedFileReader&) = delete; |
42 | | |
43 | | Status close() override; |
44 | | |
45 | 1.00k | const Path& path() const override { return _path; } |
46 | | |
47 | 16.2k | size_t size() const override { return _file_size; } |
48 | | |
49 | 8.12k | bool closed() const override { return _closed; } |
50 | | |
51 | 0 | int64_t mtime() const override { return _inner_reader->mtime(); } |
52 | | |
53 | | protected: |
54 | | Status read_at_impl(size_t offset, Slice result, size_t* bytes_read, |
55 | | const IOContext* io_ctx) override; |
56 | | |
57 | | private: |
58 | | FileReaderSPtr _inner_reader; |
59 | | Path _path; |
60 | | int64_t _packed_file_offset; // Offset in packed file where this slice starts |
61 | | int64_t _file_size; // Size of the slice |
62 | | bool _closed = false; |
63 | | }; |
64 | | |
65 | | } // namespace doris::io |