@@ -4,8 +4,8 @@ use crate::util;
44use anyhow:: Context as _;
55use qdrant_client:: Qdrant ;
66use rand:: Rng ;
7- use std:: collections:: VecDeque ;
87use std:: io;
8+ use std:: path:: PathBuf ;
99use std:: process:: exit;
1010use std:: sync:: Arc ;
1111use std:: sync:: atomic:: { AtomicBool , Ordering } ;
@@ -50,21 +50,24 @@ pub fn start_process(
5050pub struct ProcessManager {
5151 pub working_dir : String ,
5252 pub binary_path : String ,
53- pub backup_dirs : VecDeque < String > ,
53+ pub backup_dir : Option < String > ,
5454 pub child_process : Child ,
5555 pub kill_on_drop : bool ,
5656 pub cpu_quota : Option < u32 > ,
5757}
5858
5959impl ProcessManager {
6060 pub fn from_args ( args : & Args ) -> io:: Result < Self > {
61- let manager = Self :: new (
61+ let mut manager = Self :: new (
6262 & args. working_dir ,
6363 & args. exec_path ,
6464 args. shutdown_on_error ,
6565 args. cpu_quota ,
66- ) ?
67- . with_backup_dirs ( args. backup_working_dir . clone ( ) ) ;
66+ ) ?;
67+
68+ if let Some ( storage_backup) = & args. storage_backup {
69+ manager = manager. with_backup_dirs ( storage_backup) ;
70+ }
6871
6972 Ok ( manager)
7073 }
@@ -80,15 +83,15 @@ impl ProcessManager {
8083 Ok ( Self {
8184 working_dir : working_dir. to_string ( ) ,
8285 binary_path : binary_path. to_string ( ) ,
83- backup_dirs : VecDeque :: new ( ) ,
86+ backup_dir : None ,
8487 child_process : child,
8588 kill_on_drop,
8689 cpu_quota,
8790 } )
8891 }
8992
90- pub fn with_backup_dirs ( mut self , backup_dirs : impl Into < VecDeque < String > > ) -> Self {
91- self . backup_dirs = backup_dirs . into ( ) ;
93+ pub fn with_backup_dirs ( mut self , backup_dir : impl Into < String > ) -> Self {
94+ self . backup_dir = Some ( backup_dir . into ( ) ) ;
9295 self
9396 }
9497
@@ -97,25 +100,27 @@ impl ProcessManager {
97100 self . child_process . kill ( ) . await . unwrap ( ) ;
98101 }
99102
100- pub async fn backup_working_dir ( & mut self ) -> anyhow:: Result < ( ) > {
101- let Some ( backup_dir) = self . backup_dirs . front ( ) else {
103+ pub async fn backup_storage_dir ( & mut self ) -> anyhow:: Result < ( ) > {
104+ let Some ( backup_dir) = & self . backup_dir else {
102105 return Ok ( ( ) ) ;
103106 } ;
104107
105108 let backup_exists = fs:: try_exists ( backup_dir) . await . with_context ( || {
106- format ! ( "failed to query if backup working dir {backup_dir} exists" )
109+ format ! ( "failed to query if backup storage dir {backup_dir} exists" )
107110 } ) ?;
108111
112+ let backup_dir = PathBuf :: from ( backup_dir) ;
113+ let backup_dir_path = backup_dir. as_path ( ) ;
114+
115+ let source_storage_dir = PathBuf :: from ( & self . working_dir ) . join ( "storage" ) ;
116+
109117 if backup_exists {
110- fs:: remove_dir_all ( backup_dir )
118+ fs:: remove_dir_all ( backup_dir_path )
111119 . await
112- . with_context ( || format ! ( "failed to remove backup working dir {backup_dir }" ) ) ?;
120+ . with_context ( || format ! ( "failed to remove backup storage dir {backup_dir_path:? }" ) ) ?;
113121 }
114122
115- util:: copy_dir ( & self . working_dir , backup_dir) . await ?;
116-
117- let backup_dir = self . backup_dirs . pop_front ( ) . expect ( "backup dir" ) ;
118- self . backup_dirs . push_back ( backup_dir) ;
123+ util:: copy_dir ( & source_storage_dir, backup_dir_path) . await ?;
119124
120125 Ok ( ( ) )
121126 }
@@ -141,13 +146,7 @@ impl ProcessManager {
141146 log:: info!( "** Restarting qdrant **" ) ;
142147 self . kill_process ( ) . await ;
143148
144- if let Err ( err) = self . backup_working_dir ( ) . await {
145- log:: error!(
146- "Failed to backup working dir {} to {}: {err:?}" ,
147- self . working_dir,
148- self . backup_dirs. front( ) . expect( "backup dir" ) ,
149- ) ;
150- }
149+ self . backup_storage_dir ( ) . await . unwrap ( ) ;
151150
152151 self . child_process = start_process (
153152 & self . working_dir ,
0 commit comments