diff options
author | Adam Kocoloski <adam@cloudant.com> | 2010-07-02 03:12:45 -0400 |
---|---|---|
committer | Adam Kocoloski <adam@cloudant.com> | 2010-08-12 01:23:30 -0400 |
commit | 40c669d1864c4c9eb788240dd4edc533d8a352f2 (patch) | |
tree | cdd1ce41c1dc76bf8ad907821b94d61901bc9ecb /src/mem3_sync_event.erl | |
parent | 570649ec3d6c66be8d7900b655cdc1d31ca8fe27 (diff) |
mega refactoring of mem3
Diffstat (limited to 'src/mem3_sync_event.erl')
-rw-r--r-- | src/mem3_sync_event.erl | 25 |
1 files changed, 20 insertions, 5 deletions
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}. |