Configurable redirect of mem3 push jobs In order to faciliate smoother node replacements, mem3 can be configured to redirect push jobs intended for one node (the failed one) to another (its replacement). e.g,
[mem3.redirects] [email protected] = [email protected] BugzID: 14348 Project: http://git-wip-us.apache.org/repos/asf/couchdb-mem3/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-mem3/commit/016c2c97 Tree: http://git-wip-us.apache.org/repos/asf/couchdb-mem3/tree/016c2c97 Diff: http://git-wip-us.apache.org/repos/asf/couchdb-mem3/diff/016c2c97 Branch: refs/heads/import Commit: 016c2c972bda8efed943c5d299aa1052cac02e3b Parents: 09e6f07 Author: Robert Newson <[email protected]> Authored: Tue Aug 21 17:31:08 2012 +0100 Committer: Robert Newson <[email protected]> Committed: Tue Aug 21 17:31:08 2012 +0100 ---------------------------------------------------------------------- src/mem3_sync.erl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-mem3/blob/016c2c97/src/mem3_sync.erl ---------------------------------------------------------------------- diff --git a/src/mem3_sync.erl b/src/mem3_sync.erl index 5cd7960..9f3b752 100644 --- a/src/mem3_sync.erl +++ b/src/mem3_sync.erl @@ -205,7 +205,7 @@ handle_replication_exit(State, Pid) -> start_push_replication(#job{name=Name, node=Node, pid=From}) -> if From =/= nil -> gen_server:reply(From, ok); true -> ok end, spawn_link(fun() -> - case mem3_rep:go(Name, Node) of + case mem3_rep:go(Name, maybe_redirect(Node)) of {ok, Pending} when Pending > 0 -> exit({pending_changes, Pending}); _ -> @@ -330,3 +330,12 @@ shards_db() -> users_db() -> ?l2b(couch_config:get("couch_httpd_auth", "authentication_db", "_users")). + +maybe_redirect(Node) -> + case couch_config:get("mem3.redirects", atom_to_list(Node)) of + undefined -> + Node; + Redirect -> + twig:log(debug, "Redirecting push from ~p to ~p", [Node, Redirect]), + list_to_existing_atom(Redirect) + end.
