diff --git a/src/ra_aux.erl b/src/ra_aux.erl index 080b9523..023ab5c5 100644 --- a/src/ra_aux.erl +++ b/src/ra_aux.erl @@ -49,13 +49,14 @@ log_last_index_term(#{log := Log}) -> log_fetch(Idx, #{log := Log0} = State) when is_integer(Idx) -> case ra_log:fetch(Idx, Log0) of - {undefined, Log} -> - {undefined, State#{log => Log}}; - {{Idx, Term, {_Tag, Meta, Cmd, _ReplyMode}}, Log} -> - {{Term, Meta, Cmd}, State#{log => Log}} + {{Idx, Term, {'$usr', Meta, Cmd, _ReplyMode}}, Log} -> + {{Term, Meta, Cmd}, State#{log => Log}}; + {_, Log} -> + %% we only allow usr commands to be read + {undefined, State#{log => Log}} end. -%% TODO: refine this? also included in overview +-spec log_stats(ra_aux:state()) -> ra_log:overview(). log_stats(#{log := Log}) -> ra_log:overview(Log). diff --git a/src/ra_log.erl b/src/ra_log.erl index db7f6350..cc20a23a 100644 --- a/src/ra_log.erl +++ b/src/ra_log.erl @@ -127,13 +127,25 @@ counter => counters:counters_ref(), initial_access_pattern => sequential | random}. + +-type overview() :: + #{type := ra_log, + last_index := ra_index(), + first_index := ra_index(), + last_written_index_term := ra_idxterm(), + num_segments := non_neg_integer(), + open_segments => non_neg_integer(), + snapshot_index => undefined | ra_index(), + cache_size => non_neg_integer()}. + -export_type([state/0, ra_log_init_args/0, ra_meta_key/0, segment_ref/0, event/0, event_body/0, - effect/0 + effect/0, + overview/0 ]). pre_init(#{uid := UId, @@ -785,7 +797,7 @@ exists({Idx, Term}, Log0) -> {false, Log} end. --spec overview(state()) -> map(). +-spec overview(state()) -> overview(). overview(#?MODULE{last_index = LastIndex, first_index = FirstIndex, last_written_index_term = LWIT, diff --git a/test/ra_machine_int_SUITE.erl b/test/ra_machine_int_SUITE.erl index 526c2c5a..1094f8de 100644 --- a/test/ra_machine_int_SUITE.erl +++ b/test/ra_machine_int_SUITE.erl @@ -712,13 +712,16 @@ aux_command_v1_and_v2(Config) -> (_RaftState, cast, eval, AuxState, Opaque) -> %% replaces aux state {no_reply, AuxState, Opaque}; - (_RaftState, cast, NewState, _AuxState, Opaque) -> + (_RaftState, cast, NewState, _AuxState, Opaque0) -> + {Idx, _} = ra_aux:log_last_index_term(Opaque0), + {{_Term, _Meta, apple}, Opaque} = ra_aux:log_fetch(Idx, Opaque0), %% replaces aux state {no_reply, NewState, Opaque} end), ok = start_cluster(ClusterName, {module, Mod, #{}}, Cluster), {ok, _, Leader} = ra:members(ServerId1), + {ok, _, _} = ra:process_command(Leader, apple), ok = ra:cast_aux_command(Leader, banana), {leader, banana} = ra:aux_command(Leader, emit), [ServerId2, ServerId3] = Cluster -- [Leader],