Skip to content

Instantly share code, notes, and snippets.

@dams
Created September 16, 2014 08:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dams/2c946f7550750473a823 to your computer and use it in GitHub Desktop.
Save dams/2c946f7550750473a823 to your computer and use it in GitHub Desktop.
is_primary_for_doc(BKey) ->
{ok, CHBin} = riak_core_ring_manager:get_chash_bin(),
DocIdx = riak_core_util:chash_key(BKey),
Itr = chashbin:iterator(DocIdx, CHBin),
MyNode = node(),
case chashbin:itr_value(Itr) of
{_Idx, Node} when Node == MyNode -> true;
{_Idx, _Node} -> false
end.
copy_to_cache(Object) ->
{ok, Client} = riak:local_client(),
Bucket = << "cached_events" >>,
Key = riak_object:key(Object),
case is_primary_for_doc({Bucket, Key}) of
true ->
NewObj = riak_object:new( Bucket,
Key,
riak_object:get_value(Object) ),
riak_client:put(NewObj, 0, 0, Client),
Object;
false ->
Object
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment