Skip to main content

Indexer

Struct Indexer 

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

Owning handle over a SQLite connection to a logdive index.

Implementations§

Source§

impl Indexer

Source

pub fn open(path: &Path) -> Result<Self>

Open (or create) a logdive index at path.

Creates the parent directory if it does not already exist, opens the SQLite database, and runs idempotent schema migrations.

Source

pub fn open_in_memory() -> Result<Self>

Open an in-memory index. Used by tests; also usable for one-shot scenarios that don’t need persistence.

Source

pub fn open_read_only(path: &Path) -> Result<Self>

Open an existing logdive index at path in read-only mode.

Unlike Indexer::open, this method:

  1. Does not create the database file if it is missing (the SQLITE_OPEN_READ_ONLY flag fails rather than creates),
  2. Does not create the parent directory,
  3. Does not run schema migrations — the caller is promising that path already points at a valid logdive index.

Enforcement of read-only semantics is at the SQLite level: any attempted write through the returned connection raises a runtime error. This is defense-in-depth for the HTTP API (milestone 8), whose surface is exclusively read.

Source

pub fn connection(&self) -> &Connection

Borrow the underlying connection.

Exposed so the query executor can run reads without an extra abstraction layer. Read-only borrow keeps ingestion and querying from contending over &mut.

Source

pub fn insert_batch(&mut self, entries: &[LogEntry]) -> Result<InsertStats>

Insert a slice of entries into the index, chunking internally into transactions of BATCH_SIZE rows each.

Returns aggregate stats across all chunks. Entry ordering within the index is not guaranteed.

Source

pub fn prune(&mut self, cutoff: &str) -> Result<PruneStats>

Delete every entry whose timestamp is strictly older than cutoff, then VACUUM to reclaim the freed disk space.

cutoff is compared lexically against the stored timestamp TEXT column. This is correct for ISO-8601 / RFC3339 timestamps, which sort chronologically as text — the same comparison contract the query executor’s last / since clauses rely on. A non-ISO-shaped cutoff (or non-ISO timestamps in the index) will compare incorrectly, the same known limitation that applies to time-range queries.

The comparison is strict <: a row whose timestamp exactly equals cutoff is kept, not deleted.

Returns the number of rows deleted in PruneStats::deleted.

§VACUUM and transactions

SQLite refuses to run VACUUM inside an explicit transaction, so this method issues the DELETE and the VACUUM as two separate autocommit statements rather than wrapping them in conn.transaction(). The DELETE is a single statement and therefore atomic on its own; a crash between the two would leave the rows deleted but the file not yet compacted — harmless, since any later VACUUM reclaims the space.

Source

pub fn stats(&self) -> Result<Stats>

Read aggregate metadata about the index.

Runs three read-only queries:

  1. COUNT(*) for the row count,
  2. MIN(timestamp), MAX(timestamp) for the time range,
  3. SELECT DISTINCT tag ... ORDER BY tag for the tag list.

On an empty database, returns entries = 0, both timestamp bounds as None, and an empty tags vector — not an error.

Trait Implementations§

Source§

impl Debug for Indexer

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, 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 = Infallible

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.