You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor: Improve Flow Control queue contracts for clarity and correctness (#1836)
* refactor: Simplify SafeQueue interface
This commit refactors the `framework.SafeQueue` interface to remove
error returns from methods where failure is not expected in normal
operation (Add, PeekHead, PeekTail, Drain, Cleanup).
The interface now relies on the following premises:
- Queues are unbounded and in-memory.
- OOM is a panic, not a handled error.
- Internal callers are trusted not to provide nil items.
- PeekHead/PeekTail return nil for empty queues.
This change simplifies the interface and reduces unnecessary error
checking on the hot path.
This commit updates the queue implementations (ListQueue, MaxMinHeap),
mocks, and all callers within the `pkg/epp/flowcontrol/framework/...`
tree to conform to the new interface.
A subsequent commit will address callers outside this tree.
* refactor: Decouple ManagedQueue from SafeQueue
This commit refactors the `ManagedQueue` contract after the preceding
commit which altered the `SafeQueue` contract.
Motivation: The preceding commit made the generic
`framework.SafeQueue.Add` method infallible. This created a design
conflict, as the higher-level `ManagedQueue` decorator requires a
*fallible* `Add` operation to atomically reject requests when its parent
shard is draining.
This commit addresses this by refactoring `ManagedQueue` to
favor composition over embedding:
- `ManagedQueue` no longer embeds `SafeQueue`; it now contains it as a
field, correctly modeling the "has-a" relationship.
- The `ManagedQueue.Add` method now has its own explicit, fallible
contract, returning `contracts.ErrShardDraining`.
- The `Remove` and `Cleanup` operations follow the new, simpler
`SafeQueue` contract.
This change also includes the necessary updates to all callers in the
`controller` and `registry` packages to conform to these new, more
robust contracts as well as updating tests and mocks.
0 commit comments