From 40c669d1864c4c9eb788240dd4edc533d8a352f2 Mon Sep 17 00:00:00 2001 From: Adam Kocoloski Date: Fri, 2 Jul 2010 03:12:45 -0400 Subject: mega refactoring of mem3 --- src/mem3_sync_event.erl | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'src/mem3_sync_event.erl') diff --git a/src/mem3_sync_event.erl b/src/mem3_sync_event.erl index 55f3840c..45fcb8aa 100644 --- a/src/mem3_sync_event.erl +++ b/src/mem3_sync_event.erl @@ -7,11 +7,26 @@ init(_) -> {ok, nil}. -handle_event({Up, Node}, State) when Up == nodeup; Up == node_join -> - mem3_sync:add_node(Node); - -handle_event({Down, Node}, State) when Down == nodedown; Down == node_leave -> - mem3_sync:remove_node(Node); +handle_event({add_node, Node}, State) -> + Db1 = list_to_binary(couch_config:get("mem3", "node_db", "nodes")), + Db2 = list_to_binary(couch_config:get("mem3", "shard_db", "dbs")), + [mem3_sync:push(Db, Node) || Db <- [Db1, Db2]], + {ok, State}; + +handle_event({nodeup, Node}, State) -> + case lists:member(Node, mem3:nodes()) of + true -> + Db1 = list_to_binary(couch_config:get("mem3", "node_db", "nodes")), + Db2 = list_to_binary(couch_config:get("mem3", "shard_db", "dbs")), + [mem3_sync:push(Db, Node) || Db <- [Db1, Db2]]; + false -> + ok + end, + {ok, State}; + +handle_event({Down, Node}, State) when Down == nodedown; Down == remove_node -> + mem3_sync:remove_node(Node), + {ok, State}; handle_event(_Event, State) -> {ok, State}. -- cgit v1.2.3