Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENH] Add log cache #2021

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

Ishiihara
Copy link
Contributor

@Ishiihara Ishiihara commented Apr 16, 2024

Description of changes

Summarize the changes made by this PR.

  • Improvements & Bug fixes
    • ...
  • New functionality
    • This PR adds a cache for the log to reduce the latency of the brute force operator.
    • It utilizes foyer (https://github.com/MrCroxx/foyer) as the cache library. Foyer provides in memory as well as hybrid cache which allows us to apply it as block cache.
    • The key for the cache entry is collection_id + start_offset, and the value is Arc<[LogRecord]>. To call out, the cache is not yet aligned on a batch boundary. We may want to make the cache key align on the batch boundary to reduce unnecessary caching.
    • Cache invalidation is not yet implemented and will be added as a follow up PR based on collection version and log position for the latest compaction.

Test plan

How are these changes tested?

  • Tests pass locally with pytest for python, yarn test for js, cargo test for rust

Documentation Changes

Are all docstrings for user-facing APIs updated if required? Do we need to make documentation changes in the docs repository?

Copy link

Reviewer Checklist

Please leverage this checklist to ensure your code review is thorough before approving

Testing, Bugs, Errors, Logs, Documentation

  • Can you think of any use case in which the code does not behave as intended? Have they been tested?
  • Can you think of any inputs or external events that could break the code? Is user input validated and safe? Have they been tested?
  • If appropriate, are there adequate property based tests?
  • If appropriate, are there adequate unit tests?
  • Should any logging, debugging, tracing information be added or removed?
  • Are error messages user-friendly?
  • Have all documentation changes needed been made?
  • Have all non-obvious changes been commented?

System Compatibility

  • Are there any potential impacts on other parts of the system or backward compatibility?
  • Does this change intersect with any items on our roadmap, and if so, is there a plan for fitting them together?

Quality

  • Is this code of a unexpectedly high quality (Readability, Modularity, Intuitiveness)

@Ishiihara Ishiihara force-pushed the bf_knn_cache branch 2 times, most recently from 04ddca0 to 54c5844 Compare April 17, 2024 22:33
@Ishiihara Ishiihara self-assigned this Apr 17, 2024
@Ishiihara Ishiihara force-pushed the bf_knn_cache branch 7 times, most recently from 8fab2b1 to 49712f9 Compare April 25, 2024 05:17
@Ishiihara Ishiihara marked this pull request as ready for review April 25, 2024 17:21
@Ishiihara
Copy link
Contributor Author

@MrCroxx Thank you for making Foyer compatible with Rust stable. This PR uses Foyer's memory cache to cache the log records reading from databases in batches. It would be great to have you take a look and offer some insights on the PR.

@MrCroxx
Copy link

MrCroxx commented Apr 27, 2024

Hi, @Ishiihara . Thanks to invite me to review this PR. I'll finish it in 2-3 days.

I noticed you introduced both foyer and foyer-memory. IMO, with the latest version (0.8.6), foyer is enouth for most usecases. Is there something that cannot be achieved? Please tell me and I'll export it if necessary.

Copy link

@MrCroxx MrCroxx left a comment

Choose a reason for hiding this comment

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

Hi @Ishiihara , thanks again for trying foyer, I'll refactor it based on your needs ASAP. Wish you have a good experience with it,

@@ -0,0 +1,13 @@
use serde::Deserialize;

#[derive(Deserialize)]
Copy link

Choose a reason for hiding this comment

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

Let me support serde for EvictionConfig in foyer, then you can omit it.

}

pub(crate) struct LogCache {
cache: Cache<LogCacheKey, Arc<[LogRecord]>, LogCacheEventListener>,
Copy link

Choose a reason for hiding this comment

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

Please use foyer::Cache is only in-memory is needed, otherwise, use foyer::HybridCache instead.

In short, only foyer needs to be imported.

cache: Cache<LogCacheKey, Arc<[LogRecord]>, LogCacheEventListener>,
}

impl Debug for LogCache {
Copy link

Choose a reason for hiding this comment

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

I'll impl Debug for Cache and HybridCache, then you can use derive.

}
}

pub(crate) struct EntryDataHandle {
Copy link

Choose a reason for hiding this comment

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

Remove it if you only read from foyer?

@MrCroxx
Copy link

MrCroxx commented Apr 28, 2024

Hi @Ishiihara , you can run cargo update -p foyer-memory -p foyer-storage -p foyer to upgrade foyer and resolve the comments.

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.

None yet

2 participants