aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/manager.ex15
1 files changed, 7 insertions, 8 deletions
diff --git a/lib/manager.ex b/lib/manager.ex
index b547312..f6910e4 100644
--- a/lib/manager.ex
+++ b/lib/manager.ex
@@ -50,14 +50,6 @@ defmodule Shard.Manager do
{:ok, %{my_port: my_port, outbox: outbox} }
end
- def handle_call({:find, shard_id}, _from, state) do
- reply = case :ets.lookup(:shard_db, shard_id) do
- [{ ^shard_id, _, pid }] -> {:ok, pid}
- [] -> :not_found
- end
- {:reply, reply, state}
- end
-
def handle_call({:register, shard_id, manifest, pid}, _from, state) do
will_live = case :ets.lookup(:shard_db, shard_id) do
[{ ^shard_id, _, pid }] -> not Process.alive?(pid)
@@ -102,6 +94,13 @@ defmodule Shard.Manager do
end
def handle_cast({:peer_up, pk, pid, ip, port}, state) do
+ for {pk2, _, _, _} <- :ets.match(:peer_db, {:_, :_, ip, port}) do
+ if pk2 != pk do
+ # obsolete peer information
+ :ets.delete(:peer_db, pk2)
+ :ets.match_delete(:shard_peer_db, {:_, pk2})
+ end
+ end
:ets.insert(:peer_db, {pk, pid, ip, port})
# Send interested message for all our shards