pub struct CompactionStore { /* private fields */ }Implementations§
Source§impl CompactionStore
impl CompactionStore
Sourcepub async fn open(db_path: &str) -> Result<Self>
pub async fn open(db_path: &str) -> Result<Self>
Open or create the SQLite file at db_path. The directory must
already exist (we don’t create it). Use :memory: for tests.
Sourcepub fn with_pool(pool: SqlitePool) -> Self
pub fn with_pool(pool: SqlitePool) -> Self
Wrap an externally-opened pool. Useful when sharing the same SQLite file as another store. Caller is responsible for migrate.
pub async fn migrate(&self) -> Result<()>
Sourcepub async fn insert(&self, row: &CompactionRow) -> Result<()>
pub async fn insert(&self, row: &CompactionRow) -> Result<()>
Append a successful compaction. Errors only on storage problems.
Sourcepub async fn latest(&self, session_id: Uuid) -> Result<Option<CompactionRow>>
pub async fn latest(&self, session_id: Uuid) -> Result<Option<CompactionRow>>
Most recent compaction for a session, if any.
Sourcepub async fn list_for_session(
&self,
session_id: Uuid,
limit: u32,
) -> Result<Vec<CompactionRow>>
pub async fn list_for_session( &self, session_id: Uuid, limit: u32, ) -> Result<Vec<CompactionRow>>
All compactions for a session, newest first, capped at limit.
Sourcepub async fn try_acquire_lock(
&self,
session_id: Uuid,
holder: &str,
ttl_seconds: u32,
) -> Result<bool>
pub async fn try_acquire_lock( &self, session_id: Uuid, holder: &str, ttl_seconds: u32, ) -> Result<bool>
Try to take the per-session compaction lock. Returns true
when acquired, false when another holder is active. Stale
locks (older than ttl_seconds) are evicted before the
acquire attempt so a crashed compactor doesn’t deadlock the
session forever.
holder is a free-form debug label ("pid:thread_id" works
well) recorded on the row to make orphan diagnosis easier.
Sourcepub async fn release_lock(&self, session_id: Uuid) -> Result<()>
pub async fn release_lock(&self, session_id: Uuid) -> Result<()>
Release a previously-held lock. Idempotent.
Sourcepub async fn cleanup_stale_locks(&self, ttl_seconds: u32) -> Result<u64>
pub async fn cleanup_stale_locks(&self, ttl_seconds: u32) -> Result<u64>
Sweep every lock older than ttl_seconds. Call from a
background task or on boot to clean up after crashed
processes. Returns the number of rows removed.
Auto Trait Implementations§
impl Freeze for CompactionStore
impl !RefUnwindSafe for CompactionStore
impl Send for CompactionStore
impl Sync for CompactionStore
impl Unpin for CompactionStore
impl UnsafeUnpin for CompactionStore
impl !UnwindSafe for CompactionStore
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