Coverage Report

Created: 2026-06-08 20:12

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
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 <butil/iobuf.h>
22
#include <glog/logging.h>
23
24
#include "io/cache/cached_remote_file_reader.h"
25
#include "io/fs/file_system.h"
26
#include "util/async_io.h"
27
28
namespace doris::io {
29
30
const std::string FileReader::VIRTUAL_REMOTE_DATA_DIR = "virtual_remote_data_dir";
31
32
Status FileReader::read_at(size_t offset, Slice result, size_t* bytes_read,
33
13.6M
                           const IOContext* io_ctx) {
34
13.6M
    DCHECK(bthread_self() == 0);
35
13.6M
    Status st = read_at_impl(offset, result, bytes_read, io_ctx);
36
13.6M
    if (!st) {
37
50
        LOG(WARNING) << st;
38
50
    }
39
13.6M
    return st;
40
13.6M
}
41
42
Status FileReader::read_at_iobuf(size_t offset, size_t bytes_req, butil::IOBuf* out,
43
6
                                 size_t* bytes_read, const IOContext* io_ctx) {
44
6
    DCHECK(bthread_self() == 0);
45
6
    Status st = read_at_iobuf_impl(offset, bytes_req, out, bytes_read, io_ctx);
46
6
    if (!st) {
47
0
        LOG(WARNING) << st;
48
0
    }
49
6
    return st;
50
6
}
51
52
Status FileReader::read_at_iobuf_impl(size_t offset, size_t bytes_req, butil::IOBuf* out,
53
0
                                      size_t* bytes_read, const IOContext* io_ctx) {
54
0
    if (out == nullptr || bytes_read == nullptr) {
55
0
        return Status::InvalidArgument("read_at_iobuf requires non-null out and bytes_read");
56
0
    }
57
0
    *bytes_read = 0;
58
0
    (void)offset;
59
0
    (void)bytes_req;
60
0
    (void)io_ctx;
61
0
    return Status::NotSupported("read_at_iobuf is not supported by current FileReader");
62
0
}
63
64
Result<FileReaderSPtr> create_cached_file_reader(FileReaderSPtr raw_reader,
65
512k
                                                 const FileReaderOptions& opts) {
66
512k
    switch (opts.cache_type) {
67
288k
    case io::FileCachePolicy::NO_CACHE:
68
288k
        return raw_reader;
69
224k
    case FileCachePolicy::FILE_BLOCK_CACHE:
70
224k
        return std::make_shared<CachedRemoteFileReader>(std::move(raw_reader), opts);
71
0
    default:
72
0
        return ResultError(Status::InternalError("Unknown cache type: {}", opts.cache_type));
73
512k
    }
74
512k
}
75
76
} // namespace doris::io