checkpoint

package
v4.99.0 Latest Latest
Warning

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

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

Documentation

Overview

Package checkpoint lets state clients order their checkpoints after the resources they summarize.

Index

Constants

This section is empty.

Variables

View Source
var ErrSyncAborted = errors.New("sync aborted before the checkpoint could be sent")

ErrSyncAborted is returned for checkpoints that were dropped because the sync was cancelled.

Functions

func Deliver

func Deliver(ctx context.Context, res chan<- message.SyncMessage, msg message.SyncMessage) error

Deliver sends msg on res. A *Barrier is marked as reached instead, and a *Tracked message is sent and marked as sent.

func Drop

func Drop(msg message.SyncMessage)

Drop marks msg as never to be sent: a dropped *Tracked message, or the message a dropped *Barrier leads to, is aborted, and so are the checkpoints waiting for it.

func WithScope

func WithScope(ctx context.Context, scope Scope) context.Context

Types

type Barrier

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

Barrier travels through scopes and sent checkpoints, and calls reached each time one of them gets to it.

func (*Barrier) GetTable

func (*Barrier) GetTable() *schema.Table

func (*Barrier) IsSyncMessage

func (*Barrier) IsSyncMessage() bool

type Collapsing

type Collapsing interface {
	// Collapsed returns the shared scope, or the scope itself.
	Collapsed() Scope
}

Collapsing is implemented by scopes that can become equivalent to a scope they share with others, such as a table resolver's scope once the resolver ends.

type Delivery

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

Delivery tracks whether a checkpoint was sent or aborted, so that later checkpoints of the same keys can wait for it.

func NewHeld

func NewHeld(holder Scope) *Delivery

NewHeld returns a Delivery for a checkpoint that holder merges other checkpoints into.

func Schedule

func Schedule(ctx context.Context, res chan<- message.SyncMessage, scope Scope, after []*Delivery, msg message.SyncMessage) (*Delivery, error)

Schedule passes msg to Deliver once every one of scope's resources produced before the call is sent, and every checkpoint in after is sent, which may be after it returns. Without a scope or pending checkpoints to wait for, it sends msg on res. The returned Delivery tracks msg. If a checkpoint in after was aborted, Schedule returns ErrSyncAborted.

func (*Delivery) Abort

func (s *Delivery) Abort()

Abort marks s as dropped, and aborts the checkpoints waiting for it.

func (*Delivery) Aborted

func (s *Delivery) Aborted() bool

Aborted reports whether the checkpoint was dropped.

func (*Delivery) Delivered

func (s *Delivery) Delivered() bool

Delivered reports whether the checkpoint was sent.

func (*Delivery) Finish

func (s *Delivery) Finish(ctx context.Context, res chan<- message.SyncMessage) error

Finish marks s as sent, and releases the checkpoints waiting for it.

func (*Delivery) MergeInto

func (s *Delivery) MergeInto(into *Delivery)

MergeInto marks s as sent once into is sent, and aborted if into is aborted. into must not be sent yet.

func (*Delivery) MergedInto

func (s *Delivery) MergedInto(into *Delivery) bool

MergedInto reports whether s is sent with into.

func (*Delivery) NotifyAbort

func (s *Delivery) NotifyAbort(flag *atomic.Bool)

NotifyAbort sets flag if the checkpoint is aborted, or now if it already was.

type Ordering

type Ordering interface {
	// SendsAfter reports whether a checkpoint passed to the scope now will be sent no earlier than delivery.
	SendsAfter(delivery *Delivery) bool
}

Ordering is implemented by scopes that never send a checkpoint before an unsent one they already hold.

type Scope

type Scope interface {
	// Checkpoint passes msg to Deliver after every resource the scope produced before the call is sent, or to Drop if
	// the sync is cancelled first. It may return before that.
	Checkpoint(ctx context.Context, msg message.SyncMessage) error
}

Scope is the part of a sync that a table resolver drives: the resources it produces and their relations.

func Collapse

func Collapse(scope Scope) Scope

Collapse returns the shared scope a Collapsing scope collapsed into, or scope itself.

func FromContext

func FromContext(ctx context.Context) Scope

FromContext returns the scope ctx belongs to, or nil outside table resolvers.

func Join

func Join(scopes ...Scope) Scope

Join returns a scope whose checkpoints follow the resources of all the given scopes. It skips nil scopes, merges scopes that collapsed into the same one, and returns nil if all are nil.

type Tracked

type Tracked struct {
	Message  message.SyncMessage
	Delivery *Delivery
}

Tracked is a message that marks Delivery once Deliver sends it.

func (*Tracked) GetTable

func (*Tracked) GetTable() *schema.Table

func (*Tracked) IsSyncMessage

func (*Tracked) IsSyncMessage() bool

Jump to

Keyboard shortcuts

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