diff --git a/priv/yokozuna.schema b/priv/yokozuna.schema index 7b0502e0..c57c7e2f 100644 --- a/priv/yokozuna.schema +++ b/priv/yokozuna.schema @@ -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 diff --git a/src/yokozuna.erl b/src/yokozuna.erl index d09de75d..30cc92b4 100644 --- a/src/yokozuna.erl +++ b/src/yokozuna.erl @@ -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 diff --git a/test/yokozuna_schema_tests.erl b/test/yokozuna_schema_tests.erl index e97e953b..45025adc 100644 --- a/test/yokozuna_schema_tests.erl +++ b/test/yokozuna_schema_tests.erl @@ -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() ->