From 860a35e4a140a8f2b60aa162b4eb31d8a24b2911 Mon Sep 17 00:00:00 2001 From: Lucio Franco Date: Mon, 28 Aug 2023 11:10:24 -0400 Subject: [PATCH] libsql/replication: Update example and errors --- crates/.gitignore | 1 + crates/core/examples/example_v2.rs | 6 +++++- crates/replication/src/replica/hook.rs | 6 ++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/crates/.gitignore b/crates/.gitignore index e61b720b75..1066327f73 100644 --- a/crates/.gitignore +++ b/crates/.gitignore @@ -4,3 +4,4 @@ data.libsql test.db test.db-shm test.db-wal +*.sqld diff --git a/crates/core/examples/example_v2.rs b/crates/core/examples/example_v2.rs index 62aaa1a865..5bb82dc740 100644 --- a/crates/core/examples/example_v2.rs +++ b/crates/core/examples/example_v2.rs @@ -8,7 +8,9 @@ async fn main() { "".to_string() }); - Database::open_remote(url, token).unwrap() + Database::open_with_sync("db.sqld", url, token) + .await + .unwrap() } else { Database::open_in_memory().unwrap() }; @@ -28,6 +30,8 @@ async fn main() { .await .unwrap(); + db.sync().await.unwrap(); + let stmt = conn .prepare("SELECT * FROM users WHERE email = ?1") .await diff --git a/crates/replication/src/replica/hook.rs b/crates/replication/src/replica/hook.rs index ae064f6c81..25a7b682bf 100644 --- a/crates/replication/src/replica/hook.rs +++ b/crates/replication/src/replica/hook.rs @@ -5,6 +5,7 @@ use libsql_sys::ffi::{PgHdr, SQLITE_ERROR}; use libsql_sys::init_static_wal_method; use libsql_sys::types::Wal; use libsql_sys::{types::XWalFrameFn, wal_hook::WalHook}; +use tokio::sync::mpsc::error::TryRecvError; use crate::frame::{Frame, FrameBorrowed}; use crate::{FrameNo, WAL_PAGE_SIZE}; @@ -175,6 +176,11 @@ unsafe impl WalHook for InjectorHook { return LIBSQL_CONTINUE_REPLICATION as c_int; } } + Err(TryRecvError::Empty) => { + tracing::debug!("Channel empty, waiting for frames"); + + return LIBSQL_CONTINUE_REPLICATION as c_int; + } Err(e) => { tracing::warn!("replication channel closed: {}", e); return LIBSQL_EXIT_REPLICATION as c_int;