scheduler

package
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 20, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package scheduler provides deterministic, explainable runtime placement.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidPoolSet = errors.New("runtime pool set is invalid")
View Source
var ErrNoPlacement = errors.New("no eligible runtime placement")

Functions

func GuardProductionPoolSource

func GuardProductionPoolSource(source PoolSource, devMode bool) error

GuardProductionPoolSource rejects a StaticPoolSource on a production startup path. The scheduler's authoritative capacity total lives in the durable capacity ledger; a StaticPoolSource sidesteps it, so a non-dev server that is (now or in future) handed one - directly or wrapped by a LeaseAwarePoolSource - fails closed rather than silently scheduling against unenforced capacity. devMode mirrors the -dev-mode acknowledgment that already gates seeding the mutable registry from a flat file.

func WithParallelism

func WithParallelism(workers int) func(*Controller)

WithParallelism bounds concurrent per-task processing within one reconcile batch (default 4; 1 = serial).

func WithShard

func WithShard(index, count int) func(*Controller)

WithShard confines this instance to one tenant-consistent claim shard (ADR-016): it claims only tasks whose tenant maps to index of count. Count 0 disables sharding. Every controller instance must share the same count.

Types

type Controller

type Controller struct {
	// contains filtered or unexported fields
}

func NewController

func NewController(repository store.ControlStore, pools PoolSource, ownerID string, batch int, claimTTL, leaseTTL time.Duration) *Controller

func (*Controller) Reconcile

func (c *Controller) Reconcile(ctx context.Context) (int, error)

Reconcile claims and schedules admitted tasks. Transient transaction conflicts are retried with bounded backoff (ADR-002).

type LeaseAwarePoolSource

type LeaseAwarePoolSource struct {
	// contains filtered or unexported fields
}

LeaseAwarePoolSource overlays lease-derived runtime health onto a static pool configuration: a pool is ready only when its static configuration says ready AND its runtime instance is presumed alive by recent lease heartbeats. Placement therefore rejects pools whose worker stopped renewing its lease instead of scheduling a task that would be stranded until lease-expiry recovery. An instance ID missing from the health result is treated as unhealthy (fail-closed).

func NewLeaseAwarePoolSource

func NewLeaseAwarePoolSource(static PoolSource, health store.PoolHealthStore, freshness time.Duration) *LeaseAwarePoolSource

func (*LeaseAwarePoolSource) ListRuntimePools

func (s *LeaseAwarePoolSource) ListRuntimePools(ctx context.Context, tenantID string) ([]RuntimePool, error)

type Placement

type Placement struct {
	Pool       RuntimePool      `json:"pool"`
	Score      float64          `json:"score"`
	Components []ScoreComponent `json:"components"`
}

type PoolSource

type PoolSource interface {
	ListRuntimePools(context.Context, string) ([]RuntimePool, error)
}

type Rejection

type Rejection struct {
	PoolID  string   `json:"poolId"`
	Reasons []string `json:"reasons"`
}

type Result

type Result struct {
	Placement Placement `json:"placement"`
	// Candidates is the full score-ranked placement list. Placement is the
	// first entry; the scheduler walks the remaining entries in order when
	// a higher-ranked pool loses the transactional capacity reservation.
	Candidates []Placement `json:"candidates"`
	Rejected   []Rejection `json:"rejected"`
}

func Select

func Select(spec workload.Spec, pools []RuntimePool) (Result, error)

type RuntimePool

type RuntimePool struct {
	ID                string   `json:"id"`
	TenantIDs         []string `json:"tenantIds"`
	RuntimeClass      string   `json:"runtimeClass"`
	RuntimeInstanceID string   `json:"runtimeInstanceId"`
	Region            string   `json:"region"`
	DataResidency     string   `json:"dataResidency"`
	Ready             bool     `json:"ready"`
	// Status separates health from operator intent. Empty/ACTIVE accepts new
	// work; CORDONED and DRAINING preserve existing leases but reject placement.
	Status            string `json:"status,omitempty"`
	FailureDomain     string `json:"failureDomain,omitempty"`
	AvailableCPU      int64  `json:"availableCpuMillis"`
	AvailableMemory   int64  `json:"availableMemoryMiB"`
	AvailableLLMSlots int    `json:"availableLlmSlots"`
	// CapacityLedgerMissing marks a pool whose durable capacity ledger was
	// never registered by the operator. Such pools fail placement closed
	// instead of being treated as fully idle. Zero (the default) keeps
	// statically configured pools schedulable.
	CapacityLedgerMissing bool     `json:"capacityLedgerMissing,omitempty"`
	ArtifactRegions       []string `json:"artifactRegions"`
	CostWeight            float64  `json:"costWeight"`
	// Operators lists the operator subjects granted cordon/drain/activate
	// authority on this pool. Usage visibility comes from TenantIDs; the
	// two authorities are deliberately independent so a tenant of a shared
	// pool cannot operate it.
	Operators []string `json:"operators,omitempty"`
}

type ScoreComponent

type ScoreComponent struct {
	Name   string  `json:"name"`
	Value  float64 `json:"value"`
	Reason string  `json:"reason"`
}

type StaticPoolSource

type StaticPoolSource []RuntimePool

StaticPoolSource is an in-memory pool list for tests and local development. It is NOT a production capacity authority: it reports pools directly from a fixed slice and never consults the durable capacity ledger, so wiring it into a server bypasses the reservation invariant that keeps concurrent placement from over-committing a pool. Production builds the pool source from the durable registry (LeaseAwarePoolSource over the store); GuardProductionPoolSource fails a non-dev server that is handed a StaticPoolSource.

func (StaticPoolSource) ListRuntimePools

func (s StaticPoolSource) ListRuntimePools(_ context.Context, tenantID string) ([]RuntimePool, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL