diff --git a/.gitignore b/.gitignore index 78a364c..f93cb57 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ erl_crash.dump logs/ log/ *~ +.hosts.erlang \ No newline at end of file diff --git a/Emakefile b/Emakefile index 3e0b1bf..272bf58 100644 --- a/Emakefile +++ b/Emakefile @@ -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"}]}. \ No newline at end of file +{"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"}]}. \ No newline at end of file diff --git a/Makefile b/Makefile index 8b88000..3b953e3 100644 --- a/Makefile +++ b/Makefile @@ -32,11 +32,12 @@ run: erl ${ERL} -s edis test: erl - ${ERL} -config test/test.config -noshell -sname edis_test_server -s edis & + #${ERL} -config test/test.config -noshell -sname edis_test_server -s edis & mkdir -p ./test/ebin mkdir -p ./logs/ct - rebar skip_deps=true ct -v; \ - kill `ps aux | grep beam | grep edis_[t]est_server | awk '{print $$2}'` + # To run all tests, remove: suites=keys + rebar skip_deps=true ct suites=keys -v; \ + #kill `ps aux | grep beam | grep edis_[t]est_server | awk '{print $$2}'` test-hanoidb: erl ${ERL} -config test/test-hanoidb.config -noshell -sname edis_test_server -s edis -run elog debug & diff --git a/pd.config b/pd.config index c1013ce..9286350 100644 --- a/pd.config +++ b/pd.config @@ -1,8 +1,8 @@ -[{edis, [{listener_port_range, {6381, 6381}}, {backend, {edis_pd_backend, []}}]}, +[{edis, [{listener_port_range, {6384, 6385}}, {backend, {edis_pd_backend, []}}]}, {lager, [ {handlers, [ - {lager_console_backend, [debug,true]} + {lager_console_backend, [info,true]} ]} ]}, {sasl, [{errlog_type, all}, diff --git a/rebar.config b/rebar.config index bc6e6c9..e8f4060 100644 --- a/rebar.config +++ b/rebar.config @@ -23,7 +23,7 @@ warn_missing_spec, warn_untyped_record, debug_info]}. {xref_checks, [undefined_function_calls]}. -{ct_extra_params,"-no_auto_compile -dir ./test/ebin -logdir logs/ct"}. +{ct_extra_params," -dir ./test/ebin -logdir logs/ct"}. {edoc_opts, [{report_missing_types, true}, {source_path, ["src"]}, {report_missing_types, true}, {todo, true}, {packages, false}, {subpackages, false}]}. diff --git a/src/edis.app.src b/src/edis.app.src index f9f2d48..07884ff 100644 --- a/src/edis.app.src +++ b/src/edis.app.src @@ -9,8 +9,8 @@ crypto ]}, {mod, {edis, []}}, - {env, [{listener_port_range, {6379,6379}}, + {env, [{listener_port_range, {6378,6379}}, {client_timeout, 32000}, - {databases, 16}, + {databases, 1}, {requirepass, undefined}]} ]}. diff --git a/src/edis.erl b/src/edis.erl index d765d85..5071a05 100644 --- a/src/edis.erl +++ b/src/edis.erl @@ -60,6 +60,12 @@ stop() -> application:stop(?MODULE). %% @private -spec start(any(), any()) -> {ok, pid()}. start(_StartType, _StartArgs) -> +%% Try to connect to a specific host - by choosing a cookie. +%% erlang:get_cookie() (of the current node) +%% OtherNodes = net_adm:world(), + %%Me = node(), + %%erlang:set_cookie(Me, my_cookie), + pg2:create(node_group), edis_sup:start_link(). %% @private diff --git a/src/edis_command_runner.erl b/src/edis_command_runner.erl index a6cb825..dd417ac 100644 --- a/src/edis_command_runner.erl +++ b/src/edis_command_runner.erl @@ -620,7 +620,7 @@ run(#edis_command{cmd = <<"SHUTDOWN">>}, State) -> _ = spawn(edis, stop, []), {stop, normal, State}; run(#edis_command{cmd = <<"SELECT">>, args = [DbIndex]}, State) -> - tcp_ok(State#state{db = edis_db:process(DbIndex)}); + tcp_ok(State#state{db = edis_db:process(DbIndex), db_index = DbIndex}); run(#edis_command{cmd = <<"CONFIG GET">>, args = [Pattern]}, State) -> Configs = edis_config:get(Pattern), Lines = lists:flatten( diff --git a/src/edis_node_monitor.erl b/src/edis_node_monitor.erl new file mode 100644 index 0000000..d4e3d12 --- /dev/null +++ b/src/edis_node_monitor.erl @@ -0,0 +1,120 @@ +%%%------------------------------------------------------------------- +%%% File : edis_node_monitor.erl +%%% Author : Joachim Nilsson +%%% 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 +%%-------------------------------------------------------------------- \ No newline at end of file diff --git a/src/edis_node_sup.erl b/src/edis_node_sup.erl new file mode 100644 index 0000000..33464e9 --- /dev/null +++ b/src/edis_node_sup.erl @@ -0,0 +1,38 @@ +%%%------------------------------------------------------------------- +%%% @author Joachim Nilsson +%%% @copyright (C) 2011 InakaLabs SRL +%%% @doc Edis Node supervisor +%%% @end +%%%------------------------------------------------------------------- +-module(edis_node_sup). +-author('Joachim Nilsson '). + +-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]}}. \ No newline at end of file diff --git a/src/edis_sup.erl b/src/edis_sup.erl index 6ef06c2..baba926 100644 --- a/src/edis_sup.erl +++ b/src/edis_sup.erl @@ -35,4 +35,6 @@ init([]) -> permanent, 1000, supervisor, [edis_db_sup]}, PubSubSup = {edis_pubsub_sup, {edis_pubsub_sup, start_link, []}, permanent, 1000, supervisor, [edis_pubsub_sup]}, - {ok, {{one_for_one, 5, 10}, [PubSubSup, DbSup, ClientSup, ListenerSup]}}. \ No newline at end of file + NodeSup = {edis_node_sup, {edis_node_sup, start_link, []}, + permanent, 1000, supervisor, [edis_node_sup]}, + {ok, {{one_for_one, 5, 10}, [NodeSup, PubSubSup, DbSup, ClientSup, ListenerSup]}}. \ No newline at end of file