Skip to content

Commit

Permalink
yokozuna now module implements riak_kv_update_hook behavior and misc …
Browse files Browse the repository at this point in the history
…name changes, per PR comments.

Cf., riak_kv commit 32bcff513d92e228facd471cc2313a2623b1269d
  • Loading branch information
fadushin committed Dec 22, 2016
1 parent e3d3c76 commit b715906
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 18 deletions.
5 changes: 3 additions & 2 deletions priv/yokozuna.schema
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,9 @@
hidden
]}.

%% @doc Add yokozuna to the riak_kv index modules
{mapping, "search.index_module", "riak_kv.index_module", [
%% @doc Set the riak_kv update hook to be the yokozuna module, which
%% implements the `riak_kv_update_hook` behavior
{mapping, "search.update_hook", "riak_kv.update_hook", [
{datatype, atom},
{default, yokozuna},
hidden
Expand Down
55 changes: 40 additions & 15 deletions src/yokozuna.erl
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,55 @@

-type fold_fun() :: fun(([term()], Acc::term()) -> Acc::term()).

-behaviour(riak_kv_update_hook).

%% riak_kv_update_hook behaviors
-export([
update/3,
update_binary/5,
requires_existing_object/1,
should_handoff/1
]).

%%%===================================================================
%%% API
%% riak_kv_update_hook behavior
%%%===================================================================

%% @doc Index a Riak object, given a reason and partition under which
%% the object is being indexed. The object pair contains the new
%% and old objects, in the case where a read-before-write resulted
%% in an old object we can use to delete siblings before updating.
-spec index(object_pair(), write_reason(), p()) -> ok.
index(RObjPair, Reason, Idx) ->
%% @doc see riak_kv_update_hook:update/3
-spec update(
riak_kv_update_hook:object_pair(),
riak_kv_update_hook:update_reason(),
riak_kv_update_hook:partition()
) -> ok.
update(RObjPair, Reason, Idx) ->
yz_kv:index(RObjPair, Reason, Idx).

%% @doc Index a Riak object encoded as a n erlang binary. This function
%% is typically called from the write-once path, where there is no
%% old object to
-spec index_binary(bucket(), key(), binary(), write_reason(), p()) -> ok.
index_binary(Bucket, Key, Bin, Reason, P) ->
%% @doc see riak_kv_update_hook:update_binary/5
-spec update_binary(
riak_core_bucket:bucket(),
riak_object:key(),
binary(),
riak_kv_update_hook:update_reason(),
riak_kv_update_hook:partition()
) -> ok.
update_binary(Bucket, Key, Bin, Reason, P) ->
yz_kv:index_binary(Bucket, Key, Bin, Reason, P).

%% @doc Determine whether a bucket is searchable, based on its properties.
-spec is_searchable(riak_kv_bucket:props()) -> boolean().
is_searchable(BProps) ->
%% @doc see riak_kv_update_hook:requires_existing_object/1
-spec requires_existing_object(riak_kv_bucket:props()) -> boolean().
requires_existing_object(BProps) ->
yz_kv:is_search_enabled_for_bucket(BProps).

%% @doc see riak_kv_update_hook:should_handoff/1
-spec should_handoff(riak_kv_update_hook:handoff_dest()) -> boolean().
should_handoff(HandoffSpec) ->
yz_kv:should_handoff(HandoffSpec).


%%%===================================================================
%%% API
%%%===================================================================

%% @doc Disable the given `Component'. The main reason for disabling
%% a component is to help in diagnosing issues in a live,
%% production environment. E.g. the `search' component may be
Expand Down
2 changes: 1 addition & 1 deletion test/yokozuna_schema_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ basic_schema_test() ->
cuttlefish_unit:assert_config(Config, "yokozuna.aae_throttle_enabled", true),
cuttlefish_unit:assert_not_configured(Config, "yokozuna.aae_throttle_limits"),
cuttlefish_unit:assert_config(Config, "yokozuna.enable_dist_query", true),
cuttlefish_unit:assert_config(Config, "riak_kv.index_module", yokozuna),
cuttlefish_unit:assert_config(Config, "riak_kv.update_hook", yokozuna),
ok.

override_schema_test() ->
Expand Down

0 comments on commit b715906

Please sign in to comment.