pub struct CursorStore { /* private fields */ }Expand description
Persistent cursor storage backed by SQLite.
Supports debounced writes: updates go to cache immediately,
and are flushed to disk periodically via flush_dirty().
Implementations§
Source§impl CursorStore
impl CursorStore
Sourcepub async fn new(path: impl AsRef<Path>) -> Result<Self>
pub async fn new(path: impl AsRef<Path>) -> Result<Self>
Create a new cursor store at the given path.
Creates the database and tables if they don’t exist.
Sourcepub async fn get(&self, peer_id: &str) -> Option<String>
pub async fn get(&self, peer_id: &str) -> Option<String>
Get the cursor for a peer (from cache).
Returns None if no cursor exists (first sync with this peer).
Sourcepub async fn get_or_start(&self, peer_id: &str) -> String
pub async fn get_or_start(&self, peer_id: &str) -> String
Get the cursor, or return “0” for first-time sync.
Redis XREAD interprets “0” as “from the beginning”.
Sourcepub async fn set(&self, peer_id: &str, stream_id: &str)
pub async fn set(&self, peer_id: &str, stream_id: &str)
Update the cursor for a peer (debounced).
Updates cache immediately, marks cursor as dirty.
Call flush_dirty() periodically to persist to disk.
This is the preferred method for hot path updates where we want to minimize SQLite writes.
Sourcepub async fn flush_dirty(&self) -> Result<usize>
pub async fn flush_dirty(&self) -> Result<usize>
Flush all dirty cursors to disk.
Call this periodically (e.g., every 5 seconds) and on shutdown. Returns the number of cursors flushed.
Sourcepub async fn dirty_count(&self) -> usize
pub async fn dirty_count(&self) -> usize
Get count of dirty cursors pending flush.
Sourcepub async fn delete(&self, peer_id: &str) -> Result<()>
pub async fn delete(&self, peer_id: &str) -> Result<()>
Delete cursor for a peer (e.g., when peer is removed from mesh). Retries on SQLITE_BUSY/SQLITE_LOCKED with exponential backoff.
Sourcepub async fn get_all(&self) -> HashMap<String, String>
pub async fn get_all(&self) -> HashMap<String, String>
Get all cursors (for metrics/debugging).
Sourcepub async fn checkpoint(&self) -> Result<()>
pub async fn checkpoint(&self) -> Result<()>
Force flush WAL to main database (for clean shutdown). Retries on SQLITE_BUSY/SQLITE_LOCKED with exponential backoff.
Auto Trait Implementations§
impl Freeze for CursorStore
impl !RefUnwindSafe for CursorStore
impl Send for CursorStore
impl Sync for CursorStore
impl Unpin for CursorStore
impl !UnwindSafe for CursorStore
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more