Coverage Report

Created: 2026-09-02 21:02

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/io/fs/hdfs_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 <stddef.h>
21
22
#include <atomic>
23
#include <memory>
24
#include <string>
25
26
#include "common/status.h"
27
#include "io/fs/file_handle_cache.h"
28
#include "io/fs/file_reader.h"
29
#include "io/fs/file_system.h"
30
#include "io/fs/hdfs.h"
31
#include "io/fs/hdfs_file_system.h"
32
#include "io/fs/path.h"
33
#include "util/slice.h"
34
35
namespace doris::io {
36
struct IOContext;
37
38
class HdfsFileReader final : public FileReader {
39
public:
40
    // Accepted path format:
41
    // - fs_name/path_to_file
42
    // - /path_to_file
43
    // TODO(plat1ko): Support related path for cloud mode
44
    static Result<FileReaderSPtr> create(Path path, const hdfsFS& fs, std::string fs_name,
45
                                         const FileReaderOptions& opts);
46
47
    HdfsFileReader(Path path, std::string fs_name, FileHandleCache::Accessor accessor,
48
                   int64_t mtime = 0);
49
50
    ~HdfsFileReader() override;
51
52
    Status close() override;
53
54
0
    const Path& path() const override { return _path; }
55
56
0
    size_t size() const override { return _handle->file_size(); }
57
58
0
    bool closed() const override { return _closed.load(std::memory_order_acquire); }
59
60
0
    int64_t mtime() const override { return _mtime; }
61
62
protected:
63
    Status read_at_impl(size_t offset, Slice result, size_t* bytes_read,
64
                        const IOContext* io_ctx) override;
65
66
    Status do_read_at_impl(size_t offset, Slice result, size_t* bytes_read,
67
                           const IOContext* io_ctx);
68
69
private:
70
    Path _path;
71
    std::string _fs_name;
72
    FileHandleCache::Accessor _accessor;
73
    CachedHdfsFileHandle* _handle = nullptr; // owned by _cached_file_handle
74
    std::atomic<bool> _closed = false;
75
    int64_t _mtime;
76
};
77
} // namespace doris::io