Permalink
Browse files

Reduce get_my_ring calls using chashbin/etc

  • Loading branch information...
1 parent 36653d2 commit cc35687fe3d0957a28674b04425b8e3c199c8765 @jtuple jtuple committed May 12, 2013
View
@@ -104,8 +104,7 @@ delete(ReqId,Bucket,Key,Options,Timeout,Client,ClientId,VClock) ->
end.
get_r_options(Bucket, Options) ->
- {ok, Ring} = riak_core_ring_manager:get_my_ring(),
- BucketProps = riak_core_bucket:get_bucket(Bucket, Ring),
+ BucketProps = riak_core_bucket:get_bucket(Bucket),
N = proplists:get_value(n_val,BucketProps),
%% specifying R/W AND RW together doesn't make sense, so check if R or W
%is defined first. If not, use RW or default.
@@ -139,8 +138,7 @@ get_r_options(Bucket, Options) ->
end.
get_w_options(Bucket, Options) ->
- {ok, Ring} = riak_core_ring_manager:get_my_ring(),
- BucketProps = riak_core_bucket:get_bucket(Bucket, Ring),
+ BucketProps = riak_core_bucket:get_bucket(Bucket),
N = proplists:get_value(n_val,BucketProps),
%% specifying R/W AND RW together doesn't make sense, so check if R or W
%is defined first. If not, use RW or default.
View
@@ -156,14 +156,12 @@ init({test, Args, StateProps}) ->
%% @private
prepare(timeout, StateData=#state{bkey=BKey={Bucket,_Key}}) ->
?DTRACE(?C_GET_FSM_PREPARE, [], ["prepare"]),
- {ok, Ring} = riak_core_ring_manager:get_my_ring(),
- BucketProps = riak_core_bucket:get_bucket(Bucket, Ring),
+ BucketProps = riak_core_bucket:get_bucket(Bucket),
DocIdx = riak_core_util:chash_key(BKey),
N = proplists:get_value(n_val,BucketProps),
StatTracked = proplists:get_value(stat_tracked, BucketProps, false),
UpNodes = riak_core_node_watcher:nodes(riak_kv),
- Preflist2 = riak_core_apl:get_apl_ann(DocIdx, N, Ring, UpNodes),
-
+ Preflist2 = riak_core_apl:get_apl_ann(DocIdx, N, UpNodes),
new_state_timeout(validate, StateData#state{starttime=riak_core_util:moment(),
n = N,
bucket_props=BucketProps,
@@ -239,13 +239,11 @@ handle_call({insert, Id, Key, Hash, Options}, _From, State) ->
State2 = do_insert(Id, Key, Hash, Options, State),
{reply, ok, State2};
handle_call({insert_object, BKey, RObj}, _From, State) ->
- {ok, Ring} = riak_core_ring_manager:get_my_ring(),
- IndexN = riak_kv_util:get_index_n(BKey, Ring),
+ IndexN = riak_kv_util:get_index_n(BKey),
State2 = do_insert(IndexN, term_to_binary(BKey), hash_object(BKey, RObj), [], State),
{reply, ok, State2};
handle_call({delete, BKey}, _From, State) ->
- {ok, Ring} = riak_core_ring_manager:get_my_ring(),
- IndexN = riak_kv_util:get_index_n(BKey, Ring),
+ IndexN = riak_kv_util:get_index_n(BKey),
State2 = do_delete(IndexN, term_to_binary(BKey), State),
{reply, ok, State2};
@@ -299,8 +297,7 @@ handle_cast(stop, State) ->
{stop, normal, State};
handle_cast({insert_object, BKey, RObj}, State) ->
- {ok, Ring} = riak_core_ring_manager:get_my_ring(),
- IndexN = riak_kv_util:get_index_n(BKey, Ring),
+ IndexN = riak_kv_util:get_index_n(BKey),
State2 = do_insert(IndexN, term_to_binary(BKey), hash_object(BKey, RObj), [], State),
{noreply, State2};
@@ -398,9 +395,8 @@ hash_object({Bucket, Key}, RObjBin) ->
%% key/hash pair will be ignored.
-spec fold_keys(index(), pid()) -> ok.
fold_keys(Partition, Tree) ->
- {ok, Ring} = riak_core_ring_manager:get_my_ring(),
Req = ?FOLD_REQ{foldfun=fun(BKey={Bucket,Key}, RObj, _) ->
- IndexN = riak_kv_util:get_index_n({Bucket, Key}, Ring),
+ IndexN = riak_kv_util:get_index_n({Bucket, Key}),
insert(IndexN, term_to_binary(BKey), hash_object(BKey, RObj),
Tree, [if_missing]),
ok
View
@@ -190,13 +190,12 @@ init({test, Args, StateProps}) ->
prepare(timeout, StateData0 = #state{from = From, robj = RObj,
bkey = BKey,
options = Options}) ->
- {ok,Ring} = riak_core_ring_manager:get_my_ring(),
- BucketProps = riak_core_bucket:get_bucket(riak_object:bucket(RObj), Ring),
+ BucketProps = riak_core_bucket:get_bucket(riak_object:bucket(RObj)),
DocIdx = riak_core_util:chash_key(BKey),
N = proplists:get_value(n_val,BucketProps),
StatTracked = proplists:get_value(stat_tracked, BucketProps, false),
UpNodes = riak_core_node_watcher:nodes(riak_kv),
- Preflist2 = riak_core_apl:get_apl_ann(DocIdx, N, Ring, UpNodes),
+ Preflist2 = riak_core_apl:get_apl_ann(DocIdx, N, UpNodes),
%% Check if this node is in the preference list so it can coordinate
LocalPL = [IndexNode || {{_Index, Node} = IndexNode, _Type} <- Preflist2,
Node == node()],
View
@@ -33,7 +33,7 @@
expand_rw_value/4,
normalize_rw_value/2,
make_request/2,
- get_index_n/2,
+ get_index_n/1,
preflist_siblings/1,
fix_incorrect_index_entries/1,
fix_incorrect_index_entries/0,
@@ -159,12 +159,13 @@ normalize_rw_value(_, _) -> error.
%% ===================================================================
%% @doc Given a bucket/key, determine the associated preflist index_n.
--spec get_index_n({binary(), binary()}, riak_core_ring()) -> index_n().
-get_index_n({Bucket, Key}, Ring) ->
- BucketProps = riak_core_bucket:get_bucket(Bucket, Ring),
+-spec get_index_n({binary(), binary()}) -> index_n().
+get_index_n({Bucket, Key}) ->
+ BucketProps = riak_core_bucket:get_bucket(Bucket),
N = proplists:get_value(n_val, BucketProps),
ChashKey = riak_core_util:chash_key({Bucket, Key}),
- Index = riak_core_ring:responsible_index(ChashKey, Ring),
+ CHBin = riak_core_ring_manager:get_chash_bin(),
+ Index = chashbin:responsible_index(ChashKey, CHBin),
{Index, N}.
%% @doc Given an index, determine all sibling indices that participate in one
View
@@ -847,8 +847,7 @@ handle_exit(_Pid, Reason, State) ->
do_put(Sender, {Bucket,_Key}=BKey, RObj, ReqID, StartTime, Options, State) ->
case proplists:get_value(bucket_props, Options) of
undefined ->
- {ok,Ring} = riak_core_ring_manager:get_my_ring(),
- BProps = riak_core_bucket:get_bucket(Bucket, Ring);
+ BProps = riak_core_bucket:get_bucket(Bucket);
BProps ->
BProps
end,

0 comments on commit cc35687

Please sign in to comment.