Skip to content
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

feat: Parallelize loading snapshots from storage #25657

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions influxdb3_write/src/persister.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use std::any::Any;
use std::io::Write;
use std::sync::Arc;
use thiserror::Error;
use tokio::task::JoinSet;
use uuid::Uuid;

#[derive(Debug, Error)]
Expand Down Expand Up @@ -187,7 +188,7 @@ impl Persister {
///
/// This is intended to be used on server start.
pub async fn load_snapshots(&self, mut most_recent_n: usize) -> Result<Vec<PersistedSnapshot>> {
let mut output = Vec::new();
let mut join_set = JoinSet::new();
let mut offset: Option<ObjPath> = None;
while most_recent_n > 0 {
let count = if most_recent_n > 1000 {
Expand Down Expand Up @@ -228,9 +229,19 @@ impl Persister {
let len = list.len();
let end = if len <= count { len } else { count };

async fn get_snapshot(
location: ObjPath,
object_store: Arc<dyn ObjectStore>,
) -> Result<PersistedSnapshot> {
let bytes = object_store.get(&location).await?.bytes().await?;
serde_json::from_slice(&bytes).map_err(Into::into)
}

for item in &list[0..end] {
let bytes = self.object_store.get(&item.location).await?.bytes().await?;
output.push(serde_json::from_slice(&bytes)?);
join_set.spawn(get_snapshot(
item.location.clone(),
Arc::clone(&self.object_store),
));
}

if end == 0 {
Expand All @@ -243,7 +254,8 @@ impl Persister {
offset = Some(list[end - 1].location.clone());
}

Ok(output)
// Returns an error if there is one and reuses the Vec's memory as well
join_set.join_all().await.into_iter().collect()
}

/// Loads a Parquet file from ObjectStore
Expand Down
Loading