Skip to content

Commit d18e237

Browse files
authored
Only pull frames when doing write delegation (#2028)
Fixes #2026.
2 parents 361d082 + 1f640e9 commit d18e237

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

libsql/src/database.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,14 @@ cfg_replication! {
392392
#[cfg(feature = "replication")]
393393
DbType::Sync { db, encryption_config: _ } => db.sync().await,
394394
#[cfg(feature = "sync")]
395-
DbType::Offline { db, .. } => db.sync_offline().await,
395+
DbType::Offline { db, remote_writes: false, .. } => db.sync_offline().await,
396+
#[cfg(feature = "sync")]
397+
DbType::Offline { db, remote_writes: true, .. } => {
398+
let mut sync_ctx = db.sync_ctx.as_ref().unwrap().lock().await;
399+
crate::sync::bootstrap_db(&mut sync_ctx).await?;
400+
let conn = db.connect()?;
401+
crate::sync::try_pull(&mut sync_ctx, &conn).await
402+
},
396403
_ => Err(Error::SyncNotSupported(format!("{:?}", self.db_type))),
397404
}
398405
}

libsql/src/sync.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ async fn try_push(
814814
})
815815
}
816816

817-
async fn try_pull(
817+
pub async fn try_pull(
818818
sync_ctx: &mut SyncContext,
819819
conn: &Connection,
820820
) -> Result<crate::database::Replicated> {

libsql/src/sync/statement.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,21 @@ impl Stmt for SyncedStatement {
2222
async fn execute(&mut self, params: &Params) -> Result<usize> {
2323
let result = self.inner.execute(params).await;
2424
let mut context = self.context.lock().await;
25-
let _ = crate::sync::sync_offline(&mut context, &self.conn).await;
25+
crate::sync::try_pull(&mut context, &self.conn).await?;
2626
result
2727
}
2828

2929
async fn query(&mut self, params: &Params) -> Result<Rows> {
3030
let result = self.inner.query(params).await;
3131
let mut context = self.context.lock().await;
32-
let _ = crate::sync::sync_offline(&mut context, &self.conn).await;
32+
crate::sync::try_pull(&mut context, &self.conn).await?;
3333
result
3434
}
3535

3636
async fn run(&mut self, params: &Params) -> Result<()> {
3737
let result = self.inner.run(params).await;
3838
let mut context = self.context.lock().await;
39-
let _ = crate::sync::sync_offline(&mut context, &self.conn).await;
39+
crate::sync::try_pull(&mut context, &self.conn).await?;
4040
result
4141
}
4242

0 commit comments

Comments
 (0)