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, RuntimeProfile* profile); |
46 | | |
47 | | HdfsFileReader(Path path, std::string fs_name, FileHandleCache::Accessor accessor, |
48 | | RuntimeProfile* profile, int64_t mtime = 0); |
49 | | |
50 | | ~HdfsFileReader() override; |
51 | | |
52 | | Status close() override; |
53 | | |
54 | 165k | const Path& path() const override { return _path; } |
55 | | |
56 | 305k | size_t size() const override { return _handle->file_size(); } |
57 | | |
58 | 384k | bool closed() const override { return _closed.load(std::memory_order_acquire); } |
59 | | |
60 | 106k | 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 | | void _collect_profile_before_close() override; |
67 | | |
68 | | Status do_read_at_impl(size_t offset, Slice result, size_t* bytes_read, |
69 | | const IOContext* io_ctx); |
70 | | |
71 | | private: |
72 | | #ifdef USE_HADOOP_HDFS |
73 | | struct HDFSProfile { |
74 | | RuntimeProfile::Counter* total_bytes_read = nullptr; |
75 | | RuntimeProfile::Counter* total_local_bytes_read = nullptr; |
76 | | RuntimeProfile::Counter* total_short_circuit_bytes_read = nullptr; |
77 | | RuntimeProfile::Counter* total_total_zero_copy_bytes_read = nullptr; |
78 | | |
79 | | RuntimeProfile::Counter* total_hedged_read = nullptr; |
80 | | RuntimeProfile::Counter* hedged_read_in_cur_thread = nullptr; |
81 | | RuntimeProfile::Counter* hedged_read_wins = nullptr; |
82 | | }; |
83 | | #endif |
84 | | |
85 | | Path _path; |
86 | | std::string _fs_name; |
87 | | FileHandleCache::Accessor _accessor; |
88 | | CachedHdfsFileHandle* _handle = nullptr; // owned by _cached_file_handle |
89 | | std::atomic<bool> _closed = false; |
90 | | RuntimeProfile* _profile = nullptr; |
91 | | int64_t _mtime; |
92 | | #ifdef USE_HADOOP_HDFS |
93 | | HDFSProfile _hdfs_profile; |
94 | | #endif |
95 | | }; |
96 | | } // namespace doris::io |