Encoder/decoder for dgen_server mod_state.
Stores structured Erlang terms across FDB key-value pairs using a recursive encoding scheme. Three encoding types are supported:
- term (fallback) -
term_to_binary, chunked into 100KB values. - assigns map - map with all atom keys; each entry stored at a
separate FDB key using
atom_to_binary(Key)in the path. - component list - list of maps where every item has an atom
idkey with a binary value; each item stored separately, ordered by a fractional index embedded in the FDB key.
The encoding is applied recursively. For example, an assigns map whose value is a component list will nest both encodings in the key path.
Key structure
term: {BaseKey, <<"t">>, ChunkIndex}
map: {BaseKey, <<"m">>} (marker)
{BaseKey, <<"m">>, KeyBin, ...} (recursive)
list: {BaseKey, <<"l">>} (marker, holds Id => FracIndex map)
{BaseKey, <<"l">>, FracIndex, Id, ...} (recursive)
Summary
Functions
Clears all state keys under BaseKey.
Clears the term-encoded keys under BaseKey.
Reads mod_state from the backend at BaseKey.
Reads a term-encoded value at BaseKey.
Diff-based partial write. Compares OldModState and NewModState and
only writes changed keys. Falls back to a full rewrite when the encoding
type changes or both values are plain terms.
Returns the packed key for chunk 0 of a term-encoded payload at BaseKey.
Types
-type base_key() :: dgen_backend:tuple_key().
-type mod_state() :: term().
-type option() :: {versioned, boolean()}.
-type tenant() :: dgen_backend:tenant().
Functions
Clears all state keys under BaseKey.
Clears the term-encoded keys under BaseKey.
Removes all {BaseKey, <<"t">>, N} chunk keys. Used by the call/reply
protocol to clear chunked reply payloads.
Reads mod_state from the backend at BaseKey.
-spec get_version(tenant(), base_key()) -> {ok, dgen_backend:versionstamp()} | {error, not_found}.
Reads a term-encoded value at BaseKey.
Unlike get/2, this only reads the term encoding ({BaseKey, <<"t">>, N} keys)
and does not attempt to decode map or list encodings. Used by the call/reply
protocol to read chunked reply payloads.
Diff-based partial write. Compares OldModState and NewModState and
only writes changed keys. Falls back to a full rewrite when the encoding
type changes or both values are plain terms.
When OldModState is undefined, existing data is cleared first.
-spec term_first_key(dgen_backend:dir(), base_key()) -> dgen_backend:key().
Returns the packed key for chunk 0 of a term-encoded payload at BaseKey.
This is the key that is written first by write_term/3 and is suitable for
placing a watch on a term-encoded value.