Skip to content

Commit 3c0dc60

Browse files
committed
fix: sync instead of pull when not remote_writes
1 parent 95426dc commit 3c0dc60

2 files changed

Lines changed: 13 additions & 10 deletions

File tree

libsql/src/database.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -679,10 +679,8 @@ impl Database {
679679
..
680680
} => {
681681
use crate::{
682-
hrana::connection::HttpConnection,
683-
local::impls::LibsqlConnection,
684-
replication::connection::State,
685-
sync::connection::SyncedConnection,
682+
hrana::connection::HttpConnection, local::impls::LibsqlConnection,
683+
replication::connection::State, sync::connection::SyncedConnection,
686684
};
687685
use tokio::sync::Mutex;
688686

libsql/src/database/builder.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::sync::Arc;
66

77
use tracing::Instrument as _;
88

9-
use crate::{sync::DropAbort, Database, Result};
9+
use crate::{Database, Result};
1010

1111
use super::DbType;
1212

@@ -645,7 +645,7 @@ cfg_sync! {
645645
db.sync_ctx.as_ref().unwrap().lock().await.set_push_batch_size(push_batch_size);
646646
}
647647

648-
let mut bg_abort: Option<Arc<DropAbort>> = None;
648+
let mut bg_abort: Option<Arc<crate::sync::DropAbort>> = None;
649649
let conn = db.connect()?;
650650

651651
let sync_ctx = db.sync_ctx.as_ref().unwrap().clone();
@@ -656,17 +656,22 @@ cfg_sync! {
656656
loop {
657657
tracing::trace!("trying to sync");
658658
let mut ctx = sync_ctx.lock().await;
659-
if let Err(e) = crate::sync::try_pull(&mut ctx, &conn).await {
660-
tracing::error!("sync error: {}", e);
659+
if remote_writes {
660+
if let Err(e) = crate::sync::try_pull(&mut ctx, &conn).await {
661+
tracing::error!("sync error: {}", e);
662+
}
663+
} else {
664+
if let Err(e) = crate::sync::sync_offline(&mut ctx, &conn).await {
665+
tracing::error!("sync error: {}", e);
666+
}
661667
}
662-
663668
tokio::time::sleep(sync_interval).await;
664669
}
665670
}
666671
.instrument(tracing::info_span!("sync_interval")),
667672
);
668673

669-
bg_abort.replace(Arc::new(DropAbort(jh.abort_handle())));
674+
bg_abort.replace(Arc::new(crate::sync::DropAbort(jh.abort_handle())));
670675
}
671676

672677
Ok(Database {

0 commit comments

Comments
 (0)