42 lines
1.1 KiB
Go
42 lines
1.1 KiB
Go
package provider
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"time"
|
|
)
|
|
|
|
var (
|
|
ErrInvalidCoordination = errors.New("invalid provider coordination")
|
|
ErrCoordinationUnavailable = errors.New("provider coordination unavailable")
|
|
ErrLeadershipLost = errors.New("provider leadership lost")
|
|
ErrLeaderWorkStopped = errors.New("provider leader work stopped")
|
|
)
|
|
|
|
type CoordinationLimits struct {
|
|
RequestInterval time.Duration
|
|
MaxInFlight int
|
|
MaxAttemptDuration time.Duration
|
|
}
|
|
|
|
type Fence struct {
|
|
Generation string
|
|
Epoch uint64
|
|
}
|
|
|
|
type Coordinator interface {
|
|
// RunLeader waits for leadership and runs work only while its fencing lease
|
|
// is valid. The work context is canceled before a known lease expiry.
|
|
RunLeader(context.Context, string, CoordinationLimits, func(context.Context, LeaderSession) error) error
|
|
}
|
|
|
|
type LeaderSession interface {
|
|
Fence() Fence
|
|
AcquireFetch(context.Context) (RequestPermit, error)
|
|
}
|
|
|
|
type RequestPermit interface {
|
|
// Release is idempotent. A failed release expires automatically in storage.
|
|
Release(context.Context) error
|
|
}
|