Add object_spec type

Initial refactor to prepare to allow for a new version object_spec type that will support LMD being promoted as an accessible item.
This commit is contained in:
Martin Sumner 2018-11-01 10:41:46 +00:00
parent 376407fa66
commit f77dc8c3a5
2 changed files with 34 additions and 17 deletions

View file

@ -185,9 +185,7 @@
-type fold_timings() :: no_timing|#fold_timings{}. -type fold_timings() :: no_timing|#fold_timings{}.
-type head_timings() :: no_timing|#head_timings{}. -type head_timings() :: no_timing|#head_timings{}.
-type timing_types() :: head|get|put|fold. -type timing_types() :: head|get|put|fold.
-type key() :: binary()|string()|{binary(), binary()}.
% Keys SHOULD be binary()
% string() support is a legacy of old tests
-type open_options() :: -type open_options() ::
%% For full description of options see ../docs/STARTUP_OPTIONS.md %% For full description of options see ../docs/STARTUP_OPTIONS.md
[{root_path, string()|undefined} | [{root_path, string()|undefined} |
@ -302,7 +300,6 @@
% Defaults to ?COMPRESSION_POINT % Defaults to ?COMPRESSION_POINT
]. ].
-export_type([key/0]).
%%%============================================================================ %%%============================================================================
@ -363,7 +360,7 @@ book_plainstart(Opts) ->
gen_server:start(?MODULE, [set_defaults(Opts)], []). gen_server:start(?MODULE, [set_defaults(Opts)], []).
-spec book_tempput(pid(), key(), key(), any(), -spec book_tempput(pid(), leveled_codec:key(), leveled_codec:key(), any(),
leveled_codec:index_specs(), leveled_codec:index_specs(),
leveled_codec:tag(), integer()) -> ok|pause. leveled_codec:tag(), integer()) -> ok|pause.
@ -430,7 +427,7 @@ book_put(Pid, Bucket, Key, Object, IndexSpecs) ->
book_put(Pid, Bucket, Key, Object, IndexSpecs, Tag) -> book_put(Pid, Bucket, Key, Object, IndexSpecs, Tag) ->
book_put(Pid, Bucket, Key, Object, IndexSpecs, Tag, infinity). book_put(Pid, Bucket, Key, Object, IndexSpecs, Tag, infinity).
-spec book_put(pid(), key(), key(), any(), -spec book_put(pid(), leveled_codec:key(), leveled_codec:key(), any(),
leveled_codec:index_specs(), leveled_codec:index_specs(),
leveled_codec:tag(), infinity|integer()) -> ok|pause. leveled_codec:tag(), infinity|integer()) -> ok|pause.
@ -440,7 +437,7 @@ book_put(Pid, Bucket, Key, Object, IndexSpecs, Tag, TTL) ->
infinity). infinity).
-spec book_mput(pid(), list(tuple())) -> ok|pause. -spec book_mput(pid(), list(leveled_codec:object_spec())) -> ok|pause.
%% @doc %% @doc
%% %%
%% When the store is being run in head_only mode, batches of object specs may %% When the store is being run in head_only mode, batches of object specs may
@ -453,7 +450,8 @@ book_put(Pid, Bucket, Key, Object, IndexSpecs, Tag, TTL) ->
book_mput(Pid, ObjectSpecs) -> book_mput(Pid, ObjectSpecs) ->
book_mput(Pid, ObjectSpecs, infinity). book_mput(Pid, ObjectSpecs, infinity).
-spec book_mput(pid(), list(tuple()), infinity|integer()) -> ok|pause. -spec book_mput(pid(), list(leveled_codec:object_spec()), infinity|integer())
-> ok|pause.
%% @doc %% @doc
%% %%
%% When the store is being run in head_only mode, batches of object specs may %% When the store is being run in head_only mode, batches of object specs may
@ -466,8 +464,9 @@ book_mput(Pid, ObjectSpecs) ->
book_mput(Pid, ObjectSpecs, TTL) -> book_mput(Pid, ObjectSpecs, TTL) ->
gen_server:call(Pid, {mput, ObjectSpecs, TTL}, infinity). gen_server:call(Pid, {mput, ObjectSpecs, TTL}, infinity).
-spec book_delete(pid(), key(), key(), leveled_codec:index_specs()) -spec book_delete(pid(),
-> ok|pause. leveled_codec:key(), leveled_codec:key(),
leveled_codec:index_specs()) -> ok|pause.
%% @doc %% @doc
%% %%
@ -478,11 +477,15 @@ book_delete(Pid, Bucket, Key, IndexSpecs) ->
book_put(Pid, Bucket, Key, delete, IndexSpecs, ?STD_TAG). book_put(Pid, Bucket, Key, delete, IndexSpecs, ?STD_TAG).
-spec book_get(pid(), key(), key(), leveled_codec:tag()) -spec book_get(pid(),
leveled_codec:key(), leveled_codec:key(), leveled_codec:tag())
-> {ok, any()}|not_found. -> {ok, any()}|not_found.
-spec book_head(pid(), key(), key(), leveled_codec:tag()) -spec book_head(pid(),
leveled_codec:key(), leveled_codec:key(), leveled_codec:tag())
-> {ok, any()}|not_found.
-spec book_headonly(pid(),
leveled_codec:key(), leveled_codec:key(), leveled_codec:key())
-> {ok, any()}|not_found. -> {ok, any()}|not_found.
-spec book_headonly(pid(), key(), key(), key()) -> {ok, any()}|not_found.
%% @doc - GET and HEAD requests %% @doc - GET and HEAD requests
%% %%

