memory

package
v0.3.0 Latest Latest
Warning

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

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

Documentation

Overview

Package memory is the in-memory admission core both executor schedulers use.

Each accepted run has exactly one owner record while the executor holds it. It carries the run's spec and its immutable control binding, the phase it is in (persisting, queued, cancel-pending, active, finalizing, completed, retired) and the channels its result is published on. One mutex guards all of it, and persistence, callbacks and finalization always run outside that mutex.

Both transitions that create work are committed through an admission guard: while the core holds its mutex, the guard decides whether the run's binding is still armed and calls the commit it was given, which appends the queue entry or promotes it to a running one. A guard that refuses leaves the owner and its canonical row exactly as they were, so a lost lease never retracts accepted work or starts unauthorized work.

Shutdown closes admission and joins what this core owns: reservations, callbacks, finalizers and backend reads, each counted while it runs. It reports the cleanup errors of owners that finished but could not be retired, so a caller that observes a clean shutdown knows nothing of its own is still running.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MemoryStorage

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

MemoryStorage is a simple in-memory implementation storing all debuglets in a priority queue sorted by their starting time.

Because the WASM is also stored in memory, the memory usage of a lot of debuglets can be significant.

func NewPersistentStorage

func NewPersistentStorage(persist func(context.Context, scheduler.Spec) (scheduler.Spec, error), finalize func(context.Context, uuid.UUID) error, inspect func(context.Context, uuid.UUID, controlsession.Binding) error, admission scheduler.Admission) (*MemoryStorage, error)

NewPersistentStorage shares the queue's ownership state with a persistent backend. persist returns the spec kept in memory after the successful write; finalize only removes the canonical row. Neither runs under the queue lock.

func NewStorage

func NewStorage(admission scheduler.Admission) (*MemoryStorage, error)

NewStorage requires both admission guards, so every core commits the transitions that create work under one.

func (*MemoryStorage) Cancel

func (m *MemoryStorage) Cancel(ctx context.Context, id uuid.UUID, cause error) (bool, error)

Cancel signals the matching owner and waits for local cleanup and canonical row removal. A caller timeout retains the owner and its uncertain result. It compares no binding, so it is the backends' own operation rather than one a control session may ask for.

func (*MemoryStorage) CancelBound

func (m *MemoryStorage) CancelBound(ctx context.Context, id uuid.UUID, binding controlsession.Binding, cause error) (bool, error)

func (*MemoryStorage) Insert

func (m *MemoryStorage) Insert(ctx context.Context, u scheduler.Spec) error

Insert accepts at the append under mu. Cancellation observed immediately before that append rejects the job; cancellation racing an accepted append cannot turn it into an error or retract the accepted work.

func (*MemoryStorage) Inspect

func (m *MemoryStorage) Inspect(ctx context.Context, read func(context.Context) error) error

Inspect reserves one backend-owned read the same way persistence, restoration and finalization are reserved: Shutdown joins it before claiming quiescence, and a closed core refuses a new read instead of racing database closure. Cancelling ctx does not release the reservation; only read returning does, so a backend that keeps using its connection past cancellation is still joined rather than abandoned.

func (*MemoryStorage) RegisterFailed

func (s *MemoryStorage) RegisterFailed(cb scheduler.FailedFunc)

func (*MemoryStorage) RegisterOnStart

func (m *MemoryStorage) RegisterOnStart(onStart scheduler.StartFunc)

func (*MemoryStorage) Remove

func (m *MemoryStorage) Remove(ctx context.Context, debugletID uuid.UUID) (bool, error)

Remove uses the same owned deletion as Cancel for queued work. Active work returns an error; an absent admitted owner returns (false, nil).

func (*MemoryStorage) Restore

func (m *MemoryStorage) Restore(ctx context.Context, load func(context.Context, func(scheduler.Spec) error) error) error

Restore reserves the database-reading operation, so Shutdown cannot finish while a backend is still paging. emit imports already-persisted rows and never invokes the persistence hook. Shutdown may stop further import; rows left in the canonical database remain recoverable on the next startup.

func (*MemoryStorage) Shutdown

func (m *MemoryStorage) Shutdown(ctx context.Context) error

func (*MemoryStorage) StartLoop

func (m *MemoryStorage) StartLoop(ctx context.Context) error

type TimedQueue

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

TimedQueue abstracts the priority queue to allow for the removal of specific IDs in amortized O(1)

func NewTimedQueue

func NewTimedQueue() *TimedQueue

func (*TimedQueue) Len

func (tq *TimedQueue) Len() int

func (*TimedQueue) Peek

func (tq *TimedQueue) Peek(ind int) *scheduler.Spec

func (*TimedQueue) Pop

func (tq *TimedQueue) Pop() *scheduler.Spec

func (*TimedQueue) Push

func (tq *TimedQueue) Push(x scheduler.Spec)

func (*TimedQueue) Remove

func (tq *TimedQueue) Remove(ID uuid.UUID) *scheduler.Spec

Jump to

Keyboard shortcuts

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