123 lines
3.7 KiB
Go
123 lines
3.7 KiB
Go
package workerruntime
|
|
|
|
import (
|
|
"context"
|
|
"crypto/sha256"
|
|
"errors"
|
|
"time"
|
|
)
|
|
|
|
var (
|
|
ErrInvalidStore = errors.New("invalid worker runtime store")
|
|
ErrInvalidSession = errors.New("invalid worker runtime session")
|
|
ErrInvalidReport = errors.New("invalid worker runtime report")
|
|
ErrInvalidQuery = errors.New("invalid worker runtime query")
|
|
ErrStaleSession = errors.New("stale worker runtime session")
|
|
ErrStaleReport = errors.New("stale worker runtime report")
|
|
ErrConflictingReport = errors.New("conflicting worker runtime report")
|
|
ErrInvalidSnapshotReference = errors.New("invalid worker snapshot reference")
|
|
ErrInvalidAcknowledgement = errors.New("invalid worker snapshot acknowledgement")
|
|
ErrSnapshotMismatch = errors.New("worker snapshot does not match acknowledged state")
|
|
ErrStaleSnapshotReference = errors.New("stale worker snapshot reference")
|
|
ErrConflictingSnapshotReference = errors.New("conflicting worker snapshot reference")
|
|
ErrStaleAcknowledgement = errors.New("stale worker snapshot acknowledgement")
|
|
ErrInvalidOutcome = errors.New("invalid worker outcome reference")
|
|
ErrStaleOutcome = errors.New("stale worker outcome sequence")
|
|
ErrConflictingOutcome = errors.New("conflicting worker outcome sequence")
|
|
)
|
|
|
|
type Session struct {
|
|
WorkerID string
|
|
InstanceID string
|
|
SessionID string
|
|
Zone string
|
|
ProtocolVersion uint32
|
|
Labels map[string]string
|
|
AckedSnapshotVersion uint64
|
|
AckedOwnershipEpoch uint64
|
|
AckedChecksum [sha256.Size]byte
|
|
RuntimeEnabled bool
|
|
}
|
|
|
|
type SnapshotReference struct {
|
|
WorkerID string
|
|
Version uint64
|
|
OwnershipEpoch uint64
|
|
Checksum [sha256.Size]byte
|
|
}
|
|
|
|
type SnapshotAcknowledgement struct {
|
|
WorkerID string
|
|
SessionID string
|
|
Reference SnapshotReference
|
|
Applied bool
|
|
ErrorCode string
|
|
}
|
|
|
|
type Counter struct {
|
|
ProxyID string
|
|
Active int64
|
|
Reserved int64
|
|
Draining bool
|
|
}
|
|
|
|
// Report is a complete sparse replacement. Missing counters are zero for the
|
|
// reported Worker snapshot; callers must increase Sequence for every update.
|
|
type Report struct {
|
|
WorkerID string
|
|
SessionID string
|
|
Sequence uint64
|
|
SnapshotVersion uint64
|
|
OwnershipEpoch uint64
|
|
ObservedAt time.Time
|
|
Counters []Counter
|
|
}
|
|
|
|
type OwnedProxy struct {
|
|
ProxyID string
|
|
WorkerID string
|
|
OwnershipEpoch uint64
|
|
}
|
|
|
|
type Snapshot struct {
|
|
ProxyID string
|
|
Active int64
|
|
Reserved int64
|
|
Draining bool
|
|
Fresh bool
|
|
}
|
|
|
|
// OutcomeReference is the durable deduplication fence for one Gateway Outcome
|
|
// batch. The event payload itself remains outside the runtime store.
|
|
type OutcomeReference struct {
|
|
WorkerID string
|
|
SessionID string
|
|
Sequence uint64
|
|
Digest [sha256.Size]byte
|
|
}
|
|
|
|
type SessionWriter interface {
|
|
ReplaceSession(context.Context, Session, time.Duration) error
|
|
}
|
|
|
|
type ControlStore interface {
|
|
CurrentOwnershipEpoch(context.Context) (uint64, error)
|
|
OpenSession(context.Context, Session, time.Duration) error
|
|
ValidateSession(context.Context, string, string) error
|
|
RecordIssuedSnapshot(context.Context, string, SnapshotReference, time.Duration) error
|
|
AcknowledgeSnapshot(context.Context, SnapshotAcknowledgement, time.Duration) error
|
|
ReplaceRuntime(context.Context, Report, time.Duration) error
|
|
}
|
|
|
|
type OutcomeWriter interface {
|
|
RecordOutcomes(context.Context, OutcomeReference) (uint64, error)
|
|
}
|
|
|
|
type ReportWriter interface {
|
|
ReplaceRuntime(context.Context, Report, time.Duration) error
|
|
}
|
|
|
|
type RuntimeReader interface {
|
|
ReadRuntime(context.Context, []OwnedProxy) ([]Snapshot, error)
|
|
}
|