barrel_path_dict (barrel_docdb v1.0.0)

View Source

Path ID Interning for barrel_docdb

Maps JSON paths to compact 32-bit integer IDs for efficient posting list keys. Uses ETS for read cache and RocksDB for persistence.

Path format: [<<"field1">>, <<"field2">>] to PathId (32-bit integer)

Summary

Functions

Clear cache entries for a database. Called when a database is closed or deleted.

Get path ID from cache only (no creation). Returns not_found if path is not in cache.

Get or create a path ID for the given path. If the path doesn't have an ID yet, creates one and persists it.

Get path from cache by ID. Returns undefined if ID is not in cache.

Load all path IDs from store into cache. Called when a database is opened.

Reset the path dictionary (for testing only).

Start the path dictionary server

Types

att_info/0

-type att_info() ::
          #{name := binary(),
            content_type := binary(),
            length := non_neg_integer(),
            digest := binary(),
            chunked => boolean(),
            chunk_size => pos_integer(),
            chunk_count => pos_integer()}.

change/0

-type change() :: map().

db_config/0

-type db_config() :: #{path => string(), store => module(), atom() => term()}.

db_name/0

-type db_name() :: binary().

db_ref/0

-type db_ref() :: pid() | atom().

doc/0

-type doc() :: #{binary() => term()}.

doc_info/0

-type doc_info() :: #{id := docid(), rev := revid(), deleted := boolean(), revtree := revtree()}.

docid/0

-type docid() :: binary().

endpoint/0

-type endpoint() :: db_name() | {node(), db_name()} | {module(), term()}.

path/0

-type path() :: [binary() | term()].

path_id/0

-type path_id() :: non_neg_integer().

rep_options/0

-type rep_options() ::
          #{continuous => boolean(),
            since => seq_string(),
            filter => fun((doc()) -> boolean()),
            atom() => term()}.

rev_info/0

-type rev_info() ::
          #{id := revid(),
            parent := revid() | undefined,
            deleted := boolean(),
            attachments => #{binary() => att_info()}}.

revid/0

-type revid() :: binary().

revtree/0

-type revtree() :: #{revid() => rev_info()}.

seq/0

-type seq() :: barrel_hlc:timestamp().

seq_string/0

-type seq_string() :: binary().

view_name/0

-type view_name() :: binary().

view_result/0

-type view_result() :: #{key := term(), value := term(), id := docid()}.

Functions

clear_cache(DbName)

-spec clear_cache(db_name()) -> ok.

Clear cache entries for a database. Called when a database is closed or deleted.

code_change(OldVsn, State, Extra)

get_id(DbName, Path)

-spec get_id(db_name(), path()) -> {ok, path_id()} | not_found.

Get path ID from cache only (no creation). Returns not_found if path is not in cache.

get_or_create_id(StoreRef, DbName, Path)

-spec get_or_create_id(barrel_store_rocksdb:db_ref(), db_name(), path()) -> path_id().

Get or create a path ID for the given path. If the path doesn't have an ID yet, creates one and persists it.

get_path(StoreRef, DbName, PathId)

-spec get_path(barrel_store_rocksdb:db_ref(), db_name(), path_id()) -> path() | undefined.

Get path from cache by ID. Returns undefined if ID is not in cache.

handle_call(Request, From, State)

handle_cast(Msg, State)

handle_info(Info, State)

init(_)

load_from_store(StoreRef, DbName)

-spec load_from_store(barrel_store_rocksdb:db_ref(), db_name()) -> ok.

Load all path IDs from store into cache. Called when a database is opened.

reset()

-spec reset() -> ok.

Reset the path dictionary (for testing only).

start_link()

-spec start_link() -> {ok, pid()} | {error, term()}.

Start the path dictionary server

terminate(Reason, State)