Skip to content

Commit

Permalink
Merge pull request #556 from basho/bug/mw/repl-wm-stats-multiple-fs-s…
Browse files Browse the repository at this point in the history
…ources

Fixes wm stats crash when there are multiple fs sources.
  • Loading branch information
lordnull committed Mar 10, 2014
2 parents 318429d + 2a8d464 commit 846bf2d
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 11 deletions.
56 changes: 48 additions & 8 deletions src/riak_repl_wm_stats.erl
Original file line number Diff line number Diff line change
Expand Up @@ -157,17 +157,18 @@ jsonify_stats([{K, V}|T], Acc) when is_atom(K) and is_tuple(V)
jsonify_stats([{active, false}, {reactivation_scheduled, true} | T], Acc)
end;
jsonify_stats([{K,V}|T], Acc) when is_atom(K)
andalso (K == server_stats orelse K == client_stats) ->
case V of
[{Pid, Mq, {status, Stats}}] ->
andalso (K == server_stats orelse K == client_stats), is_list(V) ->
StackedStats = lists:foldl(fun
({Pid, Mq, {status, Stats}}, FoldAcc) ->
FormattedPid = format_pid(Pid),
NewStats = {status, lists:map(fun format_pid_stat/1, Stats)},
% could be client or server pid
ServerPid = [{pid, FormattedPid}],
jsonify_stats([NewStats | T], [Mq | [ServerPid | Acc]]);
[] ->
jsonify_stats(T, Acc)
end;
ServerPid = {pid, FormattedPid},
[ServerPid, Mq, NewStats] ++ FoldAcc;
(_, FoldAcc) ->
FoldAcc
end, [], V),
jsonify_stats(StackedStats ++ T, Acc);
jsonify_stats([{S,IP,Port}|T], Acc) when is_atom(S) andalso is_list(IP) andalso is_integer(Port) ->
jsonify_stats(T, [{S,
list_to_binary(IP++":"++integer_to_list(Port))}|Acc]);
Expand Down Expand Up @@ -392,6 +393,45 @@ jsonify_stats_test_() ->
_Result = mochijson2:encode({struct, Actual}) % fail if crash
end},

{"multiple fs client connections",
fun() ->
Pid = spawn(fun() -> ok end),
Actual = [{client_stats, [
{Pid, {message_queue_len,0}, {status, [
{node,'riak@test-riak-1'},
{site,"test3"},
{strategy,riak_repl_keylist_server},
{fullsync_worker,Pid},
{queue_pid,Pid},
{dropped_count,0},
{queue_length,0},
{queue_byte_size,0},
{queue_max_size,104857600},
{queue_percentage,0},
{queue_pending,0},
{queue_max_pending,5},
{state,wait_for_partition}
]}},
{Pid, {message_queue_len,0}, {status, [
{node,'riak@test-riak-1'},
{site,"site2"},
{strategy,riak_repl_keylist_server},
{fullsync_worker,Pid},
{queue_pid,Pid},
{dropped_count,0},
{queue_length,0},
{queue_byte_size,0},
{queue_max_size,104857600},
{queue_percentage,0},
{queue_pending,0},
{queue_max_pending,5},
{state,wait_for_partition}
]}}
]}],
Jsonified = jsonify_stats(Actual, []),
_ = mochijson2:encode({struct, Jsonified})
end},

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% tests during basho bench, bnw fullsync, 1.2 + 1.3 realtime, source side

Expand Down
4 changes: 2 additions & 2 deletions test/riak_core_cluster_mgr_sup_tests.erl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-module(riak_core_cluster_mgr_sup_tests).
-compile(export_all).
-ifdef(EQC).
-include_lib("riak_core/include/riak_core_connection.hrl").
-ifdef(TEST).
-include("riak_core_connection.hrl").
-include_lib("eunit/include/eunit.hrl").

murdering_test_() ->
Expand Down
2 changes: 1 addition & 1 deletion test/riak_core_cluster_mgr_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
-compile(export_all).

-include("riak_core_cluster.hrl").
-include_lib("riak_core/include/riak_core_connection.hrl").
-include("riak_core_connection.hrl").
-include_lib("eunit/include/eunit.hrl").

-define(TRACE(Stmt),Stmt).
Expand Down

0 comments on commit 846bf2d

Please sign in to comment.