be/src/io/fs/file_reader.cpp
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 | | #include "io/fs/file_reader.h" |
19 | | |
20 | | #include <bthread/bthread.h> |
21 | | #include <glog/logging.h> |
22 | | |
23 | | #include "io/cache/cached_remote_file_reader.h" |
24 | | #include "io/fs/file_system.h" |
25 | | #include "util/async_io.h" |
26 | | |
27 | | namespace doris::io { |
28 | | |
29 | | const std::string FileReader::VIRTUAL_REMOTE_DATA_DIR = "virtual_remote_data_dir"; |
30 | | |
31 | | Status FileReader::read_at(size_t offset, Slice result, size_t* bytes_read, |
32 | 45.6M | const IOContext* io_ctx) { |
33 | 45.6M | DCHECK(bthread_self() == 0); |
34 | 45.6M | Status st = read_at_impl(offset, result, bytes_read, io_ctx); |
35 | 45.6M | if (!st) { |
36 | 7 | LOG(WARNING) << st; |
37 | 7 | } |
38 | 45.6M | return st; |
39 | 45.6M | } |
40 | | |
41 | | Result<FileReaderSPtr> create_cached_file_reader(FileReaderSPtr raw_reader, |
42 | 2.73M | const FileReaderOptions& opts) { |
43 | 2.73M | switch (opts.cache_type) { |
44 | 948k | case io::FileCachePolicy::NO_CACHE: |
45 | 948k | return raw_reader; |
46 | 1.78M | case FileCachePolicy::FILE_BLOCK_CACHE: |
47 | 1.78M | return std::make_shared<CachedRemoteFileReader>(std::move(raw_reader), opts); |
48 | 0 | default: |
49 | 0 | return ResultError(Status::InternalError("Unknown cache type: {}", opts.cache_type)); |
50 | 2.73M | } |
51 | 2.73M | } |
52 | | |
53 | | } // namespace doris::io |