Coverage Report

Created: 2026-10-15 12:47

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/io/fs/file_range_coalescer.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
25
namespace doris::io {
26
27
/// A half-open byte range [offset, offset + size) in one file.
28
struct FileRange {
29
    size_t offset {0};
30
    size_t size {0};
31
32
1.51k
    size_t end() const { return offset + size; }
33
34
418
    bool operator==(const FileRange&) const = default;
35
};
36
37
/// Limits applied while adjacent input ranges are grouped into one physical read.
38
struct FileRangeCoalesceOptions {
39
    /// Maximum unread gap that may be included between two input ranges.
40
    size_t max_gap_bytes {0};
41
    /// Maximum size of a combined range. One indivisible input may exceed this limit.
42
    size_t max_range_bytes {1};
43
    /// Maximum combined-range bytes divided by bytes covered by its input ranges.
44
    double max_read_amplification_ratio {1.0};
45
46
    /// Validate the option values independently of any input ranges.
47
    Status validate() const;
48
};
49
50
/// Groups sorted file ranges without performing file IO.
51
class FileRangeCoalescer {
52
public:
53
    /// `options` must have passed validation. Each input range must be non-empty. Input ranges
54
    /// must be sorted by offset and mutually disjoint. Callers establish these invariants before
55
    /// entering the hot path.
56
    /// `max_range_bytes` limits combining multiple inputs; one indivisible input may be larger and
57
    /// is returned unchanged.
58
    static std::vector<FileRange> coalesce(const std::vector<FileRange>& input_ranges,
59
                                           const FileRangeCoalesceOptions& options);
60
};
61
62
} // namespace doris::io