Skip to content

Commit

Permalink
fixlets
Browse files Browse the repository at this point in the history
  • Loading branch information
penberg committed Nov 13, 2024
1 parent d039fd1 commit 436679d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 25 deletions.
38 changes: 20 additions & 18 deletions libsql/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,29 @@ cfg_core! {
}
}

pub type FrameNo = u64;
cfg_replication_or_sync! {
pub type FrameNo = u64;

#[derive(Debug)]
pub struct Replicated {
pub(crate) frame_no: Option<FrameNo>,
pub(crate) frames_synced: usize,
}

impl Replicated {
/// The currently synced frame number. This can be used to track
/// where in the log you might be. Beware that this value can be reset to a lower value by the
/// server in certain situations. Please use `frames_synced` if you want to track the amount of
/// work a sync has done.
pub fn frame_no(&self) -> Option<FrameNo> {
self.frame_no
#[derive(Debug)]
pub struct Replicated {
pub(crate) frame_no: Option<FrameNo>,
pub(crate) frames_synced: usize,
}

/// The count of frames synced during this call of `sync`. A frame is a 4kB frame from the
/// libsql write ahead log.
pub fn frames_synced(&self) -> usize {
self.frames_synced
impl Replicated {
/// The currently synced frame number. This can be used to track
/// where in the log you might be. Beware that this value can be reset to a lower value by the
/// server in certain situations. Please use `frames_synced` if you want to track the amount of
/// work a sync has done.
pub fn frame_no(&self) -> Option<FrameNo> {
self.frame_no
}

/// The count of frames synced during this call of `sync`. A frame is a 4kB frame from the
/// libsql write ahead log.
pub fn frames_synced(&self) -> usize {
self.frames_synced
}
}
}

Expand Down
13 changes: 6 additions & 7 deletions libsql/src/local/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ cfg_sync! {
use crate::{database::OpenFlags, local::connection::Connection};
use crate::{Error::ConnectionFailed, Result};
use libsql_sys::ffi;
use crate::database::Replicated;

// A libSQL database.
pub struct Database {
Expand Down Expand Up @@ -288,7 +287,7 @@ impl Database {
#[cfg(feature = "replication")]
/// Perform a sync step, returning the new replication index, or None, if the nothing was
/// replicated yet
pub async fn sync_oneshot(&self) -> Result<Replicated> {
pub async fn sync_oneshot(&self) -> Result<crate::database::Replicated> {
if let Some(ctx) = &self.replication_ctx {
ctx.replicator.sync_oneshot().await
} else {
Expand All @@ -301,7 +300,7 @@ impl Database {

#[cfg(feature = "replication")]
/// Sync with primary
pub async fn sync(&self) -> Result<Replicated> {
pub async fn sync(&self) -> Result<crate::database::Replicated> {
Ok(self.sync_oneshot().await?)
}

Expand All @@ -321,7 +320,7 @@ impl Database {

#[cfg(feature = "replication")]
/// Sync with primary at least to a given replication index
pub async fn sync_until(&self, replication_index: FrameNo) -> Result<Replicated> {
pub async fn sync_until(&self, replication_index: FrameNo) -> Result<crate::database::Replicated> {
if let Some(ctx) = &self.replication_ctx {
let mut frame_no: Option<FrameNo> = ctx.replicator.committed_frame_no().await;
let mut frames_synced: usize = 0;
Expand All @@ -330,7 +329,7 @@ impl Database {
frame_no = res.frame_no();
frames_synced += res.frames_synced();
}
Ok(Replicated {
Ok(crate::database::Replicated {
frame_no,
frames_synced,
})
Expand Down Expand Up @@ -380,7 +379,7 @@ impl Database {

#[cfg(feature = "sync")]
/// Push WAL frames to remote.
pub async fn push(&self) -> Result<Replicated> {
pub async fn push(&self) -> Result<crate::database::Replicated> {
let sync_ctx = self.sync_ctx.as_ref().unwrap();
let conn = self.connect()?;

Expand All @@ -403,7 +402,7 @@ impl Database {
}

let frame_count = end_frame_no - start_frame_no + 1;
Ok(Replicated{
Ok(crate::database::Replicated{
frame_no: None,
frames_synced: frame_count as usize,
})
Expand Down
10 changes: 10 additions & 0 deletions libsql/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ macro_rules! cfg_sync {
}
}

macro_rules! cfg_replication_or_sync {
($($item:item)*) => {
$(
#[cfg(any(feature = "replication", feature = "sync"))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "replication", feature = "sync"))))]
$item
)*
}
}

macro_rules! cfg_parser {
($($item:item)*) => {
$(
Expand Down

0 comments on commit 436679d

Please sign in to comment.