-
-
Notifications
You must be signed in to change notification settings - Fork 73
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
Iterating all entries in a cache #93
Comments
In order to do this locklessly, it's worth noting that either all keys will be sampled once but values may change, or that the iterator may or may not miss keys that were added during iteration. |
I am adding iterator to newly added Here is the pull request: At this moment, I think this will be good enough. If somebody wants iterator, they could consider using I will revisit iterator for other concurrent caches such as I will post some thoughts in next comment. |
This is my current thoughts on iterators for concurrent lock-free caches.
Yeah. It will be very hard to guarantee not to miss keys that were added during iteration. There may be a way. Moka records operation logs for writes (upserts and deletes) in a channel. These logs are used for batch-updating cache policy’s data structures (doc). Iterators could subscribe the operation logs for newly added keys. For example, it will firstly iterate thorough a snapshot of keys, and then iterate thorough newly added keys retrieved from the operation logs. It will repeat until catching up to the operation logs. However, there is short delay until those operation logs can be read from the channel. So even though iterator will do the above, it can miss last few new keys. Another idea is to relax the guarantee; making iterator to allow missing some new keys, but do its best to minimize the amount of missed keys. I think DashMap is taking this approach by making iterator to acquire a read lock on the shard of the map that it is currently iterating. The read lock ensures the shard to block updates, so iterator can guarantee that no new keys are missed within the shard. Iterator visits every shards in the map, one by one, and never go back to the shards it has already visited. So it will miss new keys that has been added to a shard that the iterator has already visited. These lock-free Moka caches could take a similar approach to DashMap. Moka's I do not know which way will be better yet. |
Hi @Milo123459 — I am going to review and merge #101 to add iterator to Add the following to the [dependencies]
moka = { git = "https://github.com/moka-rs/moka", branch = "master", features = ["dash"] } Then generate the Rust doc using the following command:
Open I would strongly recommend to try it now (before I publish the new version v0.8.0 to crates.io) to ensure it has everything you need. Once published, it will become harder to change APIs although I will state in the doc that I still have some other works to do for v0.8.0 release, so I will not be able to publish it until next weekend (March 27th). |
Just FYI. I added iterators to all other caches via #114 because somebody else asked for it (#112). I released Moka v0.8.2 with them. For the concurrent caches, I took the simplest design that I could came up with. The iterators do not guarantee to return new keys if they were inserted after the iterator was created. (It may or may not return them) |
Split from #92. There are some needs for iterating all entries (
(&K, &V)
) in a cache.The text was updated successfully, but these errors were encountered: