@@ -144,11 +144,11 @@ impl Database {
144
144
endpoint
145
145
} ;
146
146
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
+
152
152
Ok ( db)
153
153
}
154
154
@@ -388,7 +388,7 @@ impl Database {
388
388
#[ cfg( feature = "sync" ) ]
389
389
/// Push WAL frames to remote.
390
390
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 ;
392
392
let conn = self . connect ( ) ?;
393
393
394
394
let page_size = {
@@ -402,7 +402,7 @@ impl Database {
402
402
403
403
let max_frame_no = conn. wal_frame_count ( ) ;
404
404
405
- let generation = 1 ; // TODO: Probe from WAL.
405
+ let generation = sync_ctx . generation ( ) ; // TODO: Probe from WAL.
406
406
let start_frame_no = sync_ctx. durable_frame_num ( ) + 1 ;
407
407
let end_frame_no = max_frame_no;
408
408
@@ -423,6 +423,10 @@ impl Database {
423
423
frame_no += 1 ;
424
424
}
425
425
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.
426
430
let frame_count = end_frame_no - start_frame_no + 1 ;
427
431
Ok ( crate :: database:: Replicated {
428
432
frame_no : None ,
0 commit comments