Skip to content

feat(io): implement CacheIO read-cache layer for disk IO#2419

Open
LHT129 wants to merge 1 commit into
antgroup:mainfrom
LHT129:feature/opencode-cacheio-read-cache
Open

feat(io): implement CacheIO read-cache layer for disk IO#2419
LHT129 wants to merge 1 commit into
antgroup:mainfrom
LHT129:feature/opencode-cacheio-read-cache

Conversation

@LHT129

@LHT129 LHT129 commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Summary

Add CacheIO template class that provides a page-based read cache in front of any disk-backed IO implementation. All reads go through the cache; writes passthrough directly to the inner IO with no cache involvement.

Closes #2420

Design

  • Architecture: CacheIO : BasicIO<CacheIO> - follows existing CRTP IO pattern
  • Page-based caching: configurable page size (default 128KB)
  • Total cache size: configurable with default 256MB
  • Eviction: pluggable EvictionStrategy interface, LRU as first implementation
  • Read path: all reads go through cache; miss loads page from InnerIO
  • Write path: direct passthrough to InnerIO, no cache invalidation needed
  • DirectRead: single-page hit returns internal cache pointer (need_release=false); cross-page copies to new buffer (need_release=true)
  • Thread safety: mutex-protected cache with LRU eviction

Components

  • src/io/cache_io/eviction_strategy.h - EvictionStrategy interface + LRUEviction implementation
  • src/io/cache_io/cache_io_parameter.h/.cpp - CacheIOParameter (page_size, total_cache_size, eviction_strategy)
  • src/io/cache_io/cache_io.h - CacheIO template class
  • src/io/cache_io/cache_io_test.cpp - Unit tests (basic R/W, eviction, direct read, multi-read, parameters)

Testing

  • 6 test cases, 6322 assertions, all passing
  • No regression in existing IO tests (BufferIO, NonContinuousIO, etc.)

@LHT129 LHT129 requested a review from wxyucs as a code owner July 6, 2026 07:40
Copilot AI review requested due to automatic review settings July 6, 2026 07:40
@LHT129 LHT129 requested a review from inabao as a code owner July 6, 2026 07:40
@LHT129 LHT129 added the kind/improvement Optimizations, UX polish, or minor improvements 性能优化、体验打磨或细节改良 label Jul 6, 2026
@LHT129 LHT129 requested a review from jiaweizone as a code owner July 6, 2026 07:40
@LHT129 LHT129 added version/0.18 kind/improvement Optimizations, UX polish, or minor improvements 性能优化、体验打磨或细节改良 labels Jul 6, 2026
@vsag-bot

vsag-bot commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

/label S-waiting-on-review
/waiting-on reviewer
/request-review @jiaweizone
/request-review @wxyucs
/request-review @inabao

@mergify

mergify Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🟢 All 3 merge protections satisfied — ready to merge.

Show 3 satisfied protections

🟢 Require kind label

  • label~=^kind/

🟢 Require version label

  • label~=^version/

