feat: support cache mode for prefetch#113
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds configurable “prefetch cache mode” support so prefetching can enable/disable read-ahead cache initialization depending on whether predicates and/or bitmap selection are used.
Changes:
- Replaces the boolean prefetch-cache switch with a new
PrefetchCacheModeenum and threads it throughReadContext/ReadContextBuilder. - Updates prefetch reader creation to accept the new cache mode and conditionally initialize the cache via
NeedInitCache(). - Updates and extends existing unit tests to use the new API and validate defaults.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
include/paimon/utils/read_ahead_cache.h |
Introduces PrefetchCacheMode enum and documents intended behavior. |
include/paimon/read_context.h |
Public API change: ReadContext now exposes cache mode; builder uses SetPrefetchCacheMode. |
src/paimon/core/operation/read_context.cpp |
Implements builder storage/defaults and passes cache mode into ReadContext. |
src/paimon/core/operation/read_context_test.cpp |
Validates default cache mode and builder-set cache mode. |
src/paimon/core/operation/internal_read_context.h |
Exposes cache mode through internal context wrapper. |
src/paimon/core/operation/abstract_split_read.cpp |
Passes cache mode to PrefetchFileBatchReaderImpl::Create. |
src/paimon/common/reader/prefetch_file_batch_reader_impl.h |
Updates create/ctor signatures and stores cache mode + predicate. |
src/paimon/common/reader/prefetch_file_batch_reader_impl.cpp |
Implements conditional cache initialization based on cache mode/predicate/bitmap. |
src/paimon/common/reader/prefetch_file_batch_reader_impl_test.cpp |
Updates tests to new create signature. |
src/paimon/core/deletionvectors/apply_deletion_vector_batch_reader_test.cpp |
Updates prefetch reader creation signature usage. |
src/paimon/common/file_index/bitmap/apply_bitmap_index_batch_reader_test.cpp |
Updates prefetch reader creation signature usage. |
Comments suppressed due to low confidence (1)
src/paimon/common/reader/prefetch_file_batch_reader_impl.cpp:303
- New cache-mode behavior is implemented via
NeedInitCache()and theif (cache_ && NeedInitCache())gate, but there are no unit tests exercising the non-ALWAYS modes (e.g. ensuring cache init is skipped when a predicate and/or bitmap is present). Adding targeted tests forEXCLUDE_PREDICATE,EXCLUDE_BITMAP, andEXCLUDE_BITMAP_OR_PREDICATEwould help prevent regressions in this new feature.
bool PrefetchFileBatchReaderImpl::NeedInitCache() const {
switch (cache_mode_) {
case PrefetchCacheMode::NEVER:
return false;
case PrefetchCacheMode::EXCLUDE_PREDICATE:
return predicate_ == nullptr;
case PrefetchCacheMode::EXCLUDE_BITMAP:
return selection_bitmap_ == std::nullopt;
case PrefetchCacheMode::EXCLUDE_BITMAP_OR_PREDICATE:
return predicate_ == nullptr && selection_bitmap_ == std::nullopt;
case PrefetchCacheMode::ALWAYS:
return true;
default:
return true;
}
}
void PrefetchFileBatchReaderImpl::Workloop() {
std::vector<std::future<void>> futures;
futures.resize(readers_.size());
if (cache_ && NeedInitCache()) {
auto read_ranges = readers_[0]->PreBufferRange();
if (read_ranges.ok()) {
std::vector<ByteRange> ranges;
for (const auto& read_range : read_ranges.value()) {
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
lxy-9602
reviewed
Feb 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
Adds configurable “prefetch cache mode” support so prefetching can enable/disable read-ahead cache initialization depending on whether predicates and/or bitmap selection are used.
Tests
API and Format
PrefetchCacheMode ReadContext::GetPrefetchCacheMode() const;
ReadContextBuilder& SetPrefetchCacheMode(PrefetchCacheMode mode);
Documentation