Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
7654cf7
[feature](be) Add linear file range coalescing
bobhan1 Aug 28, 2026
90cf5b6
[feature](be) Add cache-aware file range planning
bobhan1 Aug 28, 2026
85894d0
[feature](be) Add file range read scheduler
bobhan1 Aug 28, 2026
c64e719
[feature](be) Reuse remote-only reads for no-write ranges
bobhan1 Aug 28, 2026
563b5ba
[feature](be) Add query read-ahead runtime ownership
bobhan1 Aug 28, 2026
e2a4012
[improvement](be) Add opt-in file range IO tracing
bobhan1 Sep 22, 2026
8a08ae1
[fix](be) Scope filesystem error-code imports to their functions
bobhan1 Oct 15, 2026
4271da9
[feature](be) Add page-driven column read-ahead windows
bobhan1 Aug 28, 2026
e7dbfa1
[feature](be) Add segment range read-ahead coordination
bobhan1 Oct 29, 2026
00fa56b
[feature](be) Connect scalar column readers to range read-ahead
bobhan1 Sep 2, 2026
8190e0f
[feature](be) Initialize scan read-ahead once after pruning
bobhan1 Oct 29, 2026
d03f274
[feature](be) Add complete-block cache write handoff and admission
bobhan1 Aug 28, 2026
a547700
[feature](be) Split consumed ranges for cache writeback
bobhan1 Aug 28, 2026
7cfe76c
[feature](be) Add cache block hole-fill planning
bobhan1 Aug 28, 2026
a7e3899
[feature](be) Add background partial block writeback
bobhan1 Aug 28, 2026
999f5c6
[feature](be) Initialize background hole fill
bobhan1 Aug 28, 2026
6fd7bb6
[feature](be) Route consumed ranges to cache writeback
bobhan1 Aug 28, 2026
1ae1272
[feature](be) Connect read-ahead range writeback
bobhan1 Aug 28, 2026
fd6df2c
[feature](be) Extend range read-ahead to point queries
bobhan1 Sep 2, 2026
a881473
[fix](be) Validate S3 upload buffer alignment on config updates
bobhan1 Oct 29, 2026
b237ebc
[fix](be) Handle irregular cache blocks in writeback coverage checks
bobhan1 Oct 29, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[feature](be) Add linear file range coalescing
### What problem does this PR solve?

Issue Number: None

Related PR: #67292

Problem Summary: Read-ahead and background hole filling both need to combine sparse logical ranges into bounded physical reads. Add a pure one-pass coalescer whose contract requires validated options and sorted, disjoint, non-empty inputs. Each merge checks the maximum gap, resulting span, and cumulative read amplification. The range-size limit controls merging; an indivisible input larger than the limit remains one read.

### Release note

None

### Check List (For Author)

- Test: Unit Test
    - ./run-be-ut.sh -j100 --run '--filter=FileRangeCoalescerTest.*'
- Behavior changed: No; this commit adds an internal planning primitive.
- Does this need documentation: No
  • Loading branch information
bobhan1 committed Oct 29, 2026
commit 7654cf77cd12031c793ff7ae03acf7dc343dcaa2
80 changes: 80 additions & 0 deletions be/src/io/fs/file_range_coalescer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

#include "io/fs/file_range_coalescer.h"

#include <cmath>
#include <limits>

#include "common/logging.h"

namespace doris::io {

Status FileRangeCoalesceOptions::validate() const {
if (max_range_bytes == 0) {
return Status::InvalidArgument("file range coalescing max range bytes must be positive");
}
if (!std::isfinite(max_read_amplification_ratio) || max_read_amplification_ratio < 1.0) {
return Status::InvalidArgument(
"file range coalescing read amplification ratio must be finite and at least 1");
}
return Status::OK();
}

namespace {

bool within_read_amplification(size_t range_bytes, size_t input_bytes,
double max_read_amplification_ratio) {
return static_cast<long double>(range_bytes) <=
static_cast<long double>(input_bytes) * max_read_amplification_ratio;
}

} // namespace

std::vector<FileRange> FileRangeCoalescer::coalesce(const std::vector<FileRange>& input_ranges,
const FileRangeCoalesceOptions& options) {
std::vector<FileRange> result;
result.reserve(input_ranges.size());
size_t current_input_bytes = 0;
for (const auto& range : input_ranges) {
DCHECK(range.size > 0);
DCHECK(range.offset <= std::numeric_limits<size_t>::max() - range.size);
if (result.empty()) {
result.push_back(range);
current_input_bytes = range.size;
continue;
}

auto& current = result.back();
DCHECK(current.end() <= range.offset);
const size_t gap_bytes = range.offset - current.end();
const size_t merged_bytes = range.end() - current.offset;
const size_t merged_input_bytes = current_input_bytes + range.size;
if (gap_bytes <= options.max_gap_bytes && merged_bytes <= options.max_range_bytes &&
within_read_amplification(merged_bytes, merged_input_bytes,
options.max_read_amplification_ratio)) {
current.size = merged_bytes;
current_input_bytes = merged_input_bytes;
} else {
result.push_back(range);
current_input_bytes = range.size;
}
}
return result;
}

} // namespace doris::io
62 changes: 62 additions & 0 deletions be/src/io/fs/file_range_coalescer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

