Coverage Report

Created: 2026-10-30 22:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
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
2
    const Path& path() const override { return _path; }
51
52
30
    size_t size() const override { return _file_size; }
53
54
873
    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
        // The reader is shared by foreground reads and parallel background hole-fill GETs.
67
        std::atomic<int64_t> total_get_request_counter {0};
68
        std::atomic<int64_t> too_many_request_err_counter {0};
69
        std::atomic<int64_t> too_many_request_sleep_time_ms {0};
70
        std::atomic<int64_t> total_bytes_read {0};
71
        std::atomic<int64_t> total_get_request_time_ns {0};
72
    };
73
    Path _path;
74
    size_t _file_size;
75
76
    std::string _bucket;
77
    std::string _key;
78
    std::shared_ptr<const ObjClientHolder> _client;
79
80
    std::atomic<bool> _closed = false;
81
82
    RuntimeProfile* _profile = nullptr;
83
    S3Statistics _s3_stats;
84
};
85
86
} // namespace io
87
} // namespace doris