@@ -73,7 +73,6 @@ pub struct Services {
7373
7474#[ implement( Services ) ]
7575pub async fn build ( server : Arc < Server > ) -> Result < Arc < Self > > {
76- Self :: maybe_bootstrap_checkpoint ( & server) . await ?;
7776 let db = Database :: open ( & server) . await ?;
7877 let services = Arc :: new ( OnceServices :: default ( ) ) ;
7978 let args = Args {
@@ -275,106 +274,3 @@ pub async fn memory_usage(&self) -> Result<String> {
275274 } )
276275 . await
277276}
278-
279- #[ implement( Services ) ]
280- async fn maybe_bootstrap_checkpoint ( server : & Arc < Server > ) -> Result {
281- use bytes:: Bytes ;
282-
283- let primary_url = match server. config . rocksdb_primary_url . as_ref ( ) {
284- | Some ( url) => url. clone ( ) ,
285- | None => return Ok ( ( ) ) ,
286- } ;
287-
288- let db_path = server. config . database_path . clone ( ) ;
289- let sidecar = db_path
290- . parent ( )
291- . unwrap_or ( & db_path)
292- . join ( "_replication_needs_bootstrap" ) ;
293-
294- let current_file = db_path. join ( "CURRENT" ) ;
295- let needs_bootstrap = sidecar. exists ( ) || !current_file. exists ( ) || {
296- std:: fs:: metadata ( & current_file)
297- . map ( |m| m. len ( ) == 0 )
298- . unwrap_or ( true )
299- } ;
300-
301- if !needs_bootstrap {
302- return Ok ( ( ) ) ;
303- }
304-
305- let token = server
306- . config
307- . rocksdb_replication_token
308- . as_deref ( )
309- . unwrap_or ( "" ) ;
310-
311- info ! ( "Pre-open bootstrap: downloading checkpoint from {primary_url}" ) ;
312-
313- let client = reqwest:: Client :: builder ( )
314- . connect_timeout ( std:: time:: Duration :: from_secs ( 10 ) )
315- . build ( )
316- . map_err ( |e| tuwunel_core:: err!( Database ( "Failed to build HTTP client: {e}" ) ) ) ?;
317-
318- let resp = client
319- . get ( format ! ( "{primary_url}/_tuwunel/replication/checkpoint" ) )
320- . header ( "x-tuwunel-replication-token" , token)
321- . send ( )
322- . await
323- . map_err ( |e| tuwunel_core:: err!( Database ( "Checkpoint request failed: {e}" ) ) ) ?;
324-
325- if !resp. status ( ) . is_success ( ) {
326- return Err ( tuwunel_core:: err!( Database (
327- "Primary returned {} for checkpoint" ,
328- resp. status( )
329- ) ) ) ;
330- }
331-
332- let seq: u64 = resp
333- . headers ( )
334- . get ( "x-tuwunel-checkpoint-sequence" )
335- . and_then ( |v| v. to_str ( ) . ok ( ) )
336- . and_then ( |s| s. parse ( ) . ok ( ) )
337- . unwrap_or ( 0 ) ;
338-
339- let tar_bytes: Bytes = resp
340- . bytes ( )
341- . await
342- . map_err ( |e| tuwunel_core:: err!( Database ( "Reading checkpoint body: {e}" ) ) ) ?;
343-
344- let parent = db_path. parent ( ) . unwrap_or ( & db_path) ;
345- let staging = parent. join ( "_replication_staging" ) ;
346- let backup = parent. join ( "_replication_backup" ) ;
347-
348- if staging. exists ( ) {
349- std:: fs:: remove_dir_all ( & staging)
350- . map_err ( |e| tuwunel_core:: err!( Database ( "Removing staging dir: {e}" ) ) ) ?;
351- }
352- std:: fs:: create_dir_all ( & staging)
353- . map_err ( |e| tuwunel_core:: err!( Database ( "Creating staging dir: {e}" ) ) ) ?;
354-
355- let cursor = std:: io:: Cursor :: new ( & * tar_bytes) ;
356- let mut archive = tar:: Archive :: new ( cursor) ;
357- archive
358- . unpack ( & staging)
359- . map_err ( |e| tuwunel_core:: err!( Database ( "Unpacking checkpoint: {e}" ) ) ) ?;
360-
361- let checkpoint_src = staging. join ( "checkpoint" ) ;
362-
363- if backup. exists ( ) {
364- std:: fs:: remove_dir_all ( & backup)
365- . map_err ( |e| tuwunel_core:: err!( Database ( "Removing backup: {e}" ) ) ) ?;
366- }
367- if db_path. exists ( ) {
368- std:: fs:: rename ( & db_path, & backup)
369- . map_err ( |e| tuwunel_core:: err!( Database ( "Moving db to backup: {e}" ) ) ) ?;
370- }
371- std:: fs:: rename ( & checkpoint_src, & db_path)
372- . map_err ( |e| tuwunel_core:: err!( Database ( "Moving checkpoint to db_path: {e}" ) ) ) ?;
373-
374- let _: std:: io:: Result < ( ) > = std:: fs:: remove_dir_all ( & staging) ;
375- std:: fs:: write ( & sidecar, seq. to_string ( ) )
376- . map_err ( |e| tuwunel_core:: err!( Database ( "Writing bootstrap sidecar: {e}" ) ) ) ?;
377-
378- info ! ( "Pre-open bootstrap complete; resume_seq = {seq}. RocksDB will open clean checkpoint." ) ;
379- Ok ( ( ) )
380- }
0 commit comments