-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Avoid collecting all RecordStore records into a Vec in the behaviour #3021
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,6 @@ use thiserror::Error; | |
|
||
use super::*; | ||
use crate::K_VALUE; | ||
use std::borrow::Cow; | ||
|
||
/// The result of an operation on a `RecordStore`. | ||
pub type Result<T> = std::result::Result<T, Error>; | ||
|
@@ -46,6 +45,9 @@ pub enum Error { | |
ValueTooLarge, | ||
} | ||
|
||
pub type RecordsIter = Box<dyn Iterator<Item = Record> + Send + Sync + 'static>; | ||
pub type ProviderRecordsIter = Box<dyn Iterator<Item = ProviderRecord> + Send + Sync + 'static>; | ||
|
||
/// Trait for types implementing a record store. | ||
/// | ||
/// There are two types of records managed by a `RecordStore`: | ||
|
@@ -64,36 +66,33 @@ pub enum Error { | |
/// content. Just like a regular record, a provider record is distributed | ||
/// to the closest nodes to the key. | ||
/// | ||
pub trait RecordStore<'a> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't |
||
type RecordsIter: Iterator<Item = Cow<'a, Record>>; | ||
type ProvidedIter: Iterator<Item = Cow<'a, ProviderRecord>>; | ||
|
||
pub trait RecordStore { | ||
/// Gets a record from the store, given its key. | ||
fn get(&'a self, k: &Key) -> Option<Cow<'_, Record>>; | ||
fn get(&self, k: &Key) -> Option<Record>; | ||
|
||
/// Puts a record into the store. | ||
fn put(&'a mut self, r: Record) -> Result<()>; | ||
fn put(&mut self, r: Record) -> Result<()>; | ||
|
||
/// Removes the record with the given key from the store. | ||
fn remove(&'a mut self, k: &Key); | ||
fn remove(&mut self, k: &Key); | ||
|
||
/// Gets an iterator over all (value-) records currently stored. | ||
fn records(&'a self) -> Self::RecordsIter; | ||
fn records(&self) -> RecordsIter; | ||
|
||
/// Adds a provider record to the store. | ||
/// | ||
/// A record store only needs to store a number of provider records | ||
/// for a key corresponding to the replication factor and should | ||
/// store those records whose providers are closest to the key. | ||
fn add_provider(&'a mut self, record: ProviderRecord) -> Result<()>; | ||
fn add_provider(&mut self, record: ProviderRecord) -> Result<()>; | ||
|
||
/// Gets a copy of the stored provider records for the given key. | ||
fn providers(&'a self, key: &Key) -> Vec<ProviderRecord>; | ||
fn providers(&self, key: &Key) -> Vec<ProviderRecord>; | ||
|
||
/// Gets an iterator over all stored provider records for which the | ||
/// node owning the store is itself the provider. | ||
fn provided(&'a self) -> Self::ProvidedIter; | ||
fn provided(&self) -> ProviderRecordsIter; | ||
|
||
/// Removes a provider record from the store. | ||
fn remove_provider(&'a mut self, k: &Key, p: &PeerId); | ||
fn remove_provider(&mut self, k: &Key, p: &PeerId); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
store.records
now returns an ownedIter
. With thefilter_map
right after we might be cloning many items in vain. Isn't that an issue?