Skip to main content

DbWithTtl

Struct DbWithTtl 

Source
pub struct DbWithTtl { /* private fields */ }
Expand description

A Db wrapper that attaches a wall-clock TTL to every written value. Entries whose embedded timestamp is older than ttl_seconds read as None and are physically reclaimed at the next compaction.

ttl_seconds == 0 disables expiration entirely - the wrapper still appends the TTL suffix for format consistency, but the filter keeps every entry and reads never treat any value as expired.

Implementations§

Source§

impl DbWithTtl

Source

pub fn open<P: AsRef<Path>>( path: P, opts: Options, ttl_seconds: u64, ) -> Result<Self>

Open or create a TTL-enabled database at path. The caller’s opts are forwarded to Db::open with one override: the compaction filter slot is replaced with a TtlCompactionFilter bound to ttl_seconds. Any user-supplied filter is dropped and logged via tracing::warn.

Source

pub fn put(&self, key: &[u8], value: &[u8]) -> Result<()>

Write key → value with the current wall-clock timestamp appended. The in-memory value is the stamped form until a matching DbWithTtl::get strips it off.

Source

pub fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>>

Look up key. Returns Ok(None) if the key is absent or if its embedded timestamp has aged beyond ttl_seconds. The trailing TTL suffix is always stripped from the returned value.

Source

pub fn get_slice(&self, key: &[u8]) -> Result<Option<DbSlice>>

DbWithTtl::get without copying the value.

The TTL suffix is dropped by narrowing the view, so the result still borrows the bytes the database already owns. Same absence semantics as DbWithTtl::get: an expired entry, and a value with no decodable TTL suffix, both read as Ok(None).

Source

pub fn delete(&self, key: &[u8]) -> Result<()>

Delete key. Range deletes are delegated to the inner Db::delete - tombstones don’t carry timestamps.

Source

pub fn delete_range(&self, start: &[u8], end: &[u8]) -> Result<()>

Delete every key in [start, end). Same semantics as Db::delete_range; TTL has no effect on range tombstones.

Source

pub fn scan( &self, start: Option<&[u8]>, end: Option<&[u8]>, ) -> Result<Vec<(Vec<u8>, Vec<u8>)>>

Scan [start, end), returning (key, value) pairs where every value has its trailing TTL suffix stripped and every expired entry is omitted. Ordering matches Db::scan.

Source

pub fn write(&self, batch: WriteBatch) -> Result<()>

Apply a batch of point writes atomically. Each put in the batch gets its value stamped with the current timestamp; each delete is passed through unchanged.

The input batch’s original contents are consumed and the stamped/delegated version is applied.

Source

pub fn inner(&self) -> &Db

Borrow the underlying Db for APIs that DbWithTtl does not wrap (streaming iterator, snapshots, compact_range).

Values read through the inner Db still carry their trailing TTL suffix - callers are responsible for stripping it via strip_timestamp if they want the user payload.

Source

pub fn compact_range( &self, start: Option<&[u8]>, end: Option<&[u8]>, ) -> Result<()>

Synchronously compact every SSTable overlapping [start, end) down the tree. Expired entries are physically removed via the installed TtlCompactionFilter.

Source

pub fn close(&self) -> Result<()>

Flush to disk and shut down background threads.

Trait Implementations§

Source§

impl Debug for DbWithTtl

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more