🟢 Require linked issue for feature/bug PRs

  • body~=(?im)(?:^|[\s\-\*])(?:close[sd]?|fix(?:e[sd])?|resolve[sd]?)\s*:?\s+(?:#\d+|[\w.\-]+/[\w.\-]+#\d+|https?://github\.com/[\w.\-]+/[\w.\-]+/issues/\d+)

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces CacheIO, a page-based read-cache IO layer wrapping an underlying disk-backed IO implementation, along with its configuration parameters, an LRU eviction strategy, and unit tests. The review feedback highlights several critical issues that must be addressed: potential Use-After-Free (UAF) vulnerabilities in ReadImpl and DirectReadImpl due to race conditions and lack of page pinning, uninitialized and un-updated this->size_ values that will cause read operations to fail, a potential division-by-zero crash if page_size is configured as zero, and a redundant if-else block during eviction strategy initialization.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/io/cache_io/cache_io.h Outdated
Comment thread src/io/cache_io/cache_io.h Outdated
Comment thread src/io/cache_io/cache_io.h
Comment thread src/io/cache_io/cache_io.h
Comment thread src/io/cache_io/cache_io_parameter.cpp
Comment thread src/io/cache_io/cache_io.h Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a new CacheIO<InnerIO> CRTP IO wrapper that adds a page-based in-memory read cache in front of an underlying IO implementation, plus JSON-parseable parameters and unit tests.

Changes:

  • Added CacheIO<InnerIO> template with page caching, LRU eviction, and DirectRead/MultiRead support.
  • Added CacheIOParameter (JSON serialization/parsing) and EvictionStrategy/LRUEviction.
  • Wired cache_io into IO parameter parsing and header aggregation; added unit tests.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
src/io/io_headers.h Exposes cache_io.h through the IO header umbrella.
src/io/common/io_parameter.cpp Adds JSON parsing support for type=cache_io parameters.
src/io/CMakeLists.txt Builds cache_io_parameter.cpp as part of the IO object library.
src/io/cache_io/eviction_strategy.h Introduces eviction strategy interface and LRU implementation.
src/io/cache_io/cache_io.h Implements the CacheIO read-cache IO wrapper.
src/io/cache_io/cache_io_test.cpp Adds unit tests for caching, eviction, direct read, multiread, and parameters.
src/io/cache_io/cache_io_parameter.h Declares CacheIOParameter (page size, total cache size, eviction strategy).
src/io/cache_io/cache_io_parameter.cpp Implements JSON (de)serialization for CacheIOParameter.
src/inner_string_params.h Registers the cache_io IO type string.

Comment thread src/io/cache_io/cache_io.h Outdated
Comment thread src/io/cache_io/cache_io.h Outdated
Comment thread src/io/cache_io/cache_io.h
Comment thread src/io/cache_io/cache_io.h
Comment thread src/io/cache_io/cache_io.h Outdated
Comment thread src/io/cache_io/cache_io_parameter.cpp
Comment thread src/io/common/io_parameter.cpp
Comment thread src/io/cache_io/cache_io.h Outdated
@LHT129 LHT129 added kind/feature Brand-new functionality or capabilities 引入全新的功能、新特性或新能力 and removed kind/improvement Optimizations, UX polish, or minor improvements 性能优化、体验打磨或细节改良 labels Jul 6, 2026
@LHT129 LHT129 force-pushed the feature/opencode-cacheio-read-cache branch from ec12104 to d4e7d6b Compare July 6, 2026 08:33
Copilot AI review requested due to automatic review settings July 6, 2026 08:33
@LHT129 LHT129 force-pushed the feature/opencode-cacheio-read-cache branch from d4e7d6b to 0b45a24 Compare July 6, 2026 08:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.

Comment thread src/io/cache_io/cache_io.h
Comment thread src/io/cache_io/cache_io.h Outdated
Comment thread src/io/cache_io/cache_io.h
Comment thread src/io/cache_io/cache_io.h
Comment thread src/io/cache_io/cache_io.h Outdated
Comment thread src/io/cache_io/cache_io.h Outdated
@LHT129 LHT129 force-pushed the feature/opencode-cacheio-read-cache branch from 0b45a24 to 0c604cd Compare July 6, 2026 09:36
Copilot AI review requested due to automatic review settings July 6, 2026 11:32
@LHT129 LHT129 force-pushed the feature/opencode-cacheio-read-cache branch from 0c604cd to 33f1b3a Compare July 6, 2026 11:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.

Comment thread src/io/cache_io/cache_io_parameter.cpp
Comment thread src/io/cache_io/cache_io.h
Comment thread src/io/cache_io/cache_io.h

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.

Comment thread src/io/cache_io/eviction_strategy.h Outdated
Comment thread src/io/cache_io/cache_io.h
Comment thread src/io/cache_io/cache_io.h
Comment thread src/io/cache_io/cache_io.h
@LHT129 LHT129 force-pushed the feature/opencode-cacheio-read-cache branch 2 times, most recently from 242da06 to 224fcb5 Compare July 7, 2026 02:26
Copilot AI review requested due to automatic review settings July 7, 2026 02:29
@LHT129 LHT129 force-pushed the feature/opencode-cacheio-read-cache branch from 224fcb5 to 07cef6d Compare July 7, 2026 02:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 8 comments.

Comment thread src/io/cache_io/cache_io.h Outdated
Comment thread src/io/cache_io/cache_io.h Outdated
Comment thread src/io/cache_io/cache_io.h
Comment thread src/io/cache_io/cache_io.h
Comment thread src/io/cache_io/page_cache.cpp Outdated
Comment thread src/io/cache_io/cache_io_parameter.cpp
Comment thread src/io/cache_io/cache_io_parameter.cpp
Comment thread src/io/cache_io/cache_io.h
@LHT129 LHT129 force-pushed the feature/opencode-cacheio-read-cache branch from 07cef6d to 242b2a8 Compare July 7, 2026 03:08
Copilot AI review requested due to automatic review settings July 7, 2026 03:08
@LHT129 LHT129 force-pushed the feature/opencode-cacheio-read-cache branch from 242b2a8 to c165f40 Compare July 7, 2026 03:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.

Comment thread src/io/cache_io/page.h
Comment thread src/io/cache_io/page_cache.cpp
Comment thread src/io/cache_io/cache_io_parameter.cpp
Comment thread src/io/cache_io/cache_io.h
@LHT129 LHT129 force-pushed the feature/opencode-cacheio-read-cache branch from c165f40 to e2cb7d3 Compare July 7, 2026 03:31
Copilot AI review requested due to automatic review settings July 7, 2026 06:28
@LHT129 LHT129 force-pushed the feature/opencode-cacheio-read-cache branch 2 times, most recently from fe96221 to 901c7aa Compare July 7, 2026 06:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 6 comments.

Comment thread src/io/cache_io/cache_io.h
Comment thread src/io/cache_io/cache_io.h
Comment thread src/io/cache_io/cache_io.h
Comment thread src/io/cache_io/cache_io.h
Comment thread src/io/cache_io/page_cache.cpp
Comment thread src/io/cache_io/cache_io_test.cpp
Copilot AI review requested due to automatic review settings July 7, 2026 06:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 10 comments.

Comment thread src/io/cache_io/cache_io.h
Comment thread src/io/cache_io/page.h
Comment thread src/io/cache_io/page.h
Comment thread src/io/cache_io/cache_io.h
Comment thread src/io/cache_io/cache_io.h
Comment thread src/io/cache_io/cache_io.h
Comment thread src/io/cache_io/cache_io_test.cpp
Comment thread src/io/cache_io/cache_io_test.cpp
Comment thread src/io/cache_io/cache_io_parameter.cpp Outdated
Comment thread src/io/cache_io/cache_io_parameter.cpp
Copilot AI review requested due to automatic review settings July 8, 2026 02:55
@LHT129 LHT129 force-pushed the feature/opencode-cacheio-read-cache branch from 901c7aa to d079368 Compare July 8, 2026 02:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 6 comments.

Comment thread src/io/cache_io/page.h
Comment thread src/io/cache_io/cache_io.h Outdated
Comment thread src/io/cache_io/cache_io.h Outdated
Comment thread src/io/cache_io/cache_io_parameter.cpp
Comment thread src/io/cache_io/cache_io.h
Comment thread src/io/cache_io/cache_io.h
Signed-off-by: LHT129 <tianlan.lht@antgroup.com>
Copilot AI review requested due to automatic review settings July 8, 2026 03:06
@LHT129 LHT129 force-pushed the feature/opencode-cacheio-read-cache branch from d079368 to 03bb0cc Compare July 8, 2026 03:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 8 comments.

Comment thread src/io/cache_io/page.h
Comment thread src/io/cache_io/cache_io.h
Comment thread src/io/cache_io/cache_io.h
Comment thread src/io/cache_io/cache_io.h
Comment thread src/io/cache_io/cache_io.h
Comment thread src/io/cache_io/cache_io_parameter.cpp
Comment thread src/io/common/io_parameter.cpp
Comment thread src/io/cache_io/cache_io.h
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/feature Brand-new functionality or capabilities 引入全新的功能、新特性或新能力 size/XL version/1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add CacheIO read-cache layer for disk IO

3 participants