Skip to main content

qdrant_edge/edge/
snapshots.rs

1use std::path::Path;
2
3use fs_err as fs;
4use crate::segment::common::operation_error::OperationResult;
5use crate::shard::snapshots::snapshot_manifest::SnapshotManifest;
6use crate::shard::snapshots::snapshot_utils::{SnapshotMergePlan, SnapshotUtils};
7
8use crate::edge::EdgeShard;
9
10impl EdgeShard {
11    pub fn unpack_snapshot(snapshot_path: &Path, target_path: &Path) -> OperationResult<()> {
12        SnapshotUtils::unpack_snapshot(snapshot_path, target_path)
13    }
14
15    pub fn snapshot_manifest(&self) -> OperationResult<SnapshotManifest> {
16        self.segments.read().snapshot_manifest()
17    }
18
19    pub fn recover_partial_snapshot(
20        shard_path: &Path,
21        current_manifest: &SnapshotManifest,
22        snapshot_path: &Path,
23        snapshot_manifest: &SnapshotManifest,
24    ) -> OperationResult<Self> {
25        let merge_plan = SnapshotUtils::partial_snapshot_merge_plan(
26            shard_path,
27            current_manifest,
28            snapshot_path,
29            snapshot_manifest,
30        );
31
32        let SnapshotMergePlan {
33            move_files,
34            replace_directories,
35            merge_directories,
36            delete_files,
37            delete_directories,
38        } = merge_plan;
39
40        for (move_file_from, move_file_to) in move_files {
41            crate::common::fs::move_file(&move_file_from, &move_file_to)?;
42        }
43
44        for (replace_dir_from, replace_dir_to) in replace_directories {
45            if replace_dir_to.exists() {
46                fs::remove_dir_all(&replace_dir_to)?;
47            }
48            crate::common::fs::move_dir(&replace_dir_from, &replace_dir_to)?;
49        }
50
51        for (merge_dir_from, merge_dir_to) in merge_directories {
52            crate::common::fs::move_dir(&merge_dir_from, &merge_dir_to)?;
53        }
54
55        for delete_file in delete_files {
56            fs::remove_file(&delete_file)?;
57        }
58
59        for delete_dir in delete_directories {
60            fs::remove_dir_all(&delete_dir)?;
61        }
62
63        EdgeShard::load(shard_path, None)
64    }
65}