feat: add consumer reset to specific sequence (Gap 3.12)

Add ResetToSequence to ConsumerManager that updates NextSequence,
clears AckProcessor state via new ClearAll(), and zeroes PendingBytes.
Add AckProcessor.SetAckFloor() that prunes pending entries below the
new floor. Go reference: consumer.go:4241 processResetReq.
This commit is contained in:
Joseph Doherty
2026-02-25 11:15:33 -05:00
parent b9aa62ae99
commit 778687cf6f
3 changed files with 292 additions and 0 deletions

View File

@@ -225,6 +225,28 @@ public sealed class ConsumerManager : IDisposable
return true;
}
/// <summary>
/// Resets a consumer's position to the specified sequence.
/// Clears pending acks and redelivery state.
/// Go reference: consumer.go:4241 processResetReq.
/// </summary>
public bool ResetToSequence(string stream, string durableName, ulong sequence)
{
if (!_consumers.TryGetValue((stream, durableName), out var handle))
return false;
// Update the consumer's next sequence
handle.NextSequence = sequence;
// Clear pending acks — all outstanding acks are invalid after reset
handle.AckProcessor.ClearAll();
// Clear pending bytes
handle.PendingBytes = 0;
return true;
}
public bool Unpin(string stream, string durableName)
{
return _consumers.ContainsKey((stream, durableName));

View File

@@ -294,6 +294,32 @@ public sealed class AckProcessor
_pending.Remove(sequence);
}
/// <summary>
/// Clears all pending acks, terminated set, and resets the ack floor.
/// Used during consumer reset to specific sequence.
/// Go reference: consumer.go processResetReq — clear all tracking state.
/// </summary>
public void ClearAll()
{
_pending.Clear();
_terminated.Clear();
AckFloor = 0;
TerminatedCount = 0;
_exceededSequences.Clear();
}
/// <summary>
/// Resets the ack floor to the specified value.
/// Used during consumer reset.
/// </summary>
public void SetAckFloor(ulong floor)
{
AckFloor = floor;
// Remove any pending entries below or at the new floor
foreach (var key in _pending.Keys.Where(k => k <= floor).ToArray())
_pending.Remove(key);
}
public bool HasPending => _pending.Count > 0;
public int PendingCount => _pending.Count;