-
-
Save binarytemple/9b0cf593c44f37385304 to your computer and use it in GitHub Desktop.
tanodb getting preflist
This file contains hidden or 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
| ``` | |
| Calc = fun(Bucket,Key) -> | |
| BKey = {Bucket,Key}, | |
| {ok, Ring} = riak_core_ring_manager:get_my_ring(), | |
| DocIdx = riak_core_util:chash_key(BKey), | |
| NValue = 1, | |
| UpNodes = riak_core_node_watcher:nodes(tanodb), | |
| Preflist2 = riak_core_apl:get_apl_ann(DocIdx, NValue, Ring, UpNodes), | |
| [Res] = [Part || {{Part,Node}, Type} <- Preflist2], | |
| Res | |
| end. | |
| Calc(<<"d">>, Key = <<"e0c97a4cde6c">>). | |
| ``` | |
| Great, that worked, lets back up and get access to the ring again. | |
| ``` | |
| {ok,{_,_, _, {RingSize, NodeList}, _, _, _, _, _, _, _ }} = riak_core_ring_manager:get_my_ring | |
| (). | |
| ``` | |
| That returns a lot of data, but we are only interested in the nodelist. | |
| Let's take a look a the head of that list. | |
| ```erlang | |
| (tanodb3@127.0.0.1)66> [H|_] = NodeList. | |
| (tanodb3@127.0.0.1)65> H. | |
| {0,'tanodb1@127.0.0.1'} | |
| ``` | |
| Ok, from that lets extract the partition list. | |
| ```erlang | |
| (tanodb3@127.0.0.1)63> Partitions = [ Part || {Part,_} <- NodeList]. | |
| [0,22835963083295358096932575511191922182123945984, | |
| 45671926166590716193865151022383844364247891968, | |
| 68507889249886074290797726533575766546371837952, | |
| 91343852333181432387730302044767688728495783936, | |
| 114179815416476790484662877555959610910619729920, | |
| 137015778499772148581595453067151533092743675904, | |
| ``` | |
| Lets create something for generating random numbers: | |
| ``` | |
| (tanodb3@127.0.0.1)89> integer_to_list(round(random:uniform() * 10000000000000000000000000000000)). | |
| "1421082177012422726572125978624" | |
| ``` | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment