reckon_db_archive_file (reckon_db v1.2.6)

View Source

File-based archive backend for reckon-db

Stores archived events as Erlang term files on the local filesystem. Archives are organized in directories by store and stream.

Directory structure:

  {base_dir}/
    {store_id}/
      {stream_id}/
        0-99.archive
        100-199.archive

Summary

Functions

Archive events to a file.

Delete an archive file.

Check if an archive exists.

Initialize the file archive backend.

List all archive keys for a stream.

Read events from an archive file.

Types

event/0

-type event() ::
          #event{event_id :: binary(),
                 event_type :: binary(),
                 stream_id :: binary(),
                 version :: non_neg_integer(),
                 data :: map() | binary(),
                 metadata :: map(),
                 tags :: [binary()] | undefined,
                 timestamp :: integer(),
                 epoch_us :: integer(),
                 data_content_type :: binary(),
                 metadata_content_type :: binary()}.

Functions

archive(State, ArchiveKey, Events)

-spec archive(#state{base_dir :: string()}, binary(), [event()]) ->
                 {ok, #state{base_dir :: string()}} | {error, term()}.

Archive events to a file.

delete(State, ArchiveKey)

-spec delete(#state{base_dir :: string()}, binary()) ->
                {ok, #state{base_dir :: string()}} | {error, term()}.

Delete an archive file.

exists(State, ArchiveKey)

-spec exists(#state{base_dir :: string()}, binary()) -> {boolean(), #state{base_dir :: string()}}.

Check if an archive exists.

init(Opts)

-spec init(map()) -> {ok, #state{base_dir :: string()}} | {error, term()}.

Initialize the file archive backend.

Options: - base_dir: Directory where archives are stored (required)

list(State, StoreId, StreamId)

-spec list(#state{base_dir :: string()}, atom(), binary()) ->
              {ok, [binary()], #state{base_dir :: string()}} | {error, term()}.

List all archive keys for a stream.

read(State, ArchiveKey)

-spec read(#state{base_dir :: string()}, binary()) ->
              {ok, [event()], #state{base_dir :: string()}} | {error, term()}.

Read events from an archive file.