Skip to content

Commit 4647469

Browse files
committed
fix: sync instead of pull when not remote_writes
1 parent 3a84ed4 commit 4647469

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

libsql/src/database.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ pub use builder::Builder;
77
#[cfg(feature = "core")]
88
pub use libsql_sys::{Cipher, EncryptionConfig};
99

10-
use crate::sync::DropAbort;
1110
use crate::{Connection, Result};
1211
use std::fmt;
1312
use std::sync::atomic::AtomicU64;
14-
use std::sync::Arc;
1513

1614
cfg_core! {
1715
bitflags::bitflags! {
@@ -101,7 +99,7 @@ enum DbType {
10199
url: String,
102100
auth_token: String,
103101
connector: crate::util::ConnectorService,
104-
_bg_abort: Option<Arc<DropAbort>>,
102+
_bg_abort: Option<std::sync::Arc<crate::sync::DropAbort>>,
105103
},
106104
#[cfg(feature = "remote")]
107105
Remote {
@@ -679,10 +677,8 @@ impl Database {
679677
..
680678
} => {
681679
use crate::{
682-
hrana::connection::HttpConnection,
683-
local::impls::LibsqlConnection,
684-
replication::connection::State,
685-
sync::connection::SyncedConnection,
680+
hrana::connection::HttpConnection, local::impls::LibsqlConnection,
681+
replication::connection::State, sync::connection::SyncedConnection,
686682
};
687683
use tokio::sync::Mutex;
688684

libsql/src/database/builder.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@ cfg_core! {
22
use crate::EncryptionConfig;
33
}
44

5-
use std::sync::Arc;
6-
7-
use tracing::Instrument as _;
8-
9-
use crate::{sync::DropAbort, Database, Result};
5+
use crate::{Database, Result};
106

117
use super::DbType;
128

@@ -600,6 +596,8 @@ cfg_sync! {
600596

601597
/// Build a connection to a local database that can be synced to remote server.
602598
pub async fn build(self) -> Result<Database> {
599+
use tracing::Instrument as _;
600+
603601
let SyncedDatabase {
604602
path,
605603
flags,
@@ -645,7 +643,7 @@ cfg_sync! {
645643
db.sync_ctx.as_ref().unwrap().lock().await.set_push_batch_size(push_batch_size);
646644
}
647645

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

651649
let sync_ctx = db.sync_ctx.as_ref().unwrap().clone();
@@ -656,17 +654,22 @@ cfg_sync! {
656654
loop {
657655
tracing::trace!("trying to sync");
658656
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);
657+
if remote_writes {
658+
if let Err(e) = crate::sync::try_pull(&mut ctx, &conn).await {
659+
tracing::error!("sync error: {}", e);
660+
}
661+
} else {
662+
if let Err(e) = crate::sync::sync_offline(&mut ctx, &conn).await {
663+
tracing::error!("sync error: {}", e);
664+
}
661665
}
662-
663666
tokio::time::sleep(sync_interval).await;
664667
}
665668
}
666669
.instrument(tracing::info_span!("sync_interval")),
667670
);
668671

669-
bg_abort.replace(Arc::new(DropAbort(jh.abort_handle())));
672+
bg_abort.replace(std::sync::Arc::new(crate::sync::DropAbort(jh.abort_handle())));
670673
}
671674

672675
Ok(Database {

0 commit comments

Comments
 (0)