barrel_att_backend behaviour (barrel_docdb v1.1.1)

View Source

Attachment storage backend behaviour.

An attachment backend stores document attachment bytes (and the small metadata needed to describe them) under a database/document/name key space. barrel_att_store_blob is the default backend (a RocksDB BlobDB instance). barrel_att_store is a thin dispatcher that selects a backend per database from att_opts.backend and routes calls to it, so additional backends (for example a local filesystem or an S3 object store) can be added without touching the document layer.

AttRef is the opaque handle returned by open/2; the dispatcher tags it with the backend module. Stream is the opaque streaming handle returned by put_stream/5 / get_stream/4 and embeds its att_ref.

Summary

Callbacks

abort_stream/1

-callback abort_stream(Stream :: map()) -> ok.

att_changes/4

(optional)
-callback att_changes(AttRef :: map(), DbName :: binary(), Since :: term(), Opts :: map()) ->
                         {ok, [map()], LastSeq :: term()} | {error, term()}.

att_floor/2

(optional)
-callback att_floor(AttRef :: map(), DbName :: binary()) -> term() | undefined.

checkpoint/2

(optional)
-callback checkpoint(AttRef :: map(), Path :: string()) -> ok | {error, term()}.

close/1

-callback close(AttRef :: map()) -> ok.

close_stream/1

-callback close_stream(Stream :: map()) -> ok.

delete/4

-callback delete(AttRef :: map(), DbName :: binary(), DocId :: binary(), AttName :: binary()) ->
                    ok | {error, term()}.

delete/5

(optional)
-callback delete(AttRef :: map(), DbName :: binary(), DocId :: binary(), AttName :: binary(), Opts :: map()) ->
                    ok | {error, term()}.

delete_all/3

-callback delete_all(AttRef :: map(), DbName :: binary(), DocId :: binary()) -> ok | {error, term()}.

finish_stream/1

-callback finish_stream(Stream :: map()) -> {ok, map()} | {error, term()}.

fold/5

-callback fold(AttRef :: map(), DbName :: binary(), DocId :: binary(), Fun :: fun(), Acc :: term()) ->
                  term().

get/4

-callback get(AttRef :: map(), DbName :: binary(), DocId :: binary(), AttName :: binary()) ->
                 {ok, binary()} | {error, term()}.

get_info/4

-callback get_info(AttRef :: map(), DbName :: binary(), DocId :: binary(), AttName :: binary()) ->
                      {ok, map()} | {error, term()}.

get_stream/4

-callback get_stream(AttRef :: map(), DbName :: binary(), DocId :: binary(), AttName :: binary()) ->
                        {ok, map()} | {error, term()}.

open/2

-callback open(Path :: string(), Options :: map()) -> {ok, AttRef :: map()} | {error, term()}.

put/5

-callback put(AttRef :: map(), DbName :: binary(), DocId :: binary(), AttName :: binary(), Data :: binary()) ->
                 {ok, Info :: map()} | {error, term()}.

put/6

-callback put(AttRef :: map(),
              DbName :: binary(),
              DocId :: binary(),
              AttName :: binary(),
              Data :: binary(),
              Opts :: map()) ->
                 {ok, Info :: map()} | {error, term()}.

put_stream/5

-callback put_stream(AttRef :: map(),
                     DbName :: binary(),
                     DocId :: binary(),
                     AttName :: binary(),
                     ContentType :: binary()) ->
                        {ok, map()} | {error, term()}.

put_stream/6

-callback put_stream(AttRef :: map(),
                     DbName :: binary(),
                     DocId :: binary(),
                     AttName :: binary(),
                     ContentType :: binary(),
                     Opts :: map()) ->
                        {ok, map()} | {error, term()}.

read_chunk/1

-callback read_chunk(Stream :: map()) -> {ok, binary(), map()} | eof | {error, term()}.

rebuild_feed/2

(optional)
-callback rebuild_feed(AttRef :: map(), DbName :: binary()) -> {ok, map()} | {error, term()}.

sweep_att_feed/3

(optional)
-callback sweep_att_feed(AttRef :: map(), DbName :: binary(), Cutoff :: term()) ->
                            {ok, map()} | {error, term()}.

write_chunk/2

-callback write_chunk(Stream :: map(), Data :: binary()) -> {ok, map()} | {error, term()}.