Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rabbitmq/ra
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.7.0-pre.2
Choose a base ref
...
head repository: rabbitmq/ra
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.7.0-pre.3
Choose a head ref
  • 10 commits
  • 16 files changed
  • 4 contributors

Commits on Aug 22, 2023

  1. Copy the full SHA
    209bad2 View commit details

Commits on Sep 13, 2023

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    ae2a716 View commit details
  2. Merge pull request #391 from rabbitmq/use-seshat-from-bcr

    Use seshat from bazel-central-registry
    HoloRin authored Sep 13, 2023
    Copy the full SHA
    4f78a33 View commit details

Commits on Sep 14, 2023

  1. Fixup release.yaml workflow triggering

    If the release is created with the regular token, it won't cascade
    HoloRin committed Sep 14, 2023
    Copy the full SHA
    a67f2e6 View commit details

Commits on Sep 16, 2023

  1. Update supported Erlang versions

    to reflect what targets the team cares about.
    michaelklishin authored Sep 16, 2023
    Copy the full SHA
    6e41f0d View commit details

Commits on Sep 19, 2023

  1. Adjust triggering for the erlang.yml workflow

    so that tests are run for external PRs
    HoloRin committed Sep 19, 2023
    Copy the full SHA
    99de2ca View commit details
  2. Merge pull request #397 from rabbitmq/update-actions-triggering-for-prs

    Adjust triggering for the erlang.yml workflow
    HoloRin authored Sep 19, 2023
    Copy the full SHA
    08bfcc4 View commit details

