@@ -144,11 +144,11 @@ impl Database {
144144 endpoint
145145 } ;
146146 let mut db = Database :: open ( & db_path, flags) ?;
147- db . sync_ctx = Some ( tokio :: sync :: Mutex :: new ( SyncContext :: new (
148- connector ,
149- endpoint,
150- Some ( auth_token ) ,
151- ) ) ) ;
147+
148+ let sync_ctx =
149+ SyncContext :: new ( connector , db_path . into ( ) , endpoint, Some ( auth_token ) ) . await ? ;
150+ db . sync_ctx = Some ( tokio :: sync :: Mutex :: new ( sync_ctx ) ) ;
151+
152152 Ok ( db)
153153 }
154154
@@ -388,7 +388,7 @@ impl Database {
388388 #[ cfg( feature = "sync" ) ]
389389 /// Push WAL frames to remote.
390390 pub async fn push ( & self ) -> Result < crate :: database:: Replicated > {
391- let sync_ctx = self . sync_ctx . as_ref ( ) . unwrap ( ) . lock ( ) . await ;
391+ let mut sync_ctx = self . sync_ctx . as_ref ( ) . unwrap ( ) . lock ( ) . await ;
392392 let conn = self . connect ( ) ?;
393393
394394 let page_size = {
@@ -402,7 +402,7 @@ impl Database {
402402
403403 let max_frame_no = conn. wal_frame_count ( ) ;
404404
405- let generation = 1 ; // TODO: Probe from WAL.
405+ let generation = sync_ctx . generation ( ) ; // TODO: Probe from WAL.
406406 let start_frame_no = sync_ctx. durable_frame_num ( ) + 1 ;
407407 let end_frame_no = max_frame_no;
408408
@@ -423,6 +423,10 @@ impl Database {
423423 frame_no += 1 ;
424424 }
425425
426+ sync_ctx. write_metadata ( ) . await ?;
427+
428+ // TODO(lucio): this can underflow if the server previously returned a higher max_frame_no
429+ // than what we have stored here.
426430 let frame_count = end_frame_no - start_frame_no + 1 ;
427431 Ok ( crate :: database:: Replicated {
428432 frame_no : None ,
0 commit comments