Created
September 16, 2014 08:48
-
-
Save dams/2c946f7550750473a823 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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