Skip to content

Commit 3575914

Browse files
committed
libsql: offline sync track generation in metadata
1 parent 203fc49 commit 3575914

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

libsql/src/local/database.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

libsql/src/sync.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ const DEFAULT_MAX_RETRIES: usize = 5;
1313

1414
pub 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

2426
impl 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 {
160169
struct MetadataJson {
161170
version: u32,
162171
durable_frame_num: u32,
172+
generation: u32,
163173
}
164174

165175
async fn atomic_write<P: AsRef<Path>>(path: P, data: &[u8]) -> Result<()> {

0 commit comments

Comments
 (0)