Coordinate retry attempts with backend permits

This commit is contained in:
2026-09-23 16:48:36 +00:00
parent 65d5894648
commit ae4540822e
10 changed files with 541 additions and 4 deletions

View File

@@ -107,6 +107,23 @@ func (m *Manager) getPool(backendID string) *pool {
return m.pools[backendID]
}
// Acquire obtains one active-generation permit for a backend. Its release
// function is idempotent. Backends without a configured pool are unlimited.
func (m *Manager) Acquire(ctx context.Context, backendID string) (func(), error) {
if err := ctx.Err(); err != nil {
return nil, err
}
pool := m.getPool(backendID)
if pool == nil {
return releaseNothing, nil
}
if err := pool.acquire(ctx); err != nil {
return nil, err
}
var once sync.Once
return func() { once.Do(pool.releaseActive) }, nil
}
func (p *pool) acquire(ctx context.Context) error {
p.mu.Lock()
if err := ctx.Err(); err != nil {