Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use iterator_refresh backend option for some folds #852

Merged
merged 1 commit into from
Feb 21, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/riak_kv_eleveldb_backend.erl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
-endif.

-define(API_VERSION, 1).
-define(CAPABILITIES, [async_fold, indexes, index_reformat, size]).
-define(CAPABILITIES, [async_fold, indexes, index_reformat, size,
iterator_refresh]).
-define(FIXED_INDEXES_KEY, fixed_indexes).

-record(state, {ref :: reference(),
Expand Down Expand Up @@ -466,9 +467,15 @@ fold_objects(FoldObjectsFun, Acc, Opts, #state{fold_opts=FoldOpts,
true -> undefined
end,

IteratorRefresh =
case lists:keyfind(iterator_refresh, 1, Opts) of
false -> [];
Tuple -> [Tuple]
end,

%% Set up the fold...
FirstKey = to_first_key(Limiter),
FoldOpts1 = [{first_key, FirstKey} | FoldOpts],
FoldOpts1 = IteratorRefresh ++ [{first_key, FirstKey} | FoldOpts],
FoldFun = fold_objects_fun(FoldObjectsFun, Limiter),

ObjectFolder =
Expand Down
5 changes: 4 additions & 1 deletion src/riak_kv_index_hashtree.erl
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,11 @@ hash_index_data(IndexData) when is_list(IndexData) ->
-spec fold_keys(index(), pid(), boolean()) -> ok.
fold_keys(Partition, Tree, HasIndexTree) ->
FoldFun = fold_fun(Tree, HasIndexTree),
Refresh = app_helper:get_env(riak_kv, iterator_refresh, true),
Req = riak_core_util:make_fold_req(FoldFun,
0, false, [aae_reconstruction]),
0, false,
[aae_reconstruction,
{iterator_refresh, Refresh}]),
riak_core_vnode_master:sync_command({Partition, node()},
Req,
riak_kv_vnode_master, infinity),
Expand Down
2 changes: 1 addition & 1 deletion src/riak_kv_multi_backend.erl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

-define(API_VERSION, 1).
-define(CAPABILITIES, [async_fold, index_reformat]).
-define(ANY_CAPABILITIES, [indexes]).
-define(ANY_CAPABILITIES, [indexes, iterator_refresh]).

-record (state, {backends :: [{atom(), atom(), term()}],
default_backend :: atom()}).
Expand Down
44 changes: 34 additions & 10 deletions src/riak_kv_vnode.erl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
readrepair/6,
list_keys/4,
fold/3,
fold/4,
get_vclocks/2,
vnode_status/1,
ack_keys/1,
Expand Down Expand Up @@ -305,6 +306,12 @@ fold(Preflist, Fun, Acc0) ->
Req,
riak_kv_vnode_master).

fold(Preflist, Fun, Acc0, Options) ->
Req = riak_core_util:make_fold_req(Fun, Acc0, false, Options),
riak_core_vnode_master:sync_spawn_command(Preflist,
Req,
riak_kv_vnode_master).

get_vclocks(Preflist, BKeyList) ->
riak_core_vnode_master:sync_spawn_command(Preflist,
?KV_VCLOCK_REQ{bkeys=BKeyList},
Expand Down Expand Up @@ -926,10 +933,13 @@ handoff_starting({_HOType, TargetNode}=_X, State) ->
end.

%% @doc Optional callback that is exported, but not part of the behaviour.
handoff_started({SrcPartition, _SrcNode}, WorkerPid) ->
handoff_started(SrcPartition, WorkerPid) ->
case maybe_get_vnode_lock(SrcPartition, WorkerPid) of
ok -> true;
Error -> Error
ok ->
Refresh = app_helper:get_env(riak_kv, iterator_refresh, true),
FoldOpts = [{iterator_refresh, Refresh}],
{ok, FoldOpts};
max_concurrency -> {error, max_concurrency}
end.

handoff_cancelled(State) ->
Expand Down Expand Up @@ -1714,13 +1724,8 @@ do_fold(Fun, Acc0, Sender, ReqOpts, State=#state{async_folding=AsyncFolding,
mod=Mod,
modstate=ModState}) ->
{ok, Capabilities} = Mod:capabilities(ModState),
AsyncBackend = lists:member(async_fold, Capabilities),
case AsyncFolding andalso AsyncBackend of
true ->
Opts = [async_fold|ReqOpts];
false ->
Opts = ReqOpts
end,
Opts0 = maybe_enable_async_fold(AsyncFolding, Capabilities, ReqOpts),
Opts = maybe_enable_iterator_refresh(Capabilities, Opts0),
case Mod:fold_objects(Fun, Acc0, Opts, ModState) of
{ok, Acc} ->
{reply, Acc, State};
Expand All @@ -1734,6 +1739,25 @@ do_fold(Fun, Acc0, Sender, ReqOpts, State=#state{async_folding=AsyncFolding,
{reply, ER, State}
end.

%% @private
maybe_enable_async_fold(AsyncFolding, Capabilities, Opts) ->
AsyncBackend = lists:member(async_fold, Capabilities),
case AsyncFolding andalso AsyncBackend of
true ->
[async_fold|Opts];
false ->
Opts
end.

%% @private
maybe_enable_iterator_refresh(Capabilities, Opts) ->
case lists:member(iterator_refresh, Capabilities) of
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fwiw, we could have dumped the config check in here instead of in two places but meh

true ->
Opts;
false ->
lists:keydelete(iterator_refresh, 1, Opts)
end.

%% @private
do_get_vclocks(KeyList,_State=#state{mod=Mod,modstate=ModState}) ->
[{BKey, do_get_vclock(BKey,Mod,ModState)} || BKey <- KeyList].
Expand Down