Skip to content

[Store] Add immutable bucket allocator for DFS replicas - #4124

Merged
ykwd merged 23 commits into
kvcache-ai:mainfrom
wp-bc:bucket/immutable-bucket-allocator
Sep 22, 2026
Merged

ykwd merged 23 commits into
kvcache-ai:mainfrom
wp-bc:bucket/immutable-bucket-allocator

Conversation

@wp-bc

@wp-bc wp-bc commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Description

This PR implements the DFS immutable Bucket allocator proposed in:

It introduces a pluggable GlobalAllocatorInterface for DFS replica allocation while preserving the existing DfsGlobalAllocator as the default shard implementation.

A new ImmutableBucketAllocator can be selected with:

MOONCAKE_DFS_ALLOCATOR=bucket

The Bucket allocator stores objects as aligned, append-only immutable entries in fixed-capacity Bucket files. Buckets are created on demand and reclaimed in LRU order.

The existing DistributedFSDescriptor wire format is unchanged. In Bucket mode, the existing shard_idx field carries the Bucket ID, preserving serialization compatibility.

Main changes

Pluggable DFS allocator

  • Extract GlobalAllocatorInterface as the Master-facing DFS allocation contract.
  • Adapt DfsGlobalAllocator to implement the interface.
  • Keep shard as the default allocator with unchanged behavior.
  • Add configuration parsing and validation for shard and bucket.

Immutable Bucket allocation

  • Create fixed-capacity Bucket files on demand.

  • Store values as aligned, append-only entries:

    [value bytes][zero alignment padding]
    
  • Track entries through PENDING, COMMITTED, and TOMBSTONE states.

  • Never overwrite entries or reuse tombstoned or rolled-back ranges.

  • Assign monotonically increasing Bucket IDs.

  • Allow ordered batch allocation across multiple Buckets.

  • Roll back all reservations if any allocation in a batch fails.

  • Match complete descriptors when committing, freeing, or updating entries.

  • Seal full Buckets and create new ones up to the configured limit.

Bucket-level LRU eviction

  • Track access and reclaim complete Buckets in LRU order.
  • Exclude the active Bucket and Buckets containing pending or protected entries.
  • Lock affected metadata shards in a stable order and validate every live entry against its exact DFS descriptor.
  • Abort the entire eviction if any entry is processing, leased, pinned, or otherwise invalid.
  • Remove replicas from metadata before deleting the Bucket file. Failed file deletion keeps the Bucket charged against capacity for a later retry.
  • Trigger reclamation at configured watermarks and when allocation is exhausted.

Synchronous buffered Bucket I/O

  • Extend the filesystem adapter to open existing files without creating them.
  • Use synchronous buffered positional I/O with short-lived descriptors for Bucket requests, while retaining cached descriptors for shard files.
  • Handle interrupted and partial POSIX operations, treating zero progress, premature EOF, and incomplete transfers as errors.
  • Validate Bucket paths, IDs, descriptor alignment, object sizes, and ranges before I/O.
  • Never create a file implicitly for an invalid or missing Bucket descriptor.

Master and Client integration

  • Select the configured allocator during Master initialization and allocate DFS replicas through the common interface.
  • Keep Bucket entries pending while replicas are PROCESSING, then commit them in PutEnd before publication.
  • Tombstone reservations when writes are revoked, removed, or replaced.
  • Keep DFS writes synchronous and revoke failed writes so incomplete data is never published.
  • Attempt one validated whole-Bucket eviction when Bucket capacity is exhausted.
  • Preserve existing shard expansion and eviction behavior in shard mode.

Configuration

The following settings are introduced:

MOONCAKE_DFS_ALLOCATOR=shard | bucket
MOONCAKE_DFS_BUCKET_CAPACITY=1073741824
MOONCAKE_DFS_MAX_BUCKET_COUNT=64

The existing DFS settings continue to configure common filesystem and eviction behavior:

MOONCAKE_DFS_ROOT_DIR
MOONCAKE_DFS_FS_ADAPTER
MOONCAKE_DFS_ALIGNMENT
MOONCAKE_DFS_EVICTION_ENABLED
MOONCAKE_DFS_EVICTION_HIGH_WATERMARK
MOONCAKE_DFS_EVICTION_LOW_WATERMARK
MOONCAKE_DFS_EVICTION_CHECK_INTERVAL

MOONCAKE_DFS_BUCKET_CAPACITY must be nonzero, aligned to MOONCAKE_DFS_ALIGNMENT, and representable by the filesystem interface. MOONCAKE_DFS_MAX_BUCKET_COUNT must be positive.

Documentation

  • Document the immutable Bucket layout and lifecycle.
  • Document allocator selection and Bucket-specific environment variables.
  • Describe allocation, rollback, commit, and whole-Bucket eviction.
  • Document current operational and recovery limitations.

