From 7a979e2c575e8dffdbcd820d24c3794da533e935 Mon Sep 17 00:00:00 2001 From: Ery Lee Date: Wed, 8 Apr 2015 19:40:22 +0800 Subject: [PATCH] cluster --- apps/emqttd/src/emqttd_mnesia.erl | 16 +++++----- apps/emqttd/src/emqttd_pubsub.erl | 8 +++-- apps/emqttd/src/x.erl | 50 ------------------------------- rel/reltool.config | 2 +- 4 files changed, 15 insertions(+), 61 deletions(-) delete mode 100644 apps/emqttd/src/x.erl diff --git a/apps/emqttd/src/emqttd_mnesia.erl b/apps/emqttd/src/emqttd_mnesia.erl index 27889dcd0..f6b6df91b 100644 --- a/apps/emqttd/src/emqttd_mnesia.erl +++ b/apps/emqttd/src/emqttd_mnesia.erl @@ -33,14 +33,14 @@ -export([init/0, wait/0]). init() -> - case mnesia:system_info(extra_db_nodes) of - [] -> - mnesia:stop(), - mnesia:create_schema([node()]); - _ -> - ok - end, - ok = mnesia:start(), + %case mnesia:system_info(extra_db_nodes) of + % [] -> + % mnesia:stop(), + % mnesia:create_schema([node()]); + % _ -> + % ok + %end, + %ok = mnesia:start(), create_tables(). create_tables() -> diff --git a/apps/emqttd/src/emqttd_pubsub.erl b/apps/emqttd/src/emqttd_pubsub.erl index 76d6bef76..6e25814cc 100644 --- a/apps/emqttd/src/emqttd_pubsub.erl +++ b/apps/emqttd/src/emqttd_pubsub.erl @@ -232,22 +232,26 @@ init([]) -> {ram_copies, [node()]}, {attributes, record_info(fields, topic_trie)}]), mnesia:add_table_copy(topic_trie, node(), ram_copies), + Result = mnesia:create_table(topic, [ {type, bag}, {record_name, topic}, {ram_copies, [node()]}, {attributes, record_info(fields, topic)}]), + io:format("~p~n", [Result]), mnesia:add_table_copy(topic, node(), ram_copies), mnesia:subscribe({table, topic, simple}), %% local table, not shared with other table + Result1 = mnesia:create_table(topic_subscriber, [ {type, bag}, {record_name, topic_subscriber}, {ram_copies, [node()]}, {attributes, record_info(fields, topic_subscriber)}, - {index, [subpid]}, - {local_content, true}]), + {index, [subpid]}]), + %{local_content, true}]), mnesia:subscribe({table, topic_subscriber, simple}), + io:format("~p~n", [Result1]), {ok, #state{}}. handle_call(getstats, _From, State = #state{max_subs = Max}) -> diff --git a/apps/emqttd/src/x.erl b/apps/emqttd/src/x.erl deleted file mode 100644 index 06e3e515d..000000000 --- a/apps/emqttd/src/x.erl +++ /dev/null @@ -1,50 +0,0 @@ --module(x). --behaviour(gen_server). --define(SERVER, ?MODULE). - -%% ------------------------------------------------------------------ -%% API Function Exports -%% ------------------------------------------------------------------ - --export([start_link/0]). - -%% ------------------------------------------------------------------ -%% gen_server Function Exports -%% ------------------------------------------------------------------ - --export([init/1, handle_call/3, handle_cast/2, handle_info/2, - terminate/2, code_change/3]). - -%% ------------------------------------------------------------------ -%% API Function Definitions -%% ------------------------------------------------------------------ - -start_link() -> - gen_server:start_link({local, ?SERVER}, ?MODULE, [], []). - -%% ------------------------------------------------------------------ -%% gen_server Function Definitions -%% ------------------------------------------------------------------ - -init(Args) -> - {ok, Args}. - -handle_call(_Request, _From, State) -> - {reply, ok, State}. - -handle_cast(_Msg, State) -> - {noreply, State}. - -handle_info(_Info, State) -> - {noreply, State}. - -terminate(_Reason, _State) -> - ok. - -code_change(_OldVsn, State, _Extra) -> - {ok, State}. - -%% ------------------------------------------------------------------ -%% Internal Function Definitions -%% ------------------------------------------------------------------ - diff --git a/rel/reltool.config b/rel/reltool.config index fd226f03a..954f80aac 100644 --- a/rel/reltool.config +++ b/rel/reltool.config @@ -10,7 +10,7 @@ syntax_tools, ssl, crypto, - %mnesia, + mnesia, os_mon, inets, goldrush,