be/src/io/fs/s3_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 <atomic> |
21 | | #include <memory> |
22 | | #include <string> |
23 | | |
24 | | #include "common/status.h" |
25 | | #include "io/fs/file_reader.h" |
26 | | #include "io/fs/file_system.h" |
27 | | #include "io/fs/path.h" |
28 | | #include "io/fs/s3_file_system.h" |
29 | | #include "util/slice.h" |
30 | | |
31 | | namespace doris { |
32 | | class RuntimeProfile; |
33 | | |
34 | | namespace io { |
35 | | struct IOContext; |
36 | | |
37 | | class S3FileReader final : public FileReader { |
38 | | public: |
39 | | static Result<FileReaderSPtr> create(std::shared_ptr<const ObjClientHolder> client, |
40 | | std::string bucket, std::string key, int64_t file_size, |
41 | | RuntimeProfile* profile); |
42 | | |
43 | | S3FileReader(std::shared_ptr<const ObjClientHolder> client, std::string bucket, std::string key, |
44 | | size_t file_size, RuntimeProfile* profile); |
45 | | |
46 | | ~S3FileReader() override; |
47 | | |
48 | | Status close() override; |
49 | | |
50 | 0 | const Path& path() const override { return _path; } |
51 | | |
52 | 0 | size_t size() const override { return _file_size; } |
53 | | |
54 | 0 | bool closed() const override { return _closed.load(std::memory_order_acquire); } |
55 | | |
56 | 0 | int64_t mtime() const override { return 0; } |
57 | | |
58 | | protected: |
59 | | Status read_at_impl(size_t offset, Slice result, size_t* bytes_read, |
60 | | const IOContext* io_ctx) override; |
61 | | |
62 | | void _collect_profile_before_close() override; |
63 | | |
64 | | private: |
65 | | struct S3Statistics { |
66 | | int64_t total_get_request_counter = 0; |
67 | | int64_t too_many_request_err_counter = 0; |
68 | | int64_t too_many_request_sleep_time_ms = 0; |
69 | | int64_t total_bytes_read = 0; |
70 | | int64_t total_get_request_time_ns = 0; |
71 | | }; |
72 | | Path _path; |
73 | | size_t _file_size; |
74 | | |
75 | | std::string _bucket; |
76 | | std::string _key; |
77 | | std::shared_ptr<const ObjClientHolder> _client; |
78 | | |
79 | | std::atomic<bool> _closed = false; |
80 | | |
81 | | RuntimeProfile* _profile = nullptr; |
82 | | S3Statistics _s3_stats; |
83 | | }; |
84 | | |
85 | | } // namespace io |
86 | | } // namespace doris |