Compatibility

  • shard remains the default allocator with unchanged allocation, eviction, and I/O behavior.
  • DistributedFSDescriptor serialization remains unchanged, so existing clients can continue using shard descriptors without configuration changes.
  • Bucket capacity settings affect only bucket mode.
  • Shard count and capacity settings do not control Bucket allocation.

Module

  • Transfer Engine (mooncake-transfer-engine)
  • Mooncake Store (mooncake-store)
  • Mooncake Conductor (mooncake-conductor)
  • Reshard (mooncake-reshard)
  • Mooncake EP (mooncake-ep)
  • Mooncake PG (mooncake-pg)
  • Integration (mooncake-integration)
  • P2P Store (mooncake-p2p-store)
  • Python Wheel (mooncake-wheel)
  • Common (mooncake-common)
  • Mooncake RL (mooncake-rl)
  • CI/CD
  • Docs
  • Other

Type of Change

  • Bug fix
  • New feature
  • Refactor
  • Breaking change
  • Documentation update
  • Performance improvement
  • Other

How Has This Been Tested?

Validation was performed in an isolated Linux build environment using GCC 11.4 and Ninja.

Build command:

cmake -S . -B build -G Ninja \
  -DBUILD_UNIT_TESTS=ON \
  -DWITH_STORE=ON \
  -DUSE_CUDA=OFF \
  -DUSE_HIP=OFF \
  -DUSE_HYGON=OFF \
  -DUSE_3FS=OFF \
  -DUSE_TCP=ON

cmake --build build --target \
  dfs_immutable_bucket_allocator_test \
  dfs_immutable_bucket_backend_test \
  dfs_immutable_bucket_client_test \
  distributed_storage_config_test

Test results:

  • dfs_immutable_bucket_allocator_test: 8/8 passed
  • dfs_immutable_bucket_backend_test: 3/3 passed
  • dfs_immutable_bucket_client_test: 2/2 passed
  • distributed_storage_config_test: 10/10 passed
  • git diff --check main...HEAD: passed

Coverage includes:

  • Aligned append-only allocation, cross-Bucket packing, and atomic rollback
  • Entry lifecycle, stale descriptor rejection, and concurrent allocation
  • Pending-entry protection and whole-Bucket LRU eviction
  • Non-empty-root fail-closed behavior
  • Scatter/gather I/O, partial transfers, and zero-progress handling
  • Descriptor path and range validation without implicit file creation
  • Synchronous Client writes and failed-write revocation
  • Allocation-exhaustion recovery and DFS environment configuration

Documentation validation:

  • Sphinx read and rendered all 100 source pages.

  • The new design page and navigation entry were generated successfully.

  • Strict warning handling encountered one external intersphinx TLS fetch failure; no warning originated from the new documentation.

  • Unit tests pass

  • Integration tests pass (in-process POSIX integration)

  • Manual testing done (describe below)

Checklist

  • I have performed a self-review of my own code
  • I have formatted my code using ./scripts/code_format.sh
  • I have run pre-commit on the files changed in this PR and all hooks pass
  • I have updated the documentation (if applicable)
  • I have added tests to prove my changes are effective
  • For changes >500 LOC: I have filed an RFC issue

RFC: #3641

AI Assistance Disclosure

  • No AI tools were used
  • AI tools were used

@github-actions github-actions Bot added documentation Improvements or additions to documentation run-ci Store Common labels Sep 15, 2026
@wp-bc
wp-bc force-pushed the bucket/immutable-bucket-allocator branch 2 times, most recently from 65be7e6 to 585bd21 Compare September 15, 2026 08:19
@wp-bc
wp-bc marked this pull request as ready for review September 15, 2026 08:21
@wp-bc
wp-bc force-pushed the bucket/immutable-bucket-allocator branch from 585bd21 to 8ab0e9e Compare September 15, 2026 10:45
Comment thread mooncake-store/src/master_service.cpp Resolved
Comment thread mooncake-store/src/master_service.cpp Resolved
Comment thread mooncake-store/src/master_service.cpp Resolved
@wp-bc
wp-bc force-pushed the bucket/immutable-bucket-allocator branch from 8d47b33 to c688f5a Compare September 20, 2026 06:05
Comment thread mooncake-store/src/master_service.cpp Resolved
@wp-bc
wp-bc force-pushed the bucket/immutable-bucket-allocator branch from e2a639c to 9c98e60 Compare September 20, 2026 08:56
Comment thread mooncake-store/src/master_service.cpp Resolved
@wp-bc
wp-bc force-pushed the bucket/immutable-bucket-allocator branch from 21a4ef5 to 9980663 Compare September 22, 2026 03:40

@fcczzz fcczzz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM.

@ykwd
ykwd merged commit dbd46e6 into kvcache-ai:main Sep 22, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Common documentation Improvements or additions to documentation run-ci Store

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants