Skip to content

Commit 474d76f

Browse files
Merge pull request #12358 from rabbitmq/qq-release-cursor-bug
QQ: fix off-by-one bug in release cursor effects.
2 parents bf4d573 + 2ae4dbe commit 474d76f

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

deps/rabbit/src/rabbit_fifo.erl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,7 +1064,7 @@ handle_aux(_RaState, cast, tick, #?AUX{name = Name,
10641064
undefined ->
10651065
[{release_cursor, ra_aux:last_applied(RaAux)}];
10661066
Smallest ->
1067-
[{release_cursor, Smallest}]
1067+
[{release_cursor, Smallest - 1}]
10681068
end,
10691069
{no_reply, Aux, RaAux, Effs};
10701070
handle_aux(_RaState, cast, eol, #?AUX{name = Name} = Aux, RaAux) ->
@@ -2915,7 +2915,10 @@ release_cursor(LastSmallest, Smallest)
29152915
when is_integer(LastSmallest) andalso
29162916
is_integer(Smallest) andalso
29172917
Smallest > LastSmallest ->
2918-
[{release_cursor, Smallest}];
2918+
[{release_cursor, Smallest - 1}];
2919+
release_cursor(undefined, Smallest)
2920+
when is_integer(Smallest) ->
2921+
[{release_cursor, Smallest - 1}];
29192922
release_cursor(_, _) ->
29202923
[].
29212924

deps/rabbit/test/rabbit_fifo_SUITE.erl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2347,6 +2347,31 @@ aux_test(_) ->
23472347
?assert(X > 0.0),
23482348
ok.
23492349

2350+
handle_aux_tick_test(Config) ->
2351+
_ = ra_machine_ets:start_link(),
2352+
Aux0 = init_aux(aux_test),
2353+
LastApplied = 1,
2354+
MacState0 = init(#{name => ?FUNCTION_NAME,
2355+
queue_resource => rabbit_misc:r("/", queue, ?FUNCTION_NAME_B),
2356+
single_active_consumer_on => false}),
2357+
State0 = #{machine_state => MacState0,
2358+
log => mock_log,
2359+
last_applied => LastApplied},
2360+
{MacState1, _} = enq(Config, 1, 1, first, MacState0),
2361+
State1 = State0#{machine_state => MacState1},
2362+
meck:expect(ra_log, last_index_term, fun (_) -> {1, 0} end),
2363+
?assertEqual(1, rabbit_fifo:smallest_raft_index(MacState1)),
2364+
%% the release cursor should be 1 lower than the smallest raft index
2365+
{no_reply, _, _,
2366+
[{release_cursor, 0}]} = handle_aux(leader, cast, tick, Aux0, State1),
2367+
timer:sleep(10),
2368+
2369+
persistent_term:put(quorum_queue_checkpoint_config, {1, 0, 1}),
2370+
{no_reply, _, _,
2371+
[{checkpoint, 1, _},
2372+
{release_cursor, 0}]} = handle_aux(follower, cast, force_checkpoint, Aux0, State1),
2373+
ok.
2374+
23502375

23512376
%% machine version conversion test
23522377

0 commit comments

Comments
 (0)