-
Notifications
You must be signed in to change notification settings - Fork 999
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
protocols/kad: Why run caching procedure for queries with Quorum::One only? #1577
Comments
I have some difficulties remembering but I think it really came down to the semantics just being a bit unclear. In standard Kademlia the record is cached at the nearest peer to the key that did not return the value on a successful lookup. A successful lookup in standard Kademlia is with quorum 1. If this is done for quorums > 1 as well, then the record will be cached even if, from a user's perspective, the lookup wasn't actually successful (e.g. quorum not satisfied). That said, I don't currently see any harm in doing that either, so if there was a very strong reason, I must have forgotten about it by now. |
I think I remember now. The question is: With a quorum > 1, which of the returned records do you cache? They may not be the same, and the reason someone uses a quorum > 1 to begin with is to make a choice among the obtained results, usually. That is a choice that we cannot make internally in libp2p. |
@mxinden Did my last comment answer your question and/or do you have specific suggestions for what we could do? |
Thanks for the follow up. I agree that this is problematic. I can think of two improvements (not mutually exclusive):
What do you think? Do you have alternative ideas how to make this integral part of Kademlia work for queries with quorum > 1? |
I assume that comparing
That crossed my mind as well. The difficulty there would be to come up with a practical interface. It would seem simple enough to allow configuration of a referentially transparent function, i.e. a function pointer of the kind The above considerations so far led me to believe that it may be preferable to leave these kinds of write-back after queries to client code, which in any case needs to decide (usually after decoding) which record(s) to keep for queries with quorum > 1. It is thus thinkable that we could provide a bit more metadata in a |
I just realised that you probably mean something along the lines of what I wrote in the last paragraph of my previous comment. For some reason my first reading of this comment of yours was that it suggests having a (configurable) function that decides which record to keep / cache, which I referred to in the second to last paragraph. |
As you stated above, I share the concern that this is an interface hard to get right. Additional complications might arise with people wanting to call an
I would be in favor of this approach. |
Closes libp2p#1577
e.g. for write-back caching after a successful read. In that context, peers that were queried in a successful `Kademlia::get_record` operation but did not return a record are now returned in the `GetRecordOk::no_record` list of peer IDs. Closes libp2p#1577.
e.g. for write-back caching after a successful read. In that context, peers that were queried in a successful `Kademlia::get_record` operation but did not return a record are now returned in the `GetRecordOk::no_record` list of peer IDs. Closes libp2p#1577.
e.g. for write-back caching after a successful read. In that context, peers that were queried in a successful `Kademlia::get_record` operation but did not return a record are now returned in the `GetRecordOk::no_record` list of peer IDs. Closes libp2p#1577.
* Add `Kademlia::put_record_to` for storing a record at specific nodes, e.g. for write-back caching after a successful read. In that context, peers that were queried in a successful `Kademlia::get_record` operation but did not return a record are now returned in the `GetRecordOk::no_record` list of peer IDs. Closes #1577. * Update protocols/kad/src/behaviour.rs Co-authored-by: Max Inden <[email protected]> * Refine implementation. Rather than returning the peers that are cache candidates in a `Vec` in an arbitrary order, use a `BTreeMap`. Furthermore, make the caching configurable, being enabled by default with `max_peers` of 1. By configuring it with `max_peers` > 1 it is now also possible to control at how many nodes the record is cached automatically after a lookup with quorum 1. When enabled, successful lookups will always return `cache_candidates`, which can be used explicitly with `Kademlia::put_record_to` after lookups with a quorum > 1. * Re-export KademliaCaching * Update protocols/kad/CHANGELOG.md Co-authored-by: Max Inden <[email protected]> * Clarify changelog. Co-authored-by: Max Inden <[email protected]>
* Add `Kademlia::put_record_to` for storing a record at specific nodes, e.g. for write-back caching after a successful read. In that context, peers that were queried in a successful `Kademlia::get_record` operation but did not return a record are now returned in the `GetRecordOk::no_record` list of peer IDs. Closes libp2p/rust-libp2p#1577. * Update protocols/kad/src/behaviour.rs Co-authored-by: Max Inden <[email protected]> * Refine implementation. Rather than returning the peers that are cache candidates in a `Vec` in an arbitrary order, use a `BTreeMap`. Furthermore, make the caching configurable, being enabled by default with `max_peers` of 1. By configuring it with `max_peers` > 1 it is now also possible to control at how many nodes the record is cached automatically after a lookup with quorum 1. When enabled, successful lookups will always return `cache_candidates`, which can be used explicitly with `Kademlia::put_record_to` after lookups with a quorum > 1. * Re-export KademliaCaching * Update protocols/kad/CHANGELOG.md Co-authored-by: Max Inden <[email protected]> * Clarify changelog. Co-authored-by: Max Inden <[email protected]>
When querying for a key, Kademlia remembers the closest node that did not have the key to later on store the record on that node.
Paper page 7:
This is implemented here:
rust-libp2p/protocols/kad/src/behaviour.rs
Lines 1306 to 1320 in c271f6f
Why is this procedure only triggered for queries with
Quorum::One
? Why not do this for all queries?//CC @romanb
The text was updated successfully, but these errors were encountered: