-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
[qs] batch store bootstrap perf improvements #15491
Merged
Merged
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,6 +123,7 @@ pub struct BatchStore { | |
impl BatchStore { | ||
pub(crate) fn new( | ||
epoch: u64, | ||
is_new_epoch: bool, | ||
last_certified_time: u64, | ||
db: Arc<dyn QuorumStoreStorage>, | ||
memory_quota: usize, | ||
|
@@ -146,18 +147,73 @@ impl BatchStore { | |
persist_subscribers: DashMap::new(), | ||
expiration_buffer_usecs, | ||
}; | ||
let db_content = db_clone | ||
.get_all_batches() | ||
.expect("failed to read data from db"); | ||
|
||
if is_new_epoch { | ||
tokio::task::spawn_blocking(move || { | ||
Self::gc_previous_epoch_batches_from_db(db_clone, epoch); | ||
}); | ||
} else { | ||
Self::populate_cache_and_gc_expired_batches( | ||
db_clone, | ||
epoch, | ||
last_certified_time, | ||
expiration_buffer_usecs, | ||
&batch_store, | ||
); | ||
} | ||
|
||
batch_store | ||
} | ||
|
||
fn gc_previous_epoch_batches_from_db(db: Arc<dyn QuorumStoreStorage>, current_epoch: u64) { | ||
let db_content = db.get_all_batches().expect("failed to read data from db"); | ||
info!( | ||
epoch = current_epoch, | ||
"QS: Read batches from storage. Len: {}", | ||
db_content.len(), | ||
); | ||
|
||
let mut expired_keys = Vec::new(); | ||
trace!( | ||
"QS: Batchreader {} {} {}", | ||
for (digest, value) in db_content { | ||
let epoch = value.epoch(); | ||
|
||
trace!( | ||
"QS: Batchreader recovery content epoch {:?}, digest {}", | ||
epoch, | ||
digest | ||
); | ||
|
||
if epoch < current_epoch { | ||
expired_keys.push(digest); | ||
} | ||
} | ||
|
||
info!( | ||
"QS: Batch store bootstrap expired keys len {}", | ||
expired_keys.len() | ||
); | ||
db.delete_batches(expired_keys) | ||
.expect("Deletion of expired keys should not fail"); | ||
} | ||
|
||
fn populate_cache_and_gc_expired_batches( | ||
db: Arc<dyn QuorumStoreStorage>, | ||
current_epoch: u64, | ||
last_certified_time: u64, | ||
expiration_buffer_usecs: u64, | ||
batch_store: &BatchStore, | ||
) { | ||
let db_content = db.get_all_batches().expect("failed to read data from db"); | ||
info!( | ||
epoch = current_epoch, | ||
"QS: Read batches from storage. Len: {}, Last Cerified Time: {}", | ||
db_content.len(), | ||
epoch, | ||
last_certified_time | ||
); | ||
|
||
let mut expired_keys = Vec::new(); | ||
for (digest, value) in db_content { | ||
let expiration = value.expiration(); | ||
let expiration = value.expiration().saturating_sub(expiration_buffer_usecs); | ||
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. Good catch |
||
|
||
trace!( | ||
"QS: Batchreader recovery content exp {:?}, digest {}", | ||
|
@@ -173,15 +229,15 @@ impl BatchStore { | |
.expect("Storage limit exceeded upon BatchReader construction"); | ||
} | ||
} | ||
trace!( | ||
"QS: Batchreader recovery expired keys len {}", | ||
|
||
info!( | ||
"QS: Batch store bootstrap expired keys len {}", | ||
expired_keys.len() | ||
); | ||
db_clone | ||
.delete_batches(expired_keys) | ||
.expect("Deletion of expired keys should not fail"); | ||
|
||
batch_store | ||
tokio::task::spawn_blocking(move || { | ||
db.delete_batches(expired_keys) | ||
.expect("Deletion of expired keys should not fail"); | ||
}); | ||
} | ||
|
||
fn epoch(&self) -> u64 { | ||
|
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
Oops, something went wrong.
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.
@bchocho @zekun000 I split the QS part of the PR out and addressed your comments here. I renamed the method to be clear.