#pragma once

#include <cstddef>
#include <vector>

#include "common/status.h"

namespace doris::io {

/// A half-open byte range [offset, offset + size) in one file.
struct FileRange {
size_t offset {0};
size_t size {0};

size_t end() const { return offset + size; }

bool operator==(const FileRange&) const = default;
};

/// Limits applied while adjacent input ranges are grouped into one physical read.
struct FileRangeCoalesceOptions {
/// Maximum unread gap that may be included between two input ranges.
size_t max_gap_bytes {0};
/// Maximum size of a combined range. One indivisible input may exceed this limit.
size_t max_range_bytes {1};
/// Maximum combined-range bytes divided by bytes covered by its input ranges.
double max_read_amplification_ratio {1.0};

/// Validate the option values independently of any input ranges.
Status validate() const;
};

/// Groups sorted file ranges without performing file IO.
class FileRangeCoalescer {
public:
/// `options` must have passed validation. Each input range must be non-empty. Input ranges
/// must be sorted by offset and mutually disjoint. Callers establish these invariants before
/// entering the hot path.
/// `max_range_bytes` limits combining multiple inputs; one indivisible input may be larger and
/// is returned unchanged.
static std::vector<FileRange> coalesce(const std::vector<FileRange>& input_ranges,
const FileRangeCoalesceOptions& options);
};

} // namespace doris::io
95 changes: 95 additions & 0 deletions be/test/io/fs/file_range_coalescer_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

#include "io/fs/file_range_coalescer.h"

#include <gtest/gtest.h>

#include <vector>

namespace doris::io {
namespace {

FileRangeCoalesceOptions options(size_t max_gap_bytes, size_t max_range_bytes,
double max_read_amplification_ratio) {
return {.max_gap_bytes = max_gap_bytes,
.max_range_bytes = max_range_bytes,
.max_read_amplification_ratio = max_read_amplification_ratio};
}

FileRange file_range(size_t offset, size_t size) {
return {.offset = offset, .size = size};
}

std::vector<FileRange> coalesce(const std::vector<FileRange>& ranges,
const FileRangeCoalesceOptions& coalesce_options) {
EXPECT_TRUE(coalesce_options.validate().ok());
return FileRangeCoalescer::coalesce(ranges, coalesce_options);
}

TEST(FileRangeCoalescerTest, EmptyInputProducesEmptyOutput) {
EXPECT_TRUE(coalesce({}, options(0, 1, 1.0)).empty());
}

TEST(FileRangeCoalescerTest, AcceptsAllThreeLimitsAtTheirBoundary) {
const std::vector<FileRange> ranges {file_range(0, 32), file_range(96, 32)};
const auto result = coalesce(ranges, options(64, 128, 2.0));

ASSERT_EQ(result.size(), 1);
EXPECT_EQ(result.front(), file_range(0, 128));
}

TEST(FileRangeCoalescerTest, SplitsWhenGapExceedsLimit) {
const std::vector<FileRange> ranges {file_range(0, 32), file_range(97, 32)};
const auto result = coalesce(ranges, options(64, 1024, 4.0));

EXPECT_EQ(result, (std::vector<FileRange> {file_range(0, 32), file_range(97, 32)}));
}

TEST(FileRangeCoalescerTest, SplitsWhenRangeSpanExceedsLimit) {
const std::vector<FileRange> ranges {file_range(0, 80), file_range(100, 80)};
const auto result = coalesce(ranges, options(32, 160, 2.0));

EXPECT_EQ(result, (std::vector<FileRange> {file_range(0, 80), file_range(100, 80)}));
}

TEST(FileRangeCoalescerTest, AppliesReadAmplificationToTheWholeCandidateRange) {
const std::vector<FileRange> ranges {file_range(0, 100), file_range(150, 100),
file_range(300, 100)};
const auto result = coalesce(ranges, options(50, 1024, 1.3));

EXPECT_EQ(result, (std::vector<FileRange> {file_range(0, 250), file_range(300, 100)}));
}

TEST(FileRangeCoalescerTest, KeepsContiguousInputSplittableAtAtomicBoundaries) {
const std::vector<FileRange> ranges {file_range(0, 80), file_range(80, 80),
file_range(160, 80)};
const auto result = coalesce(ranges, options(0, 160, 1.0));

EXPECT_EQ(result, (std::vector<FileRange> {file_range(0, 160), file_range(160, 80)}));
}

TEST(FileRangeCoalescerTest, KeepsInputLargerThanMaxRangeAsOneRead) {
const std::vector<FileRange> ranges {file_range(0, 192), file_range(192, 32),
file_range(256, 32)};
const auto result = coalesce(ranges, options(64, 128, 2.0));

EXPECT_EQ(result, (std::vector<FileRange> {file_range(0, 192), file_range(192, 96)}));
}

} // namespace
} // namespace doris::io