Skip to content

Commit 26ac07e

Browse files
committed
libsql: offline sync batch write_metadata
1 parent 5303da4 commit 26ac07e

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

libsql/src/local/database.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,8 @@ impl Database {
423423
frame_no += 1;
424424
}
425425

426+
sync_ctx.write_metadata().await?;
427+
426428
// TODO(lucio): this can underflow if the server previously returned a higher max_frame_no
427429
// than what we have stored here.
428430
let frame_count = end_frame_no - start_frame_no + 1;

libsql/src/sync.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,6 @@ impl SyncContext {
120120
// Update our last known max_frame_no from the server.
121121
self.durable_frame_num = durable_frame_num;
122122

123-
self.write_metadata().await?;
124-
125123
Ok(durable_frame_num)
126124
}
127125

@@ -193,7 +191,7 @@ impl SyncContext {
193191
self.generation
194192
}
195193

196-
async fn write_metadata(&mut self) -> Result<()> {
194+
pub(crate) async fn write_metadata(&mut self) -> Result<()> {
197195
let path = format!("{}-info", self.db_path);
198196

199197
let mut metadata = MetadataJson {

libsql/src/sync/test.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ async fn test_sync_context_push_frame() {
2828

2929
// Push a frame and verify the response
3030
let durable_frame = sync_ctx.push_one_frame(frame, 1, 0).await.unwrap();
31+
sync_ctx.write_metadata().await.unwrap();
3132
assert_eq!(durable_frame, 1); // First frame should return max_frame_no = 1
3233

3334
// Verify internal state was updated
@@ -55,6 +56,7 @@ async fn test_sync_context_with_auth() {
5556
let mut sync_ctx = sync_ctx;
5657

5758
let durable_frame = sync_ctx.push_one_frame(frame, 1, 0).await.unwrap();
59+
sync_ctx.write_metadata().await.unwrap();
5860
assert_eq!(durable_frame, 1);
5961
assert_eq!(server.frame_count(), 1);
6062
}
@@ -80,6 +82,7 @@ async fn test_sync_context_multiple_frames() {
8082
for i in 0..3 {
8183
let frame = Bytes::from(format!("frame data {}", i));
8284
let durable_frame = sync_ctx.push_one_frame(frame, 1, i).await.unwrap();
85+
sync_ctx.write_metadata().await.unwrap();
8386
assert_eq!(durable_frame, i + 1);
8487
assert_eq!(sync_ctx.durable_frame_num(), i + 1);
8588
assert_eq!(server.frame_count(), i + 1);
@@ -105,6 +108,7 @@ async fn test_sync_context_corrupted_metadata() {
105108
let mut sync_ctx = sync_ctx;
106109
let frame = Bytes::from("test frame data");
107110
let durable_frame = sync_ctx.push_one_frame(frame, 1, 0).await.unwrap();
111+
sync_ctx.write_metadata().await.unwrap();
108112
assert_eq!(durable_frame, 1);
109113
assert_eq!(server.frame_count(), 1);
110114

0 commit comments

Comments
 (0)