Commits on Sep 25, 2023

  1. Non-voters and automatic promotion (#375)

    * Newly added followers do not participate in quorum until they catch up with the log
    
    An opt-in ability of a cluster to ignore newly joined member until it catches
    up with the log:
    
    UId = ra:new_uid(ClusterName),
    New = #{id => Id, membership => promotable, uid => UId},
    ok = ra:start_server(default, ClusterName, New, add_machine(), [ServerRef]),
    {ok, _, _} = ra:add_member(ServerRef, New),
    
    Voter status is stored in the cluster map of the server state and is part of
    every $ra_cluster_change. Additionally, nodes store their own status at the top
    level for ease of matching. Nodes also store their own status in ra_state ETS
    table (breaking change), and present in overview.
    
    On every #append_entries_reply leader may choose to promote non-voter by
    issuing new `$ra_join` with desired voter status. Currently, only one promotion
    condition is implemented `{nonvoter, #{target := ra_index()}`. Non-voter will
    be promoted when it reaches the leaders log index at the time of joining.
    illotum authored Sep 25, 2023
    Copy the full SHA
    2863dbb View commit details
  2. v2.7.0-pre.3

    kjnilsson committed Sep 25, 2023
    Copy the full SHA
    6c85529 View commit details
  3. 2.7.0-pre.3

    kjnilsson committed Sep 25, 2023
    Copy the full SHA
    812a249 View commit details
Showing with 830 additions and 88 deletions.
  1. +5 −1 .github/workflows/erlang.yml
  2. +1 −0 .github/workflows/release.yml
  3. +7 −7 MODULE.bazel
  4. +1 −1 README.md
  5. +1 −1 src/ra.app.src
  6. +20 −15 src/ra.erl
  7. +23 −2 src/ra.hrl
  8. +8 −2 src/ra_directory.erl
  9. +3 −1 src/ra_log.erl
  10. +181 −19 src/ra_server.erl
  11. +32 −7 src/ra_server_proc.erl
  12. +144 −6 test/coordination_SUITE.erl
  13. +43 −0 test/ra_2_SUITE.erl
  14. +95 −1 test/ra_SUITE.erl
  15. +237 −25 test/ra_server_SUITE.erl
  16. +29 −0 test/ra_snapshot_SUITE.erl
6 changes: 5 additions & 1 deletion .github/workflows/erlang.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
name: Test
on: push
on:
push:
branches:
- main
pull_request:
jobs:
build:
runs-on: ubuntu-20.04
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -46,6 +46,7 @@ jobs:
id: create-release
uses: ncipollo/release-action@v1.12.0
with:
token: ${{ secrets.REPO_SCOPED_TOKEN }}
allowUpdates: true
artifactErrorsFailBuild: true
updateOnlyUnreleased: true
14 changes: 7 additions & 7 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
module(
name = "rabbitmq_ra",
version = "2.7.0-pre.2",
version = "2.7.0-pre.3",
)

bazel_dep(
name = "rules_erlang",
version = "3.11.4",
)

bazel_dep(
name = "rabbitmq_seshat",
version = "0.6.1",
repo_name = "seshat",
)

erlang_config = use_extension(
"@rules_erlang//bzlmod:extensions.bzl",
"erlang_config",
@@ -70,19 +76,13 @@ erlang_package.git_package(
branch = "master",
)

erlang_package.hex_package(
name = "seshat",
version = "0.6.0",
)

use_repo(
erlang_package,
"aten",
"gen_batch_server",
"inet_tcp_proxy_dist",
"meck",
"proper",
"seshat",
)

erlang_dev_package = use_extension(
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -37,8 +37,8 @@ distributed system verification framework.

Ra supports the following Erlang/OTP versions:

* `26.x`
* `25.x`
* `24.x`

Modern Erlang releases provide [distribution traffic fragmentation](https://www.erlang.org/blog/otp-22-highlights/#fragmented-distribution-messages)
which algorithms such as Raft significantly benefit from.
2 changes: 1 addition & 1 deletion src/ra.app.src
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{application,ra,
[{description,"Raft library"},
{vsn,"2.7.0-pre.2"},
{vsn,"2.7.0-pre.3"},
{licenses,["Apache-2.0","MPL-2.0"]},
{links,[{"github","https://github.com/rabbitmq/ra"}]},
{modules,[]},
35 changes: 20 additions & 15 deletions src/ra.erl
Original file line number Diff line number Diff line change
@@ -455,7 +455,7 @@ start_cluster(System, [#{cluster_name := ClusterName} | _] = ServerConfigs,

%% @doc Starts a new distributed ra cluster.
%% @param ClusterName the name of the cluster.
%% @param ServerId the ra_server_id() of the server
%% @param ServerId the ra_server_id() of the server, or a map with server id and settings.
%% @param Machine The {@link ra_machine:machine/0} configuration.
%% @param ServerIds a list of initial (seed) server configurations
%% @returns
@@ -470,19 +470,21 @@ start_cluster(System, [#{cluster_name := ClusterName} | _] = ServerConfigs,
%% forcefully deleted.
%% @see start_server/1
%% @end
-spec start_server(atom(), ra_cluster_name(), ra_server_id(),
-spec start_server(atom(), ra_cluster_name(), ra_server_id() | ra_new_server(),
ra_server:machine_conf(), [ra_server_id()]) ->
ok | {error, term()}.
start_server(System, ClusterName, {_, _} = ServerId, Machine, ServerIds)
start_server(System, ClusterName, {_, _} = ServerId, Machine, ServerIds) ->
start_server(System, ClusterName, #{id => ServerId}, Machine, ServerIds);
start_server(System, ClusterName, #{id := {_, _}} = Conf0, Machine, ServerIds)
when is_atom(System) ->
UId = new_uid(ra_lib:to_binary(ClusterName)),
UId = maps:get(uid, Conf0,
new_uid(ra_lib:to_binary(ClusterName))),
Conf = #{cluster_name => ClusterName,
id => ServerId,
uid => UId,
initial_members => ServerIds,
log_init_args => #{uid => UId},
machine => Machine},
start_server(System, Conf).
start_server(System, maps:merge(Conf0, Conf)).

%% @doc Starts a ra server in the default system
%% @param Conf a ra_server_config() configuration map.
@@ -558,9 +560,10 @@ delete_cluster(ServerIds, Timeout) ->
%% affect said cluster's availability characteristics (by increasing quorum node count).
%%
%% @param ServerLoc the ra server or servers to try to send the command to
%% @param ServerId the ra server id of the new server.
%% @param ServerId the ra server id of the new server, or a map with server id and settings.
%% @end
-spec add_member(ra_server_id() | [ra_server_id()], ra_server_id()) ->
-spec add_member(ra_server_id() | [ra_server_id()],
ra_server_id() | ra_new_server()) ->
ra_cmd_ret() |
{error, already_member} |
{error, cluster_change_not_permitted}.
@@ -571,7 +574,8 @@ add_member(ServerLoc, ServerId) ->
%% @see add_member/2
%% @end
-spec add_member(ra_server_id() | [ra_server_id()],
ra_server_id(), timeout()) ->
ra_server_id() | ra_new_server(),
timeout()) ->
ra_cmd_ret() |
{error, already_member} |
{error, cluster_change_not_permitted}.
@@ -580,7 +584,6 @@ add_member(ServerLoc, ServerId, Timeout) ->
{'$ra_join', ServerId, after_log_append},
Timeout).


%% @doc Removes a server from the cluster's membership configuration.
%% This function returns after appending a cluster membership change
%% command to the log.
@@ -716,7 +719,6 @@ new_uid(Source) when is_binary(Source) ->
Prefix = ra_lib:derive_safe_string(Source, 6),
ra_lib:make_uid(string:uppercase(Prefix)).


%% @doc Returns a map of overview data of the default Ra system on the current Erlang
%% node.
%% DEPRECATED: user overview/1
@@ -1132,13 +1134,16 @@ key_metrics({Name, N} = ServerId) when N == node() ->
end,
case whereis(Name) of
undefined ->
Counters#{state => noproc};
Counters#{state => noproc,
membership => unknown};
_ ->
case ets:lookup(ra_state, Name) of
[] ->
Counters#{state => unknown};
[{_, State}] ->
Counters#{state => State}
Counters#{state => unknown,
membership => unknown};
[{_, State, Membership}] ->
Counters#{state => State,
membership => Membership}
end
end;
key_metrics({_, N} = ServerId) ->
25 changes: 23 additions & 2 deletions src/ra.hrl
Original file line number Diff line number Diff line change
@@ -39,24 +39,45 @@
%% 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.
%% 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(),
% Defaults to `voter` if absent.
membership => ra_membership(),
% Required for `promotable` in the above.
uid => ra_uid()}.

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

-type ra_membership() :: voter | promotable | non_voter | unknown.

-type ra_voter_status() :: #{membership => ra_membership(),
uid => ra_uid(),
target => ra_index()}.

-type ra_peer_state() :: #{next_index := non_neg_integer(),
match_index := non_neg_integer(),
query_index := non_neg_integer(),
% the commit index last sent
% used for evaluating pipeline status
commit_index_sent := non_neg_integer(),
%% Whether the peer is part of the consensus.
%% Defaults to "yes" if absent.
voter_status => ra_voter_status(),
%% indicates that a snapshot is being sent
%% to the peer
status := ra_peer_status()}.

-type ra_cluster() :: #{ra_server_id() => ra_peer_state()}.

-type ra_cluster_servers() :: [ra_server_id()].
%% Dehydrated cluster:
-type ra_cluster_servers() :: [ra_server_id()]. % Deprecated
-type ra_peer_snapshot() :: #{voter_status => ra_voter_status()}.
-type ra_cluster_snapshot() :: #{ra_server_id() => ra_peer_snapshot()}.

%% represent a unique entry in the ra log
-type log_entry() :: {ra_index(), ra_term(), term()}.
@@ -138,7 +159,7 @@

-type snapshot_meta() :: #{index := ra_index(),
term := ra_term(),
cluster := ra_cluster_servers(),
cluster := ra_cluster_snapshot(),
machine_version := ra_machine:version()}.

-record(install_snapshot_rpc,
10 changes: 8 additions & 2 deletions src/ra_directory.erl
Original file line number Diff line number Diff line change
@@ -175,14 +175,20 @@ overview(System) when is_atom(System) ->
#{directory := Tbl,
directory_rev := _TblRev} = get_names(System),
Dir = ets:tab2list(Tbl),
States = maps:from_list(ets:tab2list(ra_state)),
Rows = lists:map(fun({K, S, V}) ->
{K, {S, V}}
end,
ets:tab2list(ra_state)),
States = maps:from_list(Rows),
Snaps = maps:from_list(ets:tab2list(ra_log_snapshot_state)),
lists:foldl(fun ({UId, Pid, Parent, ServerName, ClusterName}, Acc) ->
{S, V} = maps:get(ServerName, States, {undefined, undefined}),
Acc#{ServerName =>
#{uid => UId,
pid => Pid,
parent => Parent,
state => maps:get(ServerName, States, undefined),
state => S,
membership => V,
cluster_name => ClusterName,
snapshot_state => maps:get(UId, Snaps,
undefined)}}
4 changes: 3 additions & 1 deletion src/ra_log.erl
Original file line number Diff line number Diff line change
@@ -637,7 +637,9 @@ update_release_cursor0(Idx, Cluster, MacVersion, MacState,
#?MODULE{cfg = #cfg{snapshot_interval = SnapInter},
reader = Reader,
snapshot_state = SnapState} = State0) ->
ClusterServerIds = maps:keys(Cluster),
ClusterServerIds = maps:map(fun (_, V) ->
maps:with([voter_status], V)
end, Cluster),
SnapLimit = case ra_snapshot:current(SnapState) of
undefined -> SnapInter;
{I, _} -> I + SnapInter
Loading