View file

@ -81,6 +81,10 @@
-type tag() :: -type tag() ::
?STD_TAG|?RIAK_TAG|?IDX_TAG|?HEAD_TAG. ?STD_TAG|?RIAK_TAG|?IDX_TAG|?HEAD_TAG.
-type key() ::
binary()|string()|{binary(), binary()}.
% Keys SHOULD be binary()
% string() support is a legacy of old tests
-type sqn() :: -type sqn() ::
% SQN of the object in the Journal % SQN of the object in the Journal
pos_integer(). pos_integer().
@ -114,6 +118,10 @@
?INKT_STND|?INKT_TOMB|?INKT_MPUT|?INKT_KEYD. ?INKT_STND|?INKT_TOMB|?INKT_MPUT|?INKT_KEYD.
-type journal_key() :: -type journal_key() ::
{integer(), journal_key_tag(), ledger_key()}. {integer(), journal_key_tag(), ledger_key()}.
-type object_spec_v0() ::
{add|remove, key(), key(), key()|null, any()}.
-type object_spec() ::
object_spec_v0().
-type compression_method() :: -type compression_method() ::
lz4|native. lz4|native.
-type index_specs() :: -type index_specs() ::
@ -128,6 +136,8 @@
:: list(integer())|false. :: list(integer())|false.
-export_type([tag/0, -export_type([tag/0,
key/0,
object_spec/0,
segment_hash/0, segment_hash/0,
ledger_status/0, ledger_status/0,
ledger_key/0, ledger_key/0,
@ -550,9 +560,7 @@ hash(Obj) ->
%% @doc %% @doc
%% Convert object specs to KV entries ready for the ledger %% Convert object specs to KV entries ready for the ledger
obj_objectspecs(ObjectSpecs, SQN, TTL) -> obj_objectspecs(ObjectSpecs, SQN, TTL) ->
lists:map(fun({IdxOp, Bucket, Key, SubKey, Value}) -> lists:map(fun(ObjectSpec) -> gen_headspec(ObjectSpec, SQN, TTL) end,
gen_headspec(Bucket, Key, IdxOp, SubKey, Value, SQN, TTL)
end,
ObjectSpecs). ObjectSpecs).
-spec idx_indexspecs(index_specs(), -spec idx_indexspecs(index_specs(),
@ -573,7 +581,13 @@ gen_indexspec(Bucket, Key, IdxOp, IdxField, IdxTerm, SQN, TTL) ->
{to_ledgerkey(Bucket, Key, ?IDX_TAG, IdxField, IdxTerm), {to_ledgerkey(Bucket, Key, ?IDX_TAG, IdxField, IdxTerm),
{SQN, Status, no_lookup, null}}. {SQN, Status, no_lookup, null}}.
gen_headspec(Bucket, Key, IdxOp, SubKey, Value, SQN, TTL) -> -spec gen_headspec(object_spec(), integer(), integer()|infinity) -> ledger_kv().
%% @doc
%% Take an object_spec as passed in a book_mput, and convert it into to a
%% valid ledger key and value. Supports different shaped tuples for different
%% versions of the object_spec
gen_headspec({IdxOp, Bucket, Key, SubKey, Value}, SQN, TTL) ->
% v0 object spec
Status = set_status(IdxOp, TTL), Status = set_status(IdxOp, TTL),
K = to_ledgerkey(Bucket, {Key, SubKey}, ?HEAD_TAG), K = to_ledgerkey(Bucket, {Key, SubKey}, ?HEAD_TAG),
{K, {SQN, Status, segment_hash(K), Value}}. {K, {SQN, Status, segment_hash(K), Value}}.