Remove unnecessary branch. Also, assertion of q3's emptiness is unnecessary as the rest of the code works perfectly well even if q3 isn't empty

This commit is contained in:
Matthew Sackman 2010-10-22 12:53:46 +01:00
parent 226d9285b9
commit bbae6be610
1 changed files with 32 additions and 37 deletions

View File

@ -1298,44 +1298,39 @@ maybe_deltas_to_betas(State = #vqstate {
q3 = Q3,
index_state = IndexState,
transient_threshold = TransientThreshold }) ->
case bpqueue:is_empty(Q3) of
false ->
State;
true ->
#delta { start_seq_id = DeltaSeqId,
count = DeltaCount,
end_seq_id = DeltaSeqIdEnd } = Delta,
DeltaSeqId1 =
lists:min([rabbit_queue_index:next_segment_boundary(DeltaSeqId),
DeltaSeqIdEnd]),
{List, IndexState1} =
rabbit_queue_index:read(DeltaSeqId, DeltaSeqId1, IndexState),
{Q3a, IndexState2} = betas_from_index_entries(
List, TransientThreshold, IndexState1),
State1 = State #vqstate { index_state = IndexState2 },
case bpqueue:len(Q3a) of
#delta { start_seq_id = DeltaSeqId,
count = DeltaCount,
end_seq_id = DeltaSeqIdEnd } = Delta,
DeltaSeqId1 =
lists:min([rabbit_queue_index:next_segment_boundary(DeltaSeqId),
DeltaSeqIdEnd]),
{List, IndexState1} =
rabbit_queue_index:read(DeltaSeqId, DeltaSeqId1, IndexState),
{Q3a, IndexState2} =
betas_from_index_entries(List, TransientThreshold, IndexState1),
State1 = State #vqstate { index_state = IndexState2 },
case bpqueue:len(Q3a) of
0 ->
%% we ignored every message in the segment due to it being
%% transient and below the threshold
maybe_deltas_to_betas(
State1 #vqstate {
delta = Delta #delta { start_seq_id = DeltaSeqId1 }});
Q3aLen ->
Q3b = bpqueue:join(Q3, Q3a),
case DeltaCount - Q3aLen of
0 ->
%% we ignored every message in the segment due to
%% it being transient and below the threshold
maybe_deltas_to_betas(
State1 #vqstate {
delta = Delta #delta { start_seq_id = DeltaSeqId1 }});
Q3aLen ->
Q3b = bpqueue:join(Q3, Q3a),
case DeltaCount - Q3aLen of
0 ->
%% delta is now empty, but it wasn't
%% before, so can now join q2 onto q3
State1 #vqstate { q2 = bpqueue:new(),
delta = ?BLANK_DELTA,
q3 = bpqueue:join(Q3b, Q2) };
N when N > 0 ->
Delta1 = #delta { start_seq_id = DeltaSeqId1,
count = N,
end_seq_id = DeltaSeqIdEnd },
State1 #vqstate { delta = Delta1,
q3 = Q3b }
end
%% delta is now empty, but it wasn't before, so
%% can now join q2 onto q3
State1 #vqstate { q2 = bpqueue:new(),
delta = ?BLANK_DELTA,
q3 = bpqueue:join(Q3b, Q2) };
N when N > 0 ->
Delta1 = #delta { start_seq_id = DeltaSeqId1,
count = N,
end_seq_id = DeltaSeqIdEnd },
State1 #vqstate { delta = Delta1,
q3 = Q3b }
end
end.