eviction

package
v0.86.21 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultDurableEvictionConfig = DurableEvictionConfig{
	CheckInterval:              1 * time.Second,
	ReserveSlots:               0,
	MinWaitForCapacityEviction: 10 * time.Second,
}

DefaultDurableEvictionConfig provides sensible defaults.

Functions

This section is empty.

Types

type CancelLocalFn

type CancelLocalFn func(key string)

CancelLocalFn cancels a local durable run by its action key.

type DurableEvictionCache

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

DurableEvictionCache manages durable run state for eviction decisions. Thread-safe via internal mutex.

func NewDurableEvictionCache

func NewDurableEvictionCache() *DurableEvictionCache

NewDurableEvictionCache creates a new empty cache.

func (*DurableEvictionCache) FindKeyByStepRunID

func (c *DurableEvictionCache) FindKeyByStepRunID(stepRunID string) *string

FindKeyByStepRunID looks up a run key by its step run ID (linear scan).

func (*DurableEvictionCache) Get

Get returns the run record for a given key, or nil if not found.

func (*DurableEvictionCache) GetAllWaiting

func (c *DurableEvictionCache) GetAllWaiting() []*DurableRunRecord

GetAllWaiting returns all run records currently in a waiting state.

func (*DurableEvictionCache) MarkActive

func (c *DurableEvictionCache) MarkActive(key string, now time.Time)

MarkActive decrements the wait reference count for a run.

func (*DurableEvictionCache) MarkWaiting

func (c *DurableEvictionCache) MarkWaiting(key string, now time.Time, waitKind, resourceID string)

MarkWaiting increments the wait reference count for a run.

func (*DurableEvictionCache) RegisterRun

func (c *DurableEvictionCache) RegisterRun(
	key, stepRunID string,
	invocationCount int,
	now time.Time,
	policy *EvictionPolicy,
)

RegisterRun adds a run to the cache.

func (*DurableEvictionCache) SelectEvictionCandidate

func (c *DurableEvictionCache) SelectEvictionCandidate(
	now time.Time,
	durableSlots int,
	reserveSlots int,
	minWaitForCapacityEviction time.Duration,
) string

SelectEvictionCandidate selects the best eviction candidate. Returns the key of the selected run, or empty string if none.

func (*DurableEvictionCache) UnregisterRun

func (c *DurableEvictionCache) UnregisterRun(key string)

UnregisterRun removes a run from the cache.

type DurableEvictionConfig

type DurableEvictionConfig struct {
	CheckInterval              time.Duration
	ReserveSlots               int
	MinWaitForCapacityEviction time.Duration
}

DurableEvictionConfig controls the eviction manager behavior.

type DurableEvictionManager

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

DurableEvictionManager periodically checks for and evicts durable runs.

func NewDurableEvictionManager

func NewDurableEvictionManager(
	durableSlots int,
	cancelLocal CancelLocalFn,
	requestEvict RequestEvictionWithAckFn,
	config DurableEvictionConfig,
	l *zerolog.Logger,
) *DurableEvictionManager

NewDurableEvictionManager creates a new eviction manager.

func (*DurableEvictionManager) Cache

Cache returns the underlying cache for direct access.

func (*DurableEvictionManager) EvictAllWaiting

func (m *DurableEvictionManager) EvictAllWaiting(ctx context.Context) int

EvictAllWaiting evicts every currently-waiting durable run. Used during graceful shutdown.

func (*DurableEvictionManager) HandleServerEviction

func (m *DurableEvictionManager) HandleServerEviction(stepRunID string, invocationCount int)

HandleServerEviction processes a server-initiated eviction notification.

func (*DurableEvictionManager) MarkActive

func (m *DurableEvictionManager) MarkActive(key string)

MarkActive marks a run as active (no longer waiting).

func (*DurableEvictionManager) MarkWaiting

func (m *DurableEvictionManager) MarkWaiting(key, waitKind, resourceID string)

MarkWaiting marks a run as waiting.

func (*DurableEvictionManager) RegisterRun

func (m *DurableEvictionManager) RegisterRun(key, stepRunID string, invocationCount int, policy *EvictionPolicy)

RegisterRun adds a run to the eviction cache.

func (*DurableEvictionManager) Start

func (m *DurableEvictionManager) Start()

Start begins the eviction check loop. Safe to call multiple times.

func (*DurableEvictionManager) Stop

func (m *DurableEvictionManager) Stop()

Stop halts the eviction check loop.

func (*DurableEvictionManager) UnregisterRun

func (m *DurableEvictionManager) UnregisterRun(key string)

UnregisterRun removes a run from the eviction cache.

type DurableRunRecord

type DurableRunRecord struct {
	RegisteredAt    time.Time
	EvictionPolicy  *EvictionPolicy
	WaitingSince    *time.Time
	Key             string
	StepRunID       string
	WaitKind        string
	WaitResourceID  string
	EvictionReason  string
	InvocationCount int
	// contains filtered or unexported fields
}

DurableRunRecord tracks the state of a durable run for eviction decisions.

func (*DurableRunRecord) GetWaitingSince

func (r *DurableRunRecord) GetWaitingSince() *time.Time

GetWaitingSince returns a copy of the waiting since timestamp.

func (*DurableRunRecord) IsWaiting

func (r *DurableRunRecord) IsWaiting() bool

IsWaiting returns true if the run is currently in a waiting state.

func (*DurableRunRecord) WaitCount

func (r *DurableRunRecord) WaitCount() int

WaitCount returns the current wait reference count.

type EvictionCause

type EvictionCause string
const (
	EvictionCauseTTLExceeded      EvictionCause = "ttl_exceeded"
	EvictionCauseCapacityPressure EvictionCause = "capacity_pressure"
	EvictionCauseWorkerShutdown   EvictionCause = "worker_shutdown"
)

type EvictionPolicy

type EvictionPolicy struct {
	TTL                   time.Duration
	AllowCapacityEviction bool
	Priority              int
}

EvictionPolicy mirrors the SDK-level EvictionPolicy for internal use.

type RequestEvictionWithAckFn

type RequestEvictionWithAckFn func(ctx context.Context, key string, rec *DurableRunRecord) error

RequestEvictionWithAckFn sends an eviction request to the server and waits for ack.

Jump to

Keyboard shortcuts

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