From 690c861e9330eeaa7dedba6a973f286b7fe56d4c Mon Sep 17 00:00:00 2001 From: backurs Date: Mon, 16 Feb 2026 08:33:04 -0800 Subject: [PATCH] copy bftrees to prefix_path + bftreepaths location --- .../async_/bf_tree/neighbor_provider.rs | 4 +- .../graph/provider/async_/bf_tree/provider.rs | 59 +++++++++++++++++-- .../async_/bf_tree/quant_vector_provider.rs | 4 +- .../async_/bf_tree/vector_provider.rs | 4 +- 4 files changed, 60 insertions(+), 11 deletions(-) diff --git a/diskann-providers/src/model/graph/provider/async_/bf_tree/neighbor_provider.rs b/diskann-providers/src/model/graph/provider/async_/bf_tree/neighbor_provider.rs index fa19850d5..b853465df 100644 --- a/diskann-providers/src/model/graph/provider/async_/bf_tree/neighbor_provider.rs +++ b/diskann-providers/src/model/graph/provider/async_/bf_tree/neighbor_provider.rs @@ -54,8 +54,8 @@ impl NeighborProvider { /// Create a snapshot of the adjacency list index /// - pub fn snapshot(&self) { - self.adjacency_list_index.snapshot(); + pub fn snapshot(&self) -> std::path::PathBuf { + self.adjacency_list_index.snapshot() } /// Return the maximum degree (number of neighbors per vector) diff --git a/diskann-providers/src/model/graph/provider/async_/bf_tree/provider.rs b/diskann-providers/src/model/graph/provider/async_/bf_tree/provider.rs index 8650b969f..a31a1d78c 100644 --- a/diskann-providers/src/model/graph/provider/async_/bf_tree/provider.rs +++ b/diskann-providers/src/model/graph/provider/async_/bf_tree/provider.rs @@ -1897,8 +1897,28 @@ where } // Save vectors and neighbors - self.full_vectors.snapshot(); - self.neighbor_provider.snapshot(); + let vectors_snapshot_path = self.full_vectors.snapshot(); + let neighbors_snapshot_path = self.neighbor_provider.snapshot(); + + // Copy snapshot files to the target prefix location if they differ + let target_vectors_path = BfTreePaths::vectors_bftree(&saved_params.prefix); + if vectors_snapshot_path != target_vectors_path { + std::fs::copy(&vectors_snapshot_path, &target_vectors_path).map_err(|e| { + ANNError::log_index_error(format!( + "Failed to copy vectors from {:?} to {:?}: {}", + vectors_snapshot_path, target_vectors_path, e + )) + })?; + } + let target_neighbors_path = BfTreePaths::neighbors_bftree(&saved_params.prefix); + if neighbors_snapshot_path != target_neighbors_path { + std::fs::copy(&neighbors_snapshot_path, &target_neighbors_path).map_err(|e| { + ANNError::log_index_error(format!( + "Failed to copy neighbors from {:?} to {:?}: {}", + neighbors_snapshot_path, target_neighbors_path, e + )) + })?; + } // Save delete bitmap { @@ -2035,9 +2055,38 @@ where } // Save vectors, neighbors, and quant vectors - self.full_vectors.snapshot(); - self.neighbor_provider.snapshot(); - self.quant_vectors.snapshot(); + let vectors_snapshot_path = self.full_vectors.snapshot(); + let neighbors_snapshot_path = self.neighbor_provider.snapshot(); + let quant_snapshot_path = self.quant_vectors.snapshot(); + + // Copy snapshot files to the target prefix location if they differ + let target_vectors_path = BfTreePaths::vectors_bftree(&saved_params.prefix); + if vectors_snapshot_path != target_vectors_path { + std::fs::copy(&vectors_snapshot_path, &target_vectors_path).map_err(|e| { + ANNError::log_index_error(format!( + "Failed to copy vectors from {:?} to {:?}: {}", + vectors_snapshot_path, target_vectors_path, e + )) + })?; + } + let target_neighbors_path = BfTreePaths::neighbors_bftree(&saved_params.prefix); + if neighbors_snapshot_path != target_neighbors_path { + std::fs::copy(&neighbors_snapshot_path, &target_neighbors_path).map_err(|e| { + ANNError::log_index_error(format!( + "Failed to copy neighbors from {:?} to {:?}: {}", + neighbors_snapshot_path, target_neighbors_path, e + )) + })?; + } + let target_quant_path = BfTreePaths::quant_bftree(&saved_params.prefix); + if quant_snapshot_path != target_quant_path { + std::fs::copy(&quant_snapshot_path, &target_quant_path).map_err(|e| { + ANNError::log_index_error(format!( + "Failed to copy quant from {:?} to {:?}: {}", + quant_snapshot_path, target_quant_path, e + )) + })?; + } // Save PQ table metadata and data using PQStorage format let filename = BfTreePaths::pq_pivots_bin(&saved_params.prefix); diff --git a/diskann-providers/src/model/graph/provider/async_/bf_tree/quant_vector_provider.rs b/diskann-providers/src/model/graph/provider/async_/bf_tree/quant_vector_provider.rs index a0582748b..e64e7e7a9 100644 --- a/diskann-providers/src/model/graph/provider/async_/bf_tree/quant_vector_provider.rs +++ b/diskann-providers/src/model/graph/provider/async_/bf_tree/quant_vector_provider.rs @@ -76,8 +76,8 @@ impl QuantVectorProvider { /// Create a snapshot of the quant vector index /// - pub fn snapshot(&self) { - self.quant_vector_index.snapshot(); + pub fn snapshot(&self) -> std::path::PathBuf { + self.quant_vector_index.snapshot() } /// Create a new instance from an existing BfTree (for loading from snapshot) diff --git a/diskann-providers/src/model/graph/provider/async_/bf_tree/vector_provider.rs b/diskann-providers/src/model/graph/provider/async_/bf_tree/vector_provider.rs index 1a67034b5..e7231076b 100644 --- a/diskann-providers/src/model/graph/provider/async_/bf_tree/vector_provider.rs +++ b/diskann-providers/src/model/graph/provider/async_/bf_tree/vector_provider.rs @@ -104,8 +104,8 @@ impl VectorProvider { /// Create a snapshot of the vector index /// #[inline(always)] - pub fn snapshot(&self) { - self.vector_index.snapshot(); + pub fn snapshot(&self) -> std::path::PathBuf { + self.vector_index.snapshot() } /// Set vector with Id, `i``, to `v`