@@ -13,12 +13,14 @@ const DEFAULT_MAX_RETRIES: usize = 5;
1313
1414pub struct SyncContext {
1515 db_path : String ,
16+ client : hyper:: Client < ConnectorService , Body > ,
1617 sync_url : String ,
1718 auth_token : Option < String > ,
1819 max_retries : usize ,
1920 /// Represents the max_frame_no from the server.
2021 durable_frame_num : u32 ,
21- client : hyper:: Client < ConnectorService , Body > ,
22+ /// Represents the current checkpoint generation.
23+ generation : u32 ,
2224}
2325
2426impl SyncContext {
@@ -34,9 +36,10 @@ impl SyncContext {
3436 db_path,
3537 sync_url,
3638 auth_token,
37- durable_frame_num : 0 ,
3839 max_retries : DEFAULT_MAX_RETRIES ,
3940 client,
41+ durable_frame_num : 0 ,
42+ generation : 1 ,
4043 } ;
4144
4245 me. read_metadata ( ) . await ?;
@@ -119,12 +122,17 @@ impl SyncContext {
119122 self . durable_frame_num
120123 }
121124
125+ pub ( crate ) fn generation ( & self ) -> u32 {
126+ self . generation
127+ }
128+
122129 async fn write_metadata ( & mut self ) -> Result < ( ) > {
123130 let path = format ! ( "{}-info" , self . db_path) ;
124131
125132 let contents = serde_json:: to_vec ( & MetadataJson {
126133 version : METADATA_VERSION ,
127134 durable_frame_num : self . durable_frame_num ,
135+ generation : self . generation ,
128136 } )
129137 . unwrap ( ) ;
130138
@@ -151,6 +159,7 @@ impl SyncContext {
151159 ) ;
152160
153161 self . durable_frame_num = metadata. durable_frame_num ;
162+ self . generation = metadata. generation ;
154163
155164 Ok ( ( ) )
156165 }
@@ -160,6 +169,7 @@ impl SyncContext {
160169struct MetadataJson {
161170 version : u32 ,
162171 durable_frame_num : u32 ,
172+ generation : u32 ,
163173}
164174
165175async fn atomic_write < P : AsRef < Path > > ( path : P , data : & [ u8 ] ) -> Result < ( ) > {
0 commit comments