Skip to content

Commit

Permalink
libsql/replication: Update example and errors
Browse files Browse the repository at this point in the history
  • Loading branch information
LucioFranco committed Aug 28, 2023
1 parent 5ad6bc3 commit 860a35e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions crates/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ data.libsql
test.db
test.db-shm
test.db-wal
*.sqld
6 changes: 5 additions & 1 deletion crates/core/examples/example_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
};
Expand All @@ -28,6 +30,8 @@ async fn main() {
.await
.unwrap();

db.sync().await.unwrap();

let stmt = conn
.prepare("SELECT * FROM users WHERE email = ?1")
.await
Expand Down
6 changes: 6 additions & 0 deletions crates/replication/src/replica/hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 860a35e

Please sign in to comment.