forked from dustin/mccouch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use supervisors to manage crashes better.
Now crashing the FSM that manages the backend will cause the connections to drop instead of just be orphaned. closes dustin#12 Change-Id: I99105f8ef9abf8949049ae0e9ea63cfe117f7cdc
- Loading branch information
Showing
6 changed files
with
87 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
; Add this to etc/couchdb/local.d | ||
[daemons] | ||
mc_daemon={mc_daemon, start_link, ["kv", true]} | ||
mc_daemon={mc_sup, start_link, ["kv", true]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
-module(mc_conn_sup). | ||
|
||
-behaviour(supervisor). | ||
|
||
-export([start_link/0]). | ||
|
||
-export([init/1]). | ||
|
||
-export([start_connection/1]). | ||
|
||
-define(SERVER, ?MODULE). | ||
|
||
start_link() -> | ||
supervisor:start_link({local, ?SERVER}, ?MODULE, []). | ||
|
||
init([]) -> | ||
{ok, {{simple_one_for_one, 0, 1}, | ||
[{mc_connection, {mc_connection, start_link, [mc_daemon]}, | ||
temporary, brutal_kill, worker, [mc_connection]}]}}. | ||
|
||
start_connection(NS) -> | ||
{ok, Pid} = supervisor:start_child(?MODULE, [NS]), | ||
gen_tcp:controlling_process(NS, Pid), | ||
%% Tell this mc_connection it's the controlling process and ready to go. | ||
Pid ! go, | ||
{ok, Pid}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
-module(mc_sup). | ||
|
||
-behaviour(supervisor). | ||
|
||
-export([start_link/2]). | ||
|
||
-export([init/1]). | ||
|
||
-define(SERVER, ?MODULE). | ||
|
||
start_link(DbName, JsonMode) -> | ||
application:start(sasl), | ||
supervisor:start_link({local, ?SERVER}, ?MODULE, [DbName, JsonMode]). | ||
|
||
%%-------------------------------------------------------------------- | ||
%% @private | ||
%% @doc | ||
%% Whenever a supervisor is started using supervisor:start_link/[2,3], | ||
%% this function is called by the new process to find out about | ||
%% restart strategy, maximum restart frequency and child | ||
%% specifications. | ||
%% | ||
%% @spec init(Args) -> {ok, {SupFlags, [ChildSpec]}} | | ||
%% ignore | | ||
%% {error, Reason} | ||
%% @end | ||
%%-------------------------------------------------------------------- | ||
init([DbName, JsonMode]) -> | ||
RestartStrategy = one_for_all, | ||
MaxRestarts = 1000, | ||
MaxSecondsBetweenRestarts = 3600, | ||
|
||
SupFlags = {RestartStrategy, MaxRestarts, MaxSecondsBetweenRestarts}, | ||
|
||
Restart = permanent, | ||
Shutdown = 2000, | ||
Type = worker, | ||
|
||
Daemon = {mc_daemon, {mc_daemon, start_link, [DbName, JsonMode]}, | ||
Restart, Shutdown, Type, [mc_daemon]}, | ||
|
||
TcpListener = {mc_tcp_listener, {mc_tcp_listener, start_link, [11213, mc_daemon]}, | ||
Restart, Shutdown, Type, [mc_tcp_listener, mc_daemon]}, | ||
|
||
ConnSup = {mc_conn_sup, {mc_conn_sup, start_link, []}, | ||
Restart, Shutdown, supervisor, dynamic}, | ||
|
||
{ok, {SupFlags, [Daemon, TcpListener, ConnSup]}}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters