Skip to content

Commit

Permalink
Count commands received with invalid reply-modes
Browse files Browse the repository at this point in the history
  • Loading branch information
the-mikedavis committed Oct 19, 2022
1 parent 20ba89c commit be203b9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/ra.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@
-define(C_RA_SRV_AER_RECEIVED_FOLLOWER_EMPTY, ?C_RA_LOG_RESERVED + 17).
-define(C_RA_SRV_TERM_AND_VOTED_FOR_UPDATES, ?C_RA_LOG_RESERVED + 18).
-define(C_RA_SRV_LOCAL_QUERIES, ?C_RA_LOG_RESERVED + 19).
-define(C_RA_SRV_INVALID_REPLY_MODE_COMMANDS, ?C_RA_LOG_RESERVED + 20).


-define(RA_SRV_COUNTER_FIELDS,
Expand Down Expand Up @@ -294,7 +295,9 @@
{term_and_voted_for_updates, ?C_RA_SRV_TERM_AND_VOTED_FOR_UPDATES, counter,
"Total number of updates of term and voted for"},
{local_queries, ?C_RA_SRV_LOCAL_QUERIES, counter,
"Total number of local queries"}
"Total number of local queries"},
{invalid_reply_mode_commands, ?C_RA_SRV_INVALID_REPLY_MODE_COMMANDS, counter,
"Total number of commands received with an invalid reply-mode"}
]).

-define(RA_COUNTER_FIELDS, ?RA_LOG_COUNTER_FIELDS ++ ?RA_SRV_COUNTER_FIELDS).
6 changes: 4 additions & 2 deletions src/ra_server_proc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ leader(EventType, {local_call, Msg}, State) ->
leader(EventType, {leader_cast, Msg}, State) ->
leader(EventType, Msg, State);
leader(EventType, {command, normal, {CmdType, Data, ReplyMode}},
#state{server_state = ServerState0} = State0) ->
#state{conf = Conf, server_state = ServerState0} = State0) ->
case validate_reply_mode(ReplyMode) of
ok ->
%% normal priority commands are written immediately
Expand All @@ -365,6 +365,7 @@ leader(EventType, {command, normal, {CmdType, Data, ReplyMode}},
State0#state{server_state = ServerState}),
{keep_state, State, Actions};
Error ->
ok = incr_counter(Conf, ?C_RA_SRV_INVALID_REPLY_MODE_COMMANDS, 1),
case EventType of
{call, From} ->
{keep_state, State0, [{reply, From, Error}]};
Expand All @@ -373,7 +374,7 @@ leader(EventType, {command, normal, {CmdType, Data, ReplyMode}},
end
end;
leader(EventType, {command, low, {CmdType, Data, ReplyMode}},
#state{delayed_commands = Delayed} = State0) ->
#state{conf = Conf, delayed_commands = Delayed} = State0) ->
case validate_reply_mode(ReplyMode) of
ok ->
%% cache the low priority command until the flush_commands message
Expand All @@ -395,6 +396,7 @@ leader(EventType, {command, low, {CmdType, Data, ReplyMode}},
State = State0#state{delayed_commands = queue:in(Cmd, Delayed)},
{keep_state, State, []};
Error ->
ok = incr_counter(Conf, ?C_RA_SRV_INVALID_REPLY_MODE_COMMANDS, 1),
case EventType of
{call, From} ->
{keep_state, State0, [{reply, From, Error}]};
Expand Down

0 comments on commit be203b9

Please sign in to comment.