Skip to content

Commit

Permalink
Merge pull request #1 from eraserewind/upgrade-elixir-0.12
Browse files Browse the repository at this point in the history
Upgrade to Elixir 0.12
  • Loading branch information
awetzel committed Jan 31, 2014
2 parents 6b804d7 + eb55fbf commit c4a94b4
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .gitignore
@@ -1,4 +1,4 @@
/ebin
/_build
/deps
erl_crash.dump
*.ez
Expand Down
6 changes: 3 additions & 3 deletions lib/consistent_hash.ex
Expand Up @@ -12,12 +12,12 @@ defmodule ConsistentHash do
#then create a bst adapted to consistent hashing traversal, for a given hash, find the next vnode dot in the ring
vnodes = nodes |> flat_map(fn n -> (1..@vnode_per_node |> map &{key_as_int("#{n}#{&1}"),n}) end)
|> sort(fn {h1,_},{h2,_}->h2>h1 end)
vnodes |> bsplit({0,trunc(:math.pow(2,160)-1)},vnodes|>first)
vnodes |> bsplit({0,trunc(:math.pow(2,160)-1)},vnodes|>List.first)
end

# "place each term into int hash space : term -> 160bits bin -> integer"
defp key_as_int(<<key::[size(160),integer]>>),do: key
defp key_as_int(key),do: (key |> term_to_binary |> :crypto.sha |> key_as_int)
defp key_as_int(key),do: :crypto.hash(:sha, term_to_binary(key)) |> key_as_int

# dedicated binary search tree, middle split each interval (easy tree
# balancing) except when only one vnode is there (split at vnode hash)
Expand All @@ -26,7 +26,7 @@ defmodule ConsistentHash do
defp bsplit(list,{lbound,rbound},next) do # interval contains multiple vnode, recursivly middle split allows easy tree balancing
center = lbound + (rbound - lbound)/2
{left,right} = list |> split_while(fn {h,_n}->h<center end)
{center,bsplit(left,{lbound,center},(right|>first)||next),bsplit(right,{center,rbound},next)}
{center,bsplit(left,{lbound,center},(right|>List.first)||next),bsplit(right,{center,rbound},next)}
end
# bsplit is designed to allow standard btree traversing to associate node to hash
defp bfind(_,node) when is_atom(node), do: node
Expand Down
4 changes: 2 additions & 2 deletions lib/supervisorring.ex
Expand Up @@ -49,13 +49,13 @@ defmodule Supervisorring do
# "node_for_key"==node then proc associated with id is running on the node
def handle_cast({:onnode,id,sender,fun},state) do
case ConsistentHash.node_for_key(state.ring,{state.sup_ref,id}) do
n when n==node -> sender<-{:executed,fun.()}
n when n==node -> send sender, {:executed,fun.()}
othernode -> :gen_server.cast({state.sup_ref|>Supervisorring.child_manager_ref,othernode},{:onnode,id,sender,fun})
end
{:noreply,state}
end
def handle_cast({:get_handler,childid,sender},State[child_specs: specs]=state) do
sender <- specs|>filter(&match?({:dyn_child_handler,_},&1))|>find(fn{_,h}->h.match(childid)end)
send sender, specs|>filter(&match?({:dyn_child_handler,_},&1))|>find(fn{_,h}->h.match(childid)end)
{:noreply,state}
end
def handle_cast(:sync_children,State[sup_ref: sup_ref,child_specs: specs,callback: callback]=state) do
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Expand Up @@ -4,7 +4,7 @@ defmodule Supervisorring.Mixfile do
def project do
[ app: :supervisorring,
version: "0.0.1",
elixir: "~> 0.11.0",
elixir: "~> 0.12.0",
deps: [{:nano_ring,"0.0.1",git: "git://github.com/awetzel/nano_ring"}],
## dev multi nodes configs
env: [
Expand Down
2 changes: 1 addition & 1 deletion mix.lock
@@ -1 +1 @@
[ "nano_ring": {:git, "git://github.com/awetzel/nano_ring", "a309c6f336102fca8cc8c8c9128caf0db7b20708", []} ]
[ "nano_ring": {:git, "git://github.com/awetzel/nano_ring", "ec3379f7efa71d1a08af8f3ea1df22caffec4da3", []} ]

0 comments on commit c4a94b4

Please sign in to comment.