Skip to content

Commit

Permalink
Ensure cluster_index_term is updated after snapshot installation.
Browse files Browse the repository at this point in the history
If the snapshot contained a member change it may not update
the leaderboard correctly.
  • Loading branch information
kjnilsson committed Jul 11, 2024
1 parent 2fbb7a3 commit b4f4e93
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/ra_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1384,6 +1384,9 @@ handle_receive_snapshot(#install_snapshot_rpc{term = Term,
log => Log,
commit_index => SnapIndex,
last_applied => SnapIndex,
%% this may not be the actual cluster index
cluster_index_term => {SnapIndex,
SnapTerm},
cluster => make_cluster(Id, ClusterIds),
membership => get_membership(ClusterIds, State0),
machine_state => MacState}),
Expand Down
1 change: 1 addition & 0 deletions src/ra_server_sup_sup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ delete_server_rpc(System, RaName) ->
catch ets:delete(ra_state, RaName),
catch ets:delete(ra_open_file_metrics, Pid),
catch ra_counters:delete({RaName, node()}),
catch ra_leaderboard:clear(RaName),
ok
end.

Expand Down
4 changes: 4 additions & 0 deletions test/ra_2_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,13 @@ server_is_force_deleted(Config) ->
% force roll over
ok = force_roll_over(),
Pid = ra_directory:where_is(?SYS, UId),
{Name, _} = ServerId,
?assertEqual(ServerId, ra_leaderboard:lookup_leader(Name)),
ok = ra:force_delete_server(?SYS, ServerId),

validate_ets_table_deletes([UId], [Pid], [ServerId]),
?assertEqual(undefined, ra_leaderboard:lookup_leader(Name)),
ct:pal("ra_leaderboard overview ~p", [ra_leaderboard:overview()]),
% start a node with the same nodeid but different uid
% simulating the case where a queue got deleted then re-declared shortly
% afterwards
Expand Down
1 change: 1 addition & 0 deletions test/ra_server_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1489,6 +1489,7 @@ follower_install_snapshot_machine_version(_Config) ->
effective_machine_module = MacMod1,
effective_machine_version = 1},
last_applied := 4,
cluster_index_term := {4, 5},
machine_state := SnapData, %% old machine state
commit_index := 4},
_} = ra_server:handle_receive_snapshot(ISR, State0),
Expand Down

0 comments on commit b4f4e93

Please sign in to comment.