Coverage Report

Created: 2026-07-03 18:10

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/io/cache/peer_file_cache_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 <butil/iobuf.h>
21
22
#include <atomic>
23
#include <memory>
24
#include <string>
25
#include <vector>
26
27
#include "common/status.h"
28
#include "io/cache/file_block.h"
29
#include "io/fs/file_reader.h"
30
#include "io/fs/file_system.h"
31
#include "io/fs/path.h"
32
#include "io/fs/s3_file_system.h"
33
34
namespace doris {
35
class RuntimeProfile;
36
37
namespace io {
38
struct IOContext;
39
40
struct PeerFetchChunk {
41
    size_t block_index = 0;
42
    size_t block_offset = 0;
43
    butil::IOBuf payload;
44
};
45
46
struct PeerFetchResult {
47
    std::vector<PeerFetchChunk> chunks;
48
    size_t bytes_read = 0;
49
50
5.21k
    void clear() {
51
5.21k
        chunks.clear();
52
5.21k
        bytes_read = 0;
53
5.21k
    }
54
};
55
56
class PeerFileCacheReader final {
57
public:
58
    /**
59
     * Construct a peer file cache reader bound to a specific file and peer endpoint.
60
     *
61
     * Params:
62
     * - file_path: Path of the target file whose cache blocks will be fetched from a peer.
63
     * - is_doris_table: Whether the target file is a Doris table segment; only true is supported.
64
     * - host: Peer hostname or IP address to fetch from.
65
     * - port: Peer BRPC service port.
66
     */
67
    PeerFileCacheReader(const io::Path& file_path, bool is_doris_table, std::string host, int port);
68
    ~PeerFileCacheReader();
69
    /**
70
     * Fetch data blocks from a peer into a PeerFetchResult.
71
     *
72
     * Behavior:
73
     * - Supports only Doris table segment files (is_doris_table=true); otherwise returns NotSupported.
74
     * - Builds a BRPC request to invoke peer fetch_peer_data using the given blocks.
75
     * - Advertises attachment support and accepts either protobuf payload mode or attachment mode.
76
     * - Populates result with sparse PeerFetchChunk entries matching the requested block ranges.
77
     * - Succeeds only if the peer response exactly covers all requested block ranges.
78
     *
79
     * Params:
80
     * - blocks: List of file blocks to fetch (global file offsets, inclusive ranges).
81
     * - result: Output structure holding sparse chunks and total bytes_read.
82
     * - file_size: Size of the file to be read.
83
     * - ctx: IO context (kept for interface symmetry).
84
     *
85
     * Returns:
86
     * - OK: Successfully populated all requested block bytes into the result.
87
     * - NotSupported: The file is not a Doris table segment.
88
     */
89
    Status fetch_blocks(const std::vector<FileBlockSPtr>& blocks, PeerFetchResult* result,
90
                        size_t file_size, const IOContext* ctx, bool request_fill = false,
91
                        int64_t tablet_id = 0, std::string resource_id = {});
92
93
private:
94
    io::Path _path;
95
    bool _is_doris_table {false};
96
    std::string _host = "127.0.0.1";
97
    int _port = 9060;
98
};
99
100
} // namespace io
101
} // namespace doris