Electric.ShapeCache.ShapeStatus (electric v1.0.23)

View Source

Keeps track of shape state.

Can recover basic persisted shape metadata from shape storage to repopulate the in-memory cache.

The shape cache then loads this and starts processes (storage and consumer) for each {shape_handle, %Shape{}} pair. These then use their attached storage to recover the status information for the shape (snapshot xmin and latest offset).

The ETS metadata table name is part of the config because we need to be able to access the data in the ETS from anywhere, so there's an internal api, using the full state and an external api using just the table name.

Summary

Types

option()

@type option() ::
  {:shape_meta_table, atom() | reference()}
  | {:storage, {module(), [term()]}}
  | {:root, binary()}

options()

@type options() :: [option()]

shape_handle()

@type shape_handle() :: Electric.ShapeCacheBehaviour.shape_handle()

t()

@type t() :: %Electric.ShapeCache.ShapeStatus{
  root: String.t(),
  shape_meta_table: table(),
  storage: Electric.ShapeCache.Storage.storage()
}

table()

@type table() :: atom() | reference()

xmin()

@type xmin() :: Electric.ShapeCacheBehaviour.xmin()

Functions

latest_offset(state, shape_handle)

latest_offset!(state, shape_handle)

least_recently_used(meta_table, shape_count)

list_shape_handles_for_relations(state, relations)

@spec list_shape_handles_for_relations(t(), [Electric.oid_relation()]) :: [
  shape_handle()
]

snapshot_xmin(state, shape_handle)

update_last_read_time_to_now(meta_table, shape_handle)