Skip to content

Add sync() methods to HybridCache for consistency guarantees#1090

Open
Barre wants to merge 2 commits intofoyer-rs:mainfrom
Barre:main
Open

Add sync() methods to HybridCache for consistency guarantees#1090
Barre wants to merge 2 commits intofoyer-rs:mainfrom
Barre:main

Conversation

@Barre
Copy link

@Barre Barre commented Aug 5, 2025

Add sync(), remove_sync(), insert_sync(), and insert_with_properties_sync() methods to HybridCache to ensure operations complete before returning.

This fixes race conditions where:

  • Deletions could be read after remove() due to async processing
  • Overwrites could return stale data due to async deletion of old values

The new methods provide opt-in consistency guarantees without breaking existing code that doesn't require strict ordering.

What's changed and what's your intention?

Please explain IN DETAIL what the changes are in this PR and why they are needed. :D

Checklist

  • I have written the necessary rustdoc comments
  • I have added the necessary unit tests and integration tests
  • I have passed cargo x (or cargo x --fast instead if the old tests are not modified) in my local environment.

Related issues or PRs (optional)

#1085

Barre added 2 commits August 5, 2025 12:03
Add sync(), remove_sync(), insert_sync(), and insert_with_properties_sync()
methods to HybridCache to ensure operations complete before returning.

This fixes race conditions where:
- Deletions could be read after remove() due to async processing
- Overwrites could return stale data due to async deletion of old values

The new methods provide opt-in consistency guarantees without breaking
existing code that doesn't require strict ordering.
@MrCroxx
Copy link
Member

MrCroxx commented Aug 6, 2025

Hi, @Barre . Thank you for your contribution.

I agree to expose the disk cache wait interface, but I have reservations about introducing interfaces like insert_sync()/delete_sync().

The issue here is that as a cache, foyer allows for the loss of any data. Therefore, the insert_sync() interface seems to be of little use.

The inconsistency issues you encountered with overwrite or deletion cannot be resolved solely through sync. I am working on fixing these issues. I hope to resolve this through other means rather than prematurely introducing additional interfaces that lead to complexity and confusion. For now, I can expose wait() for users with needs to call manually to address the issue.

However, it should be noted that this does not completely solve the problem, as the current design still cannot fully guarantee consistency for overwrite and deletion in order to prevent OOM and throttle the disk. Since most users of foyer use S3 as remote storage, these use cases are generally not involved, and I will gradually fix them in subsequent versions.

@codecov
Copy link

codecov bot commented Aug 6, 2025

Codecov Report

❌ Patch coverage is 0% with 25 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
foyer/src/hybrid/cache.rs 0.00% 25 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (e9f2c57) and HEAD (db9d1c8). Click for more details.

HEAD has 2 uploads less than BASE
Flag BASE (e9f2c57) HEAD (db9d1c8)
3 1
Files with missing lines Coverage Δ
foyer/src/hybrid/cache.rs 44.04% <0.00%> (-39.30%) ⬇️

... and 53 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@MrCroxx MrCroxx force-pushed the main branch 2 times, most recently from 3f7f53f to c009129 Compare September 12, 2025 05:49
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