Replies: 0 comments 4 replies
-
|
I think this is definitely the way to go, though I'd normalize and generalize the callbacks. One possible approach follows, with some pattern changes. Result PatternsI've changed all functions to return one of:
ContextI've generalized the Additionally, I've defined the result of Question: Module FlexibilityI've added the object being operated upon to the If a module only ever returns one (constant) result from these operations, it can simply ignore the parameter. %% @doc Riak KV Merge Strategy Behavior.
%%
%% === Result patterns ===
%%
%% {ok, Result :: term()}
%% atom()
%% {error, Reason :: term()}
%%
%% === Extra Information ===
%%
%% The {@link context()} type is used to convey contextual information across
%% callbacks in a form understood by the callback module implementation.
%% The calling process passes this information uninterpretted.
%%
%% The {@link context_obj()} tagged tupple provides an unambiguous pattern
%% for matching a {@link intermediary()} (likely a {@link riak_obj()}) bundled
%% with an opaque {@link context()}.
%%
%% The callback module's `process_update/2', `assign_dot/1', and
%% `reconcile_strategy/1' functions MUST all handle ANY {@link subject_obj()}
%% returned from `handle_put_request_body/2' appropriately.
%%
-module(riak_kv_merge_strategy).
-export_type([
context/0,
context_obj/0,
merge_opt/0,
strategy/0
]).
-type context() :: term(). % Effectively opaque.
-type merge_opt() :: term(). % Allow for structured data.
-type strategy() :: most_recent | merge.
-type simple_obj() :: riak_obj().
-type context_obj() :: {ctx, intermediary(), context()}.
-type intermediary() :: term(). % Likely riak_obj(), but not explicit
-type subject_obj() :: simple_obj() | context_obj().
-type obj_content() :: riak_object:r_content().
-type obj_value() :: riak_object:value().
-type riak_obj() :: riak_object:riak_object().
-type vnode_id() :: riak_kv_vnode:vnode_id().
-callback handle_get_response_body(
Object :: riak_obj(), MergeOption :: merge_opt() ) ->
{ok, Result :: riak_obj()} | {error, Reason :: term()}.
-callback handle_put_request_body(
Object :: riak_obj(), Value :: obj_value() ) ->
{ok, Result :: subject_obj()} | {error, Reason :: term()}.
-callback merge_content(
ObjContL :: obj_content(), ObjContR :: obj_content() ) ->
{ok, Result :: obj_content()} | {error, Reason :: term()}.
-callback process_update(
Object :: subject_obj(), VNodeID :: vnode_id() ) ->
{ok, Result :: riak_obj()} | {error, Reason :: term()}.
-callback assign_dot(Object :: subject_obj() ) -> boolean().
-callback reconcile_strategy(Object :: subject_obj() ) -> strategy(). |
Beta Was this translation helpful? Give feedback.
-
|
I really like this approach @martinsumner ! 👏🏼 |
Beta Was this translation helpful? Give feedback.
-
|
it would be ideal to pair this at the client side with a corresponding behaviour, so extending Riak with types would imply developing an implementation of |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Discussion of the MergeStrategyBehaviour.md document.
Beta Was this translation helpful? Give feedback.
All reactions