Coverage Report

Created: 2026-11-02 15:01

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/io/cache/file_range_planner.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 <cstddef>
21
#include <vector>
22
23
#include "common/status.h"
24
#include "io/fs/file_range_coalescer.h"
25
26
namespace doris::io {
27
28
struct ReadAheadStatistics;
29
30
struct FileRangePlanOptions {
31
    /// Limits for the initial range coalescing pass.
32
    FileRangeCoalesceOptions coalesce_options;
33
    /// File Cache block size used when considering boundary-block completion.
34
    size_t cache_block_size {1};
35
    /// Minimum input-byte coverage required before completing a boundary block.
36
    double block_fill_min_coverage {1.0};
37
38
    Status validate() const;
39
};
40
41
/// The location of one input range in its final read buffer.
42
struct FileRangeLocation {
43
    /// Index into FileRangePlan::ranges.
44
    size_t range_index {0};
45
    /// Offset of the original input's first byte within that physical range buffer.
46
    size_t buffer_offset {0};
47
48
42
    bool operator==(const FileRangeLocation&) const = default;
49
};
50
51
struct FileRangePlan {
52
    /// Physical ranges to read after coalescing and optional cache-block completion.
53
    std::vector<FileRange> ranges;
54
    /// One location per input in caller-supplied order; every input is contained by that range.
55
    std::vector<FileRangeLocation> input_locations;
56
57
27
    bool operator==(const FileRangePlan&) const = default;
58
};
59
60
/// Builds a read-only plan without allocating buffers or performing file IO.
61
class FileRangePlanner {
62
public:
63
    /// `input_ranges` must be sorted by offset and mutually disjoint. The planner first coalesces
64
    /// them, then completes high-coverage cache blocks when the resulting physical ranges remain
65
    /// within `max_range_bytes`. One input larger than that limit remains a standalone read. The
66
    /// physical EOF block uses its valid file bytes as the coverage denominator.
67
    static Status plan(const std::vector<FileRange>& input_ranges, size_t file_size,
68
                       const FileRangePlanOptions& options, FileRangePlan* output_plan,
69
                       ReadAheadStatistics* statistics = nullptr);
70
};
71
72
} // namespace doris::io