feat: add IO cache (LRUCache, CacheManager, CacheInputStream) and MemorySlice utilities by lxy-9602 · Pull Request #40 · apache/paimon-cpp · GitHub
Skip to content

feat: add IO cache (LRUCache, CacheManager, CacheInputStream) and MemorySlice utilities - #40

Merged
leaves12138 merged 1 commit into
apache:mainfrom
lxy-9602:add-mem-cache
Jun 2, 2026
Merged

feat: add IO cache (LRUCache, CacheManager, CacheInputStream) and MemorySlice utilities#40
leaves12138 merged 1 commit into
apache:mainfrom
lxy-9602:add-mem-cache

Conversation

@lxy-9602

@lxy-9602 lxy-9602 commented Jun 2, 2026

Copy link
Copy Markdown
Member

Purpose

No Linked issue.

Introduce IO caching infrastructure and memory slice utilities:

IO Cache (src/paimon/common/io/):

  • Cache — abstract cache interface (cache/cache.h)
  • CacheKey — cache key with file path and offset identity (cache/cache_key.h/cpp)
  • LRUCache — least-recently-used cache implementation (cache/lru_cache.h/cpp)
  • CacheManager — manages cache lifecycle and eviction (cache/cache_manager.h/cpp)
  • CacheInputStream — input stream backed by the page cache (cache_input_stream.h)

Memory Slice (src/paimon/common/memory/):

  • MemorySlice — a view over a contiguous memory region (memory_slice.h/cpp)
  • MemorySliceInput — sequential reader over a MemorySlice (memory_slice_input.h)
  • MemorySliceOutput — growable writer producing a MemorySlice (memory_slice_output.h/cpp)

Tests

  • cache_input_stream_test.cpp — cached read behavior and cache hits/misses
  • lru_cache_test.cpp — LRU eviction order and capacity limits
  • memory_slice_test.cpp — slice construction, subslicing, comparison

API and Format

Documentation

Generative AI tooling

Migrate-by: Aone Copilot (Claude)

@leaves12138 leaves12138 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.

Thanks for the migration. I found one blocker in MemorySliceOutput growth: EnsureSize treats the already-required total size as an increment, which causes excessive growth and can hang forever for a zero-sized initial buffer.

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.

size is already the required total capacity passed by callers (size_ + bytes_to_write). Adding the current segment size again makes growth much larger than needed; for example, appending one byte to a full power-of-two buffer grows from N to 4N. More importantly, if MemorySliceOutput(0, pool) is used, capacity remains 0 and capacity <<= 1 loops forever. Please use min_capacity = size and handle capacity == 0 explicitly (or reject/normalize zero initial capacity), and add coverage for the zero-capacity case.

@leaves12138 leaves12138 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.

I re-checked MemorySliceOutput against Java Paimon's MemorySliceOutput.ensureSize(). The C++ implementation intentionally follows the same growth policy, and current callers initialize it with a non-zero capacity. I did another pass over the cache and memory slice code and did not find remaining blockers.

@leaves12138
leaves12138 merged commit 8cb8c61 into apache:main Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants