Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion src/ered_cluster.erl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3]).
terminate/2, code_change/3, format_status/1]).


-export_type([cluster_ref/0,
Expand Down Expand Up @@ -590,6 +590,19 @@ terminate(Reason, State) ->
code_change(_OldVsn, State = #st{}, _Extra) ->
{ok, State}.

format_status(Status) ->
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This just affects OTP25+ I guess, but thats fine.
format_status(Status) (since OTP 25.0) (optional)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it will just be ignored on OTP < 25.

maps:map(
fun (state, State) ->
%% Convert record to map.
Fields = record_info(fields, st),
[st | Values] = tuple_to_list(State),
StateMap = maps:from_list(lists:zip(Fields, Values)),
%% Replace the huge slots binary with a readable representation.
maps:update(slots, format_slotmap(State#st.slots), StateMap);
(_, Value) ->
Value
end, Status).

%%%===================================================================
%%% Internal functions
%%%===================================================================
Expand Down Expand Up @@ -948,6 +961,26 @@ all_slots_covered(State) ->
%% check so last slot is ok
R == 16384.

%% A more readable representation of the large binary slot map for use in crash
%% reports. Input: <<1,1,1,...,2,2,2,...,3,3,3>>. Returns a list of ranges on
%% the form [{{0, 5000}, 1}, {{5001, 10000}, 2}, {{10001, 16383}, 3}].
format_slotmap(Binary) ->
format_slotmap_helper(Binary, 0, []).

format_slotmap_helper(Binary, I, Acc) when I >= byte_size(Binary) ->
lists:reverse(Acc);
format_slotmap_helper(Binary, I, [{{From, To}, PrevValue} | Acc]) ->
NewAcc = case binary:at(Binary, I) of
PrevValue ->
[{{From, I}, PrevValue} | Acc];
OtherValue ->
[{{I, I}, OtherValue}, {{From, To}, PrevValue} | Acc]
end,
format_slotmap_helper(Binary, I + 1, NewAcc);
format_slotmap_helper(Binary, 0, []) ->
FirstValue = binary:at(Binary, 0),
format_slotmap_helper(Binary, 1, [{{0, 0}, FirstValue}]).

check_replica_count(#st{min_replicas = 0}) ->
true;
check_replica_count(State) ->
Expand Down
Loading