Skip to content

Commit

Permalink
use uid for identity
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Valiushko committed Sep 20, 2023
1 parent 27a533b commit d854c56
Show file tree
Hide file tree
Showing 10 changed files with 200 additions and 214 deletions.
19 changes: 5 additions & 14 deletions src/ra.erl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
overview/1,
%% helpers
new_uid/1,
new_nvid/0,
%% rebalancing
transfer_leadership/2,
%% auxiliary commands
Expand Down Expand Up @@ -484,7 +483,7 @@ start_server(System, ClusterName, #{id := {_, _}} = Conf0, Machine, ServerIds)
initial_members => ServerIds,
log_init_args => #{uid => UId},
machine => Machine},
start_server(System, maps:merge(Conf0, Conf)).
start_server(System, maps:merge(Conf, Conf0)).

%% @doc Starts a ra server in the default system
%% @param Conf a ra_server_config() configuration map.
Expand Down Expand Up @@ -719,14 +718,6 @@ new_uid(Source) when is_binary(Source) ->
Prefix = ra_lib:derive_safe_string(Source, 6),
ra_lib:make_uid(string:uppercase(Prefix)).

%% @doc generates a random uid using timestamp for the first
%% 6 characters.
%% @end
new_nvid() ->
Millis = erlang:system_time(millisecond),
Prefix = base64:encode(<<Millis:32/little>>),
new_uid(Prefix).

%% @doc Returns a map of overview data of the default Ra system on the current Erlang
%% node.
%% DEPRECATED: user overview/1
Expand Down Expand Up @@ -1143,15 +1134,15 @@ key_metrics({Name, N} = ServerId) when N == node() ->
case whereis(Name) of
undefined ->
Counters#{state => noproc,
voter_status => noproc};
non_voter => noproc};
_ ->
case ets:lookup(ra_state, Name) of
[] ->
Counters#{state => unknown,
voter_status => unknown};
[{_, State, Voter}] ->
non_voter => unknown};
[{_, State, NonVoter}] ->
Counters#{state => State,
voter_status => Voter}
non_voter => NonVoter}
end
end;
key_metrics({_, N} = ServerId) ->
Expand Down
17 changes: 7 additions & 10 deletions src/ra.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -33,33 +33,30 @@
%% used for on disk resources and local name to pid mapping
-type ra_uid() :: binary().

%% Transient ID that uniquely identifies any new non-voter.
-type ra_nvid() :: binary().

%% Identifies a Ra server (node) in a Ra cluster.
%%
%% Ra servers need to be registered stable names (names that are reachable
%% after node restart). Pids are not stable in this sense.
-type ra_server_id() :: {Name :: atom(), Node :: node()}.

%% Specifies server configuration for a new cluster member.
%% Both `ra:add_member` and `ra:start_server` must be called with the same value.
%% Subset of ra_server:ra_server_config().
%% Both `ra:add_member` and `ra:start_server` must be called with the same values.
-type ra_new_server() :: #{id := ra_server_id(),

%% If set, server will start as non-voter until later promoted by the
%% leader.
non_voter_id => ra_nvid()}.
non_voter => boolean(),
uid => ra_uid()}.

-type ra_peer_status() :: normal |
{sending_snapshot, pid()} |
suspended |
disconnected.

-type ra_voter_status() :: {voter, ra_voter_state()} |
{nonvoter, ra_voter_state()}.

-type ra_voter_state() :: #{nvid => ra_nvid(),
target => ra_index()}.
-type ra_voter_status() :: #{non_voter => boolean(),
uid => ra_uid(),
target => ra_index()}.

-type ra_peer_state() :: #{next_index := non_neg_integer(),
match_index := non_neg_integer(),
Expand Down
2 changes: 1 addition & 1 deletion src/ra_directory.erl
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ overview(System) when is_atom(System) ->
pid => Pid,
parent => Parent,
state => S,
voter_status => V,
non_voter => V,
cluster_name => ClusterName,
snapshot_state => maps:get(UId, Snaps,
undefined)}}
Expand Down
Loading

0 comments on commit d854c56

Please sign in to comment.