Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First step of implementing the multinode support
- Loading branch information
Joachim
committed
Mar 26, 2013
1 parent
1698f5f
commit 993c21d
Showing
11 changed files
with
182 additions
and
14 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 |
---|---|---|
|
@@ -8,3 +8,4 @@ erl_crash.dump | |
logs/ | ||
log/ | ||
*~ | ||
.hosts.erlang |
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,4 +1,4 @@ | ||
{"src/*", [warn_unused_vars, warn_export_all, warn_shadow_vars, warn_unused_import, warn_unused_function, warn_bif_clash, warn_unused_record, warn_deprecated_function, warn_obsolete_guard, strict_validation, report, warn_export_vars, warn_exported_vars, warn_missing_spec, warn_untyped_record, debug_info, {outdir, "ebin"}, {i, "include"}, {i, "deps/lager/include"}]}. | ||
{"src/*/*", [warn_unused_vars, warn_export_all, warn_shadow_vars, warn_unused_import, warn_unused_function, warn_bif_clash, warn_unused_record, warn_deprecated_function, warn_obsolete_guard, strict_validation, report, warn_export_vars, warn_exported_vars, warn_missing_spec, warn_untyped_record, debug_info, {outdir, "ebin"}, {i, "include"}, {i, "deps/lager/include"}]}. | ||
{"test/*", [warn_unused_vars, warn_shadow_vars, warn_unused_import, warn_unused_function, warn_bif_clash, warn_unused_record, warn_deprecated_function, warn_obsolete_guard, strict_validation, report, warn_export_vars, warn_exported_vars, warn_missing_spec, warn_untyped_record, debug_info, {outdir, "ebin"}, {i, "include"}, {i, "deps/lager/include"}]}. | ||
{"test/*/*", [warn_unused_vars, warn_export_all, warn_shadow_vars, warn_unused_import, warn_unused_function, warn_bif_clash, warn_unused_record, warn_deprecated_function, warn_obsolete_guard, strict_validation, report, warn_export_vars, warn_exported_vars, warn_missing_spec, warn_untyped_record, debug_info, {outdir, "ebin"}, {i, "include"}, {i, "deps/lager/include"}]}. | ||
{"src/*", [{parse_transform, lager_transform}, warn_unused_vars, warn_export_all, warn_shadow_vars, warn_unused_import, warn_unused_function, warn_bif_clash, warn_unused_record, warn_deprecated_function, warn_obsolete_guard, strict_validation, report, warn_export_vars, warn_exported_vars, warn_missing_spec, warn_untyped_record, debug_info, {outdir, "ebin"}, {i, "include"}, {i, "deps/lager/include"}]}. | ||
{"src/*/*", [{parse_transform, lager_transform}, warn_unused_vars, warn_export_all, warn_shadow_vars, warn_unused_import, warn_unused_function, warn_bif_clash, warn_unused_record, warn_deprecated_function, warn_obsolete_guard, strict_validation, report, warn_export_vars, warn_exported_vars, warn_missing_spec, warn_untyped_record, debug_info, {outdir, "ebin"}, {i, "include"}, {i, "deps/lager/include"}]}. | ||
{"test/*", [{parse_transform, lager_transform}, warn_unused_vars, warn_shadow_vars, warn_unused_import, warn_unused_function, warn_bif_clash, warn_unused_record, warn_deprecated_function, warn_obsolete_guard, strict_validation, report, warn_export_vars, warn_exported_vars, warn_missing_spec, warn_untyped_record, debug_info, {outdir, "ebin"}, {i, "include"}, {i, "deps/lager/include"}]}. | ||
{"test/*/*", [{parse_transform, lager_transform}, arn_unused_vars, warn_export_all, warn_shadow_vars, warn_unused_import, warn_unused_function, warn_bif_clash, warn_unused_record, warn_deprecated_function, warn_obsolete_guard, strict_validation, report, warn_export_vars, warn_exported_vars, warn_missing_spec, warn_untyped_record, debug_info, {outdir, "ebin"}, {i, "include"}, {i, "deps/lager/include"}]}. |
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
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
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,120 @@ | ||
%%%------------------------------------------------------------------- | ||
%%% File : edis_node_monitor.erl | ||
%%% Author : Joachim Nilsson <joachim@inakanetworks.com> | ||
%%% Description : A node monitor for multi-node support | ||
%%% | ||
%%% Created : 22 March 2013 | ||
%%%------------------------------------------------------------------- | ||
-module(edis_node_monitor). | ||
|
||
-behaviour(gen_server). | ||
|
||
%% API | ||
-export([start_link/0]). | ||
|
||
%% gen_server callbacks | ||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, | ||
terminate/2, code_change/3]). | ||
|
||
-record(state, {}). | ||
-define(SERVER, ?MODULE). | ||
|
||
%%==================================================================== | ||
%% API | ||
%%==================================================================== | ||
%%-------------------------------------------------------------------- | ||
%% Function: start_link() -> {ok,Pid} | ignore | {error,Error} | ||
%% Description: Starts the server | ||
%%-------------------------------------------------------------------- | ||
start_link() -> | ||
gen_server:start_link({local, ?SERVER}, ?MODULE, [], []). | ||
|
||
multi_node_set(Key,Value) -> gen_server:abcast('bar@Joachims-MacBook-Air.local', 'bar', {set, Key, Value}). | ||
|
||
%%==================================================================== | ||
%% gen_server callbacks | ||
%%==================================================================== | ||
|
||
%%-------------------------------------------------------------------- | ||
%% Function: init(Args) -> {ok, State} | | ||
%% {ok, State, Timeout} | | ||
%% ignore | | ||
%% {stop, Reason} | ||
%% Description: Initiates the server | ||
%%-------------------------------------------------------------------- | ||
init([]) -> | ||
ok = pg2:join(node_group, self()), | ||
ok = net_kernel:monitor_nodes(true, [nodedown_reason]), | ||
net_adm:world(), | ||
{ok, #state{}}. | ||
|
||
%%-------------------------------------------------------------------- | ||
%% Function: %% handle_call(Request, From, State) -> {reply, Reply, State} | | ||
%% {reply, Reply, State, Timeout} | | ||
%% {noreply, State} | | ||
%% {noreply, State, Timeout} | | ||
%% {stop, Reason, Reply, State} | | ||
%% {stop, Reason, State} | ||
%% Description: Handling call messages | ||
%%-------------------------------------------------------------------- | ||
handle_call(_Request, _From, State) -> | ||
Reply = ok, | ||
{reply, Reply, State}. | ||
|
||
%%-------------------------------------------------------------------- | ||
%% Function: handle_cast(Msg, State) -> {noreply, State} | | ||
%% {noreply, State, Timeout} | | ||
%% {stop, Reason, State} | ||
%% Description: Handling cast messages | ||
%%-------------------------------------------------------------------- | ||
handle_cast(_Msg, State) -> | ||
|
||
|
||
|
||
|
||
{noreply, State}. | ||
|
||
%%-------------------------------------------------------------------- | ||
%% Function: handle_info(Info, State) -> {noreply, State} | | ||
%% {noreply, State, Timeout} | | ||
%% {stop, Reason, State} | ||
%% Description: Handling all non call/cast messages | ||
%%-------------------------------------------------------------------- | ||
handle_info({Event, Node, Data}, State) -> | ||
|
||
|
||
%% INFO ABOUT NODES SHOULD COME IN HERE. CHECK OUT FORMAT (monitor_nodes?) AND CATCH | ||
%% Is this the format that monitor_nodes will deliver a message? {Event, Node, Data} | ||
|
||
case Event of | ||
nodeup -> | ||
lager:notice("~n~n\t\t~p is UP! (~p)~n~n", [Node, Data]); | ||
nodedown -> | ||
lager:notice("~n~n\t\t~p is DOWN! (~p).", [Node, Data]); | ||
nodegone -> | ||
lager:notice("~n~n\t\t~p is GONE! (~p).", [Node, Data]) | ||
end, | ||
|
||
|
||
{noreply, State}. | ||
|
||
%%-------------------------------------------------------------------- | ||
%% Function: terminate(Reason, State) -> void() | ||
%% Description: This function is called by a gen_server when it is about to | ||
%% terminate. It should be the opposite of Module:init/1 and do any necessary | ||
%% cleaning up. When it returns, the gen_server terminates with Reason. | ||
%% The return value is ignored. | ||
%%-------------------------------------------------------------------- | ||
terminate(_Reason, _State) -> | ||
ok. | ||
|
||
%%-------------------------------------------------------------------- | ||
%% Func: code_change(OldVsn, State, Extra) -> {ok, NewState} | ||
%% Description: Convert process state when code is changed | ||
%%-------------------------------------------------------------------- | ||
code_change(_OldVsn, State, _Extra) -> | ||
{ok, State}. | ||
|
||
%%-------------------------------------------------------------------- | ||
%%% Internal functions | ||
%%-------------------------------------------------------------------- |
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,38 @@ | ||
%%%------------------------------------------------------------------- | ||
%%% @author Joachim Nilsson <joachim@inakanetworks.com> | ||
%%% @copyright (C) 2011 InakaLabs SRL | ||
%%% @doc Edis Node supervisor | ||
%%% @end | ||
%%%------------------------------------------------------------------- | ||
-module(edis_node_sup). | ||
-author('Joachim Nilsson <joachim@inakanetworks.com>'). | ||
|
||
-include("edis.hrl"). | ||
|
||
-behaviour(supervisor). | ||
|
||
-export([start_link/0, reload/0, init/1]). | ||
|
||
%% ==================================================================== | ||
%% External functions | ||
%% ==================================================================== | ||
%% @doc Starts the supervisor process | ||
-spec start_link() -> ignore | {error, term()} | {ok, pid()}. | ||
start_link() -> | ||
supervisor:start_link({local, ?MODULE}, ?MODULE, []). | ||
|
||
%% @doc Reloads configuration. Restarts the managers | ||
-spec reload() -> ok. | ||
reload() -> | ||
true = exit(erlang:whereis(?MODULE), kill), | ||
ok. | ||
|
||
%% ==================================================================== | ||
%% Server functions | ||
%% ==================================================================== | ||
%% @hidden | ||
-spec init([]) -> {ok, {{one_for_one, 5, 10}, [supervisor:child_spec()]}}. | ||
init([]) -> | ||
lager:info("Node supervisor initialized~n", []), | ||
Mgr = {edis_node_monitor, {edis_node_monitor, start_link, []}, permanent, brutal_kill, worker, [edis_node_monitor]}, | ||
{ok, {{one_for_one, 5, 1}, [Mgr]}}. |
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