aarondb/projection_index

projection_index — non-authoritative index lifecycle

Index state is a replayable projection of an ordered source. Queries are only available while the index is healthy; the source remains authoritative.

Types

pub type Error {
  InvalidSchemaVersion
  OffsetGap(expected: Int, received: Int)
  NotQueryable(Health)
}

Constructors

  • InvalidSchemaVersion
  • OffsetGap(expected: Int, received: Int)
  • NotQueryable(Health)
pub type Health {
  Building
  Rebuilding
  Queryable
  Degraded(reason: String)
  Failed(reason: String)
}

Constructors

  • Building
  • Rebuilding
  • Queryable
  • Degraded(reason: String)
  • Failed(reason: String)
pub type Index {
  Index(
    schema_version: Int,
    generation: Int,
    health: Health,
    last_applied_offset: Int,
    values: List(String),
  )
}

Constructors

  • Index(
      schema_version: Int,
      generation: Int,
      health: Health,
      last_applied_offset: Int,
      values: List(String),
    )

Values

pub fn apply(
  index: Index,
  offset: Int,
  value: String,
) -> Result(Index, Error)
pub fn begin_rebuild(
  index: Index,
  schema_version: Int,
) -> Result(Index, Error)

Marks the current projection unavailable while a separate generation is built.

pub fn degrade(index: Index, reason: String) -> Index
pub fn fail(index: Index, reason: String) -> Index
pub fn failure_reason(index: Index) -> option.Option(String)
pub fn new(schema_version: Int) -> Result(Index, Error)
pub fn query(index: Index) -> Result(List(String), Error)
pub fn swap(
  current: Index,
  replacement: Index,
  source_high_watermark: Int,
) -> Result(Index, Error)

The caller swaps only a fully caught-up replacement. This makes a partial rebuild unqueryable instead of returning silently incomplete answers.

Search Document