Skip to content

Commit d77e019

Browse files
committed
add docs and clean up
1 parent 1dd2cc9 commit d77e019

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

libsql/src/local/database.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ impl Database {
261261
/// Perform a sync step, returning the new replication index, or None, if the nothing was
262262
/// replicated yet
263263
pub async fn sync_oneshot(&self) -> Result<crate::replication::Replicated> {
264-
if let Some(ref ctx) = self.replication_ctx {
264+
if let Some(ctx) = &self.replication_ctx {
265265
ctx.replicator.sync_oneshot().await
266266
} else {
267267
Err(crate::errors::Error::Misuse(

libsql/src/replication/mod.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Utilities used when using a replicated version of libsql.
22
33
use std::path::PathBuf;
4+
use std::sync::atomic::AtomicUsize;
45
use std::sync::Arc;
56
use std::time::Duration;
67

@@ -39,10 +40,16 @@ pub struct Replicated {
3940
}
4041

4142
impl Replicated {
43+
/// The currently synced frame number. This can be used to track
44+
/// where in the log you might be. Beware that this value can be reset to a lower value by the
45+
/// server in certain situations. Please use `frames_synced` if you want to track the amount of
46+
/// work a sync has done.
4247
pub fn frame_no(&self) -> Option<FrameNo> {
4348
self.frame_no
4449
}
4550

51+
/// The count of frames synced during this call of `sync`. A frame is a 4kB frame from the
52+
/// libsql write ahead log.
4653
pub fn frames_synced(&self) -> usize {
4754
self.frames_synced
4855
}
@@ -124,6 +131,7 @@ impl Writer {
124131
pub(crate) struct EmbeddedReplicator {
125132
replicator: Arc<Mutex<Replicator<Either<RemoteClient, LocalClient>>>>,
126133
bg_abort: Option<Arc<DropAbort>>,
134+
last_frames_synced: Arc<AtomicUsize>,
127135
}
128136

129137
impl From<libsql_replication::replicator::Error> for errors::Error {
@@ -153,6 +161,7 @@ impl EmbeddedReplicator {
153161
let mut replicator = Self {
154162
replicator,
155163
bg_abort: None,
164+
last_frames_synced: Arc::new(AtomicUsize::new(0)),
156165
};
157166

158167
if let Some(sync_duration) = perodic_sync {
@@ -196,6 +205,7 @@ impl EmbeddedReplicator {
196205
Ok(Self {
197206
replicator,
198207
bg_abort: None,
208+
last_frames_synced: Arc::new(AtomicUsize::new(0)),
199209
})
200210
}
201211

@@ -245,9 +255,13 @@ impl EmbeddedReplicator {
245255
}
246256
}
247257

258+
let last_frames_synced = self
259+
.last_frames_synced
260+
.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
261+
248262
let replicated = Replicated {
249263
frame_no: replicator.client_mut().committed_frame_no(),
250-
frames_synced: replicator.frames_synced(),
264+
frames_synced: replicator.frames_synced() - last_frames_synced,
251265
};
252266

253267
Ok(replicated)

0 commit comments

Comments
 (0)