Skip to content

Commit e1962a4

Browse files
generallagourlay
andcommitted
Fix no file or directory error on snapshot creation (qdrant#2720)
* remove temp files from archive * fmt * Undo revert "Remove one layer of tmp folder for shards" (qdrant#2683) Remove one layer of tmp folder for shards Unicity of segment tmp folder provided by Uuid --------- Co-authored-by: Arnaud Gourlay <[email protected]>
1 parent abd0d57 commit e1962a4

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

lib/collection/src/collection.rs

+17-9
Original file line numberDiff line numberDiff line change
@@ -1606,44 +1606,52 @@ impl Collection {
16061606
);
16071607

16081608
// Dedicated temporary directory for this snapshot (deleted on drop)
1609-
let snapshot_temp_dir = tempfile::Builder::new()
1610-
.prefix(&format!("{snapshot_name}-temp-"))
1609+
let snapshot_temp_target_dir = tempfile::Builder::new()
1610+
.prefix(&format!("{snapshot_name}-target-"))
16111611
.tempdir_in(global_temp_dir)?;
1612-
let snapshot_temp_dir_path = snapshot_temp_dir.path().to_path_buf();
1612+
1613+
let snapshot_temp_target_dir_path = snapshot_temp_target_dir.path().to_path_buf();
16131614
// Create snapshot of each shard
16141615
{
1616+
let snapshot_temp_temp_dir = tempfile::Builder::new()
1617+
.prefix(&format!("{snapshot_name}-temp-"))
1618+
.tempdir_in(global_temp_dir)?;
16151619
let shards_holder = self.shards_holder.read().await;
16161620
// Create snapshot of each shard
16171621
for (shard_id, replica_set) in shards_holder.get_shards() {
16181622
let shard_snapshot_path =
1619-
versioned_shard_path(&snapshot_temp_dir_path, *shard_id, 0);
1623+
versioned_shard_path(&snapshot_temp_target_dir_path, *shard_id, 0);
16201624
create_dir_all(&shard_snapshot_path).await?;
16211625
// If node is listener, we can save whatever currently is in the storage
16221626
let save_wal = self.shared_storage_config.node_type != NodeType::Listener;
16231627
replica_set
1624-
.create_snapshot(&snapshot_temp_dir_path, &shard_snapshot_path, save_wal)
1628+
.create_snapshot(
1629+
snapshot_temp_temp_dir.path(),
1630+
&shard_snapshot_path,
1631+
save_wal,
1632+
)
16251633
.await?;
16261634
}
16271635
}
16281636

16291637
// Save collection config and version
1630-
CollectionVersion::save(&snapshot_temp_dir_path)?;
1638+
CollectionVersion::save(&snapshot_temp_target_dir_path)?;
16311639
self.collection_config
16321640
.read()
16331641
.await
1634-
.save(&snapshot_temp_dir_path)?;
1642+
.save(&snapshot_temp_target_dir_path)?;
16351643

16361644
// Dedicated temporary file for archiving this snapshot (deleted on drop)
16371645
let mut snapshot_temp_arc_file = tempfile::Builder::new()
16381646
.prefix(&format!("{snapshot_name}-arc-"))
16391647
.tempfile_in(global_temp_dir)?;
16401648

16411649
// Archive snapshot folder into a single file
1642-
log::debug!("Archiving snapshot {:?}", &snapshot_temp_dir_path);
1650+
log::debug!("Archiving snapshot {:?}", &snapshot_temp_target_dir_path);
16431651
let archiving = tokio::task::spawn_blocking(move || {
16441652
let mut builder = TarBuilder::new(snapshot_temp_arc_file.as_file_mut());
16451653
// archive recursively collection directory `snapshot_path_with_arc_extension` into `snapshot_path`
1646-
builder.append_dir_all(".", &snapshot_temp_dir_path)?;
1654+
builder.append_dir_all(".", &snapshot_temp_target_dir_path)?;
16471655
builder.finish()?;
16481656
drop(builder);
16491657
// return ownership of the file

lib/collection/src/shards/local_shard.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use tokio::fs::{copy, create_dir_all, remove_dir_all};
2323
use tokio::runtime::Handle;
2424
use tokio::sync::mpsc::Sender;
2525
use tokio::sync::{mpsc, oneshot, Mutex, RwLock as TokioRwLock};
26-
use uuid::Uuid;
2726
use wal::{Wal, WalOptions};
2827

2928
use super::update_tracker::UpdateTracker;
@@ -573,8 +572,7 @@ impl LocalShard {
573572
rx.await?;
574573
}
575574

576-
let temp_path = temp_path.join(format!("shard-{}", Uuid::new_v4()));
577-
create_dir_all(&temp_path).await?;
575+
let temp_path = temp_path.to_owned();
578576

579577
tokio::task::spawn_blocking(move || {
580578
let segments_read = segments.read();

0 commit comments

Comments
 (0)