-
Notifications
You must be signed in to change notification settings - Fork 247
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
Add persistent record storage for the DSN. #862
Conversation
- split providers and records traits
- add MemoryRecordStorage - add NoRecordStorage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some questions and nits.
Please try to rebase against main before opening PR and make sure all commits compile, pass checks and, ideally, all changes are as close to the final version as possible from the beginning.
pub async fn put_value(&self, key: Multihash, value: Vec<u8>) -> Result<bool, PutValueError> { | ||
let (result_sender, result_receiver) = oneshot::channel(); | ||
|
||
self.shared | ||
.command_sender | ||
.clone() | ||
.send(Command::PutValue { | ||
key, | ||
value, | ||
result_sender, | ||
}) | ||
.await?; | ||
|
||
Ok(result_receiver.await?) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we discussed that we'll not have puts, instead we'll do announcements and it will be up to the target of the announcement to download and cache something or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We discussed it offline: I will test L2 cache using puts and later test pull solution to match "get-closest and then send add-provider" algorithm.
error!(?err, "Can't create Parity DB record storage iterator."); | ||
|
||
ParityDbRecordIterator::empty() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why returning empty iterator instead of an error? Silencing these doesn't seem nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also don't like that it doesn't fail here. You can at least discard errors and return an option as an api.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like it either. However, libp2p interface is suboptimal here. The only alternative I see is to panic. Please, let me know whether I should panic here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add TODO about this with link to upstream issue that these should be made fallible to allow more backend implementations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
match result { | ||
Ok(data) => { | ||
if let Some(data) = data { | ||
let db_rec_result = serde_json::from_slice::<ParityDbRecord>(&data); | ||
|
||
match db_rec_result { | ||
Ok(db_rec) => { | ||
trace!(?key, "Record loaded successfully from DB"); | ||
|
||
Some(Cow::Owned(db_rec.into())) | ||
} | ||
Err(err) => { | ||
debug!(?key, ?err, "Parity DB record deserialization error"); | ||
|
||
None | ||
} | ||
} | ||
} else { | ||
trace!(?key, "No Parity DB record for given key"); | ||
|
||
None | ||
} | ||
} | ||
Err(err) => { | ||
debug!(?key, ?err, "Parity DB record storage error"); | ||
|
||
None | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can match for literally any value:
match result {
Ok(Some(data)) => {
let db_rec_result = serde_json::from_slice::<ParityDbRecord>(&data);
match db_rec_result {
Ok(db_rec) => {
trace!(?key, "Record loaded successfully from DB");
Some(Cow::Owned(db_rec.into()))
}
Err(err) => {
debug!(?key, ?err, "Parity DB record deserialization error");
None
}
}
}
Ok(None) => {
trace!(?key, "No Parity DB record for given key");
None
}
Err(err) => {
debug!(?key, ?err, "Parity DB record storage error");
None
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree. This option is better. Thanks.
let tx = vec![(self.column_id, key, data)]; | ||
|
||
let result = self.db.commit(tx); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Vector is heap allocated. You can use either of those instead:
self.db.commit(Some((self.column_id, key, data)));
self.db.commit(std::iter::once((self.column_id, key, data)));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. I will change to Option but with a separate line for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe you can also just use []
or &[]
, Option
is not natural here even though it happens to implement IntoIterator
.
error!(?err, "Can't create Parity DB record storage iterator."); | ||
|
||
ParityDbRecordIterator::empty() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also don't like that it doesn't fail here. You can at least discard errors and return an option as an api.
# Conflicts: # crates/subspace-farmer/src/single_plot_farm.rs
This PR adds a code supporting pieces cache for the DSN. It adds a persistent implementation of the Kademlia record storage.
Changes
put_value
operation for NodeComments
Code contributor checklist: