Skip to content

Commit

Permalink
Fix leofs/issues/99
Browse files Browse the repository at this point in the history
  • Loading branch information
yosukehara committed Nov 8, 2013
1 parent 8a72f83 commit 39bab36
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 17 deletions.
9 changes: 6 additions & 3 deletions include/leo_redundant_manager.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,12 @@

%% Dump File
%%
-define(DUMP_FILE_MEMBERS, "./log/ring/members.dump.").
-define(DUMP_FILE_RING_CUR, "./log/ring/ring_cur.dump.").
-define(DUMP_FILE_RING_PREV, "./log/ring/ring_prv.dump.").
-define(DEF_LOG_DIR_MEMBERS, "./log/ring/").
-define(DEF_LOG_DIR_RING, "./log/ring/").
-define(DUMP_FILE_MEMBERS_CUR, "members_cur.dump.").
-define(DUMP_FILE_MEMBERS_PREV, "members_prv.dump.").
-define(DUMP_FILE_RING_CUR, "ring_cur.dump.").
-define(DUMP_FILE_RING_PREV, "ring_prv.dump.").


%% Record
Expand Down
4 changes: 3 additions & 1 deletion src/leo_redundant_manager.app.src
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
{mod, {leo_redundant_manager_app, []}},
{env, [{profile, false},
{notify_mf, [leo_manager_api, notify]},
{sync_mf, [leo_manager_api, synchronize]}
{sync_mf, [leo_manager_api, synchronize]},
{log_dir_member, "./log/ring/"},
{log_dir_ring, "./log/ring/"}
]}
]
}.
53 changes: 44 additions & 9 deletions src/leo_redundant_manager.erl
Original file line number Diff line number Diff line change
Expand Up @@ -374,10 +374,36 @@ handle_call({adjust, CurRingTable, PrevRingTable, VNodeId}, _From, State) ->


handle_call({dump, member}, _From, State) ->
Reply = case leo_redundant_manager_table_member:find_all() of
{ok, Members} ->
FileName = ?DUMP_FILE_MEMBERS ++ integer_to_list(leo_date:now()),
leo_file:file_unconsult(FileName, Members);
LogDir = case application:get_env(leo_redundant_manager,
log_dir_member) of
undefined ->
?DEF_LOG_DIR_MEMBERS;
{ok, Dir} ->
case (string:len(Dir) == string:rstr(Dir, "/")) of
true -> Dir;
false -> Dir ++ "/"
end
end,
_ = filelib:ensure_dir(LogDir),

Reply = case leo_redundant_manager_table_member:find_all(?MEMBER_TBL_CUR) of
{ok, MembersCur} ->
Path_1 = lists:append([LogDir,
?DUMP_FILE_MEMBERS_CUR,
integer_to_list(leo_date:now())]),
leo_file:file_unconsult(Path_1, MembersCur),

case leo_redundant_manager_table_member:find_all(?MEMBER_TBL_PREV) of
{ok, MembersPrev} ->
Path_2 = lists:append([LogDir,
?DUMP_FILE_MEMBERS_PREV,
integer_to_list(leo_date:now())]),
leo_file:file_unconsult(Path_2, MembersPrev);
not_found = Cause ->
{error, Cause};
Error ->
Error
end;
not_found = Cause ->
{error, Cause};
Error ->
Expand Down Expand Up @@ -672,13 +698,22 @@ get_members_1(?VER_PREV) ->
%% @doc Export 'Ring' from a table
%% @private
dump_ring_tabs() ->
_ = filelib:ensure_dir("./log/ring/"),
File0 = ?DUMP_FILE_RING_CUR ++ integer_to_list(leo_date:now()),
File1 = ?DUMP_FILE_RING_PREV ++ integer_to_list(leo_date:now()),
LogDir = case application:get_env(leo_redundant_manager, log_dir_ring) of
undefined -> ?DEF_LOG_DIR_RING;
{ok, Dir} ->
case (string:len(Dir) == string:rstr(Dir, "/")) of
true -> Dir;
false -> Dir ++ "/"
end
end,

_ = filelib:ensure_dir(LogDir),
File_1 = LogDir ++ ?DUMP_FILE_RING_CUR ++ integer_to_list(leo_date:now()),
File_2 = LogDir ++ ?DUMP_FILE_RING_PREV ++ integer_to_list(leo_date:now()),

Res0 = leo_redundant_manager_chash:export(
leo_redundant_manager_api:table_info(?VER_CURRENT), File0),
leo_redundant_manager_api:table_info(?VER_CURRENT), File_1),
Res1 = leo_redundant_manager_chash:export(
leo_redundant_manager_api:table_info(?VER_PREV), File1),
leo_redundant_manager_api:table_info(?VER_PREV), File_2),
{Res0, Res1}.

7 changes: 3 additions & 4 deletions test/leo_redundant_manager_api_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,17 @@ attach_1_({Hostname}) ->
AttachNode = list_to_atom("node_8@" ++ Hostname),
ok = leo_redundant_manager_api:attach(AttachNode),
leo_redundant_manager_api:dump(?CHECKSUM_RING),
leo_redundant_manager_api:dump(?CHECKSUM_MEMBER),

Size_2 = leo_redundant_manager_table_ring:size({ets, ?RING_TBL_CUR}),
?assertEqual((9 * ?DEF_NUMBER_OF_VNODES), Size_2),

%% execute
timer:sleep(100),
?debugVal(ok),
{ok, Res1} = leo_redundant_manager_api:rebalance(),
lists:foreach(fun(Item) ->
Src = proplists:get_value('src', Item),
Dest = proplists:get_value('dest', Item),
?debugVal({Src, Dest}),
?assertEqual(true, Src =/= Dest),
?assertEqual(true, Src =/= AttachNode)
end, Res1),
Expand Down Expand Up @@ -156,7 +155,6 @@ attach_1_1(Index) ->


attach_2_({Hostname}) ->
?debugVal(attach_2),
ok = prepare(Hostname, gateway),
{ok, _, _} = leo_redundant_manager_api:create(?VER_CURRENT),
{ok, _, _} = leo_redundant_manager_api:create(?VER_PREV),
Expand All @@ -167,13 +165,13 @@ attach_2_({Hostname}) ->
ok = leo_redundant_manager_api:attach(list_to_atom("node_9@" ++ Hostname)),
ok = leo_redundant_manager_api:attach(list_to_atom("node_10@" ++ Hostname)),
leo_redundant_manager_api:dump(?CHECKSUM_RING),
leo_redundant_manager_api:dump(?CHECKSUM_MEMBER),

RingSize = leo_redundant_manager_table_ring:size({ets, ?RING_TBL_CUR}),
?assertEqual((11 * ?DEF_NUMBER_OF_VNODES), RingSize),

%% execute
timer:sleep(100),
?debugVal(attach_2_1),
{ok, _} = leo_redundant_manager_api:rebalance(),
{ok, MembersCur, _Hashs} = leo_redundant_manager_api:create(?VER_CURRENT),
{ok, MembersPrev, Hashs} = leo_redundant_manager_api:create(?VER_PREV),
Expand Down Expand Up @@ -221,6 +219,7 @@ detach_({Hostname}) ->
DetachNode = list_to_atom("node_0@" ++ Hostname),
ok = leo_redundant_manager_api:detach(DetachNode),
leo_redundant_manager_api:dump(?CHECKSUM_RING),
leo_redundant_manager_api:dump(?CHECKSUM_MEMBER),

%% execute
{ok, Res} = leo_redundant_manager_api:rebalance(),
Expand Down

0 comments on commit 39bab36

Please sign in to comment.