Help us shape the future of Go! Take the 2026 Go Developer Survey

coord

package
v0.57.20 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrLeaseReleased indicates a write lease has already been released.
	ErrLeaseReleased = errors.New("coord: lease released")
	// ErrStaleGeneration indicates a writer published from an old generation.
	ErrStaleGeneration = errors.New("coord: stale generation")
	// ErrScopeEmpty indicates a scope with no ObjectStoreID and no Key.
	ErrScopeEmpty = errors.New("coord: scope has no object store id and no key")
)
View Source
var ErrUnsupported = errors.New("coord: unsupported")

ErrUnsupported indicates a scoped ObjectStore does not support direct coordination.

Functions

This section is empty.

Types

type BackendKind added in v0.52.0

type BackendKind string

BackendKind identifies the storage backend behind a coordination capability.

const (
	// BackendKindUnknown means the backend was not identified.
	BackendKindUnknown BackendKind = ""
	// BackendKindInMemory identifies the in-memory coordinator.
	BackendKindInMemory BackendKind = "in-memory"
	// BackendKindBbolt identifies the bbolt coordinator adapter.
	BackendKindBbolt BackendKind = "bbolt"
	// BackendKindOPFS identifies the OPFS coordinator adapter.
	BackendKindOPFS BackendKind = "opfs"
	// BackendKindFileLock identifies the advisory file lock coordinator adapter.
	BackendKindFileLock BackendKind = "filelock"
	// BackendKindRedis identifies the redis coordinator adapter.
	BackendKindRedis BackendKind = "redis"
	// BackendKindRPC identifies a remote coordinator adapter.
	BackendKindRPC BackendKind = "rpc"
	// BackendKindUnsupported identifies a backend with no direct coordinator.
	BackendKindUnsupported BackendKind = "unsupported"
)

type Capability added in v0.52.0

type Capability struct {
	// Supported is true when direct coordination is available.
	Supported bool
	// Backend identifies the backend that would coordinate the scope.
	Backend BackendKind
	// VolumeID is the owning Volume id.
	VolumeID string
	// ObjectStoreID is the ObjectStore id inside the Volume.
	ObjectStoreID string
	// Generation is the latest durable generation observed by the coordinator.
	Generation uint64
	// Generations is true when the scope carries durable generation fencing,
	// Snapshot, Publish, and Watch.
	Generations bool
	// DetectsLoss is true when the backend closes WriteLease.Done and reports
	// WriteLease.Err on involuntary loss.
	DetectsLoss bool
	// FallbackReason explains why Supported is false.
	FallbackReason FallbackReason
}

Capability describes direct coordination support for a scoped ObjectStore.

type Coordinator

type Coordinator interface {
	// Capability reports whether the scoped ObjectStore supports direct
	// multi-writer coordination and why callers must fall back when it does not.
	Capability(ctx context.Context, scope Scope) (*Capability, error)
	// Snapshot returns the latest durable generation and root metadata.
	Snapshot(ctx context.Context, scope Scope) (*Snapshot, error)
	// Watch returns root, prefix, lock, and fallback events after generation.
	Watch(ctx context.Context, scope Scope, afterGeneration uint64) (Watch, error)
	// TryAcquireWriteLease attempts to acquire the logical write lease.
	TryAcquireWriteLease(ctx context.Context, scope Scope) (WriteLease, bool, error)
	// WaitAcquireWriteLease waits until the logical write lease is available.
	WaitAcquireWriteLease(ctx context.Context, scope Scope) (WriteLease, error)
}

Coordinator provides backend-neutral coordination for one Volume.

type Event added in v0.52.0

type Event struct {
	// ProcessID identifies the process that produced or requested the event.
	ProcessID string
	// VolumeID is the owning Volume id.
	VolumeID string
	// ObjectStoreID is the ObjectStore id inside the Volume.
	ObjectStoreID string
	// Generation is the durable generation associated with this event.
	Generation uint64
	// WantLock is true when another participant is waiting for the write lease.
	WantLock bool
	// Unlocked is true when a participant released the write lease.
	Unlocked bool
	// RootChanged carries the accepted root after a commit.
	RootChanged *bucket.ObjectRef
	// KeyPrefixChanged carries a key prefix invalidated by a commit.
	KeyPrefixChanged []byte
	// FallbackReason carries a visible fallback reason when direct coordination fails.
	FallbackReason FallbackReason
}

Event reports a coordination state change for a scoped ObjectStore.

type FallbackReason added in v0.52.0

type FallbackReason string

FallbackReason explains why a caller must use the proxy/RPC fallback path.

const (
	// FallbackReasonNone means no fallback is required.
	FallbackReasonNone FallbackReason = ""
	// FallbackReasonUnsupported means the scoped backend has no coordinator.
	FallbackReasonUnsupported FallbackReason = "unsupported"
	// FallbackReasonDescriptorInvalid means a direct descriptor failed validation.
	FallbackReasonDescriptorInvalid FallbackReason = "descriptor-invalid"
	// FallbackReasonDescriptorStale means the direct descriptor was for an old generation.
	FallbackReasonDescriptorStale FallbackReason = "descriptor-stale"
)

type Scope added in v0.52.0

type Scope struct {
	// VolumeID is the owning Volume id.
	VolumeID string
	// ObjectStoreID is the ObjectStore id inside the Volume.
	ObjectStoreID string
	// ParticipantID identifies the process or handle performing the operation.
	ParticipantID string
	// Key names a caller-chosen exclusion subject inside the Volume.
	Key string
}

Scope identifies the coordinated ObjectStore or exclusion subject inside a Volume.

type Snapshot added in v0.52.0

type Snapshot struct {
	// VolumeID is the owning Volume id.
	VolumeID string
	// ObjectStoreID is the ObjectStore id inside the Volume.
	ObjectStoreID string
	// Generation is the latest durable generation.
	Generation uint64
	// Root is the latest durable ObjectStore root.
	Root *bucket.ObjectRef
}

Snapshot captures the latest durable generation and root metadata.

type UnsupportedCoordinator added in v0.52.0

type UnsupportedCoordinator struct {
	// Backend is the unsupported backend kind to report.
	Backend BackendKind
	// Reason is the fallback reason to report.
	Reason FallbackReason
}

UnsupportedCoordinator reports explicit proxy/RPC fallback for a Volume.

func NewUnsupportedCoordinator added in v0.52.0

func NewUnsupportedCoordinator(backend BackendKind, reason FallbackReason) *UnsupportedCoordinator

NewUnsupportedCoordinator builds a Coordinator for unsupported backends.

func (*UnsupportedCoordinator) Capability added in v0.52.0

func (c *UnsupportedCoordinator) Capability(ctx context.Context, scope Scope) (*Capability, error)

Capability reports an unsupported coordination capability.

func (*UnsupportedCoordinator) Snapshot added in v0.52.0

func (c *UnsupportedCoordinator) Snapshot(ctx context.Context, scope Scope) (*Snapshot, error)

Snapshot returns ErrUnsupported because no durable coordination snapshot exists.

func (*UnsupportedCoordinator) TryAcquireWriteLease added in v0.52.0

func (c *UnsupportedCoordinator) TryAcquireWriteLease(ctx context.Context, scope Scope) (WriteLease, bool, error)

TryAcquireWriteLease returns ErrUnsupported because no direct lease exists.

func (*UnsupportedCoordinator) WaitAcquireWriteLease added in v0.52.0

func (c *UnsupportedCoordinator) WaitAcquireWriteLease(ctx context.Context, scope Scope) (WriteLease, error)

WaitAcquireWriteLease returns ErrUnsupported because no direct lease exists.

func (*UnsupportedCoordinator) Watch added in v0.52.0

func (c *UnsupportedCoordinator) Watch(ctx context.Context, scope Scope, afterGeneration uint64) (Watch, error)

Watch returns ErrUnsupported because the backend has no direct event stream.

type Watch added in v0.52.0

type Watch interface {
	// Events returns the event stream for this watch.
	Events() <-chan Event
	// Close releases resources held by this watch.
	Close() error
}

Watch streams coordination events until closed or until its context ends.

type WriteLease added in v0.52.0

type WriteLease interface {
	// Done returns a channel closed when the lease is released or lost.
	//
	// Done closes on release or on involuntary loss. A backend reporting
	// Capability.DetectsLoss false closes Done only from Release.
	Done() <-chan struct{}
	// Err returns the loss error after Done is closed, or nil for a held or
	// cleanly released lease.
	Err() error
	// Refresh returns the latest durable generation and root before writing.
	//
	// Refresh on a scope with Capability.Generations false returns ErrUnsupported.
	Refresh(ctx context.Context) (*Snapshot, error)
	// Publish records an accepted generation/root/prefix change.
	//
	// Publish on a scope with Capability.Generations false returns ErrUnsupported.
	Publish(ctx context.Context, event Event) (*Snapshot, error)
	// Release releases the logical write lease.
	//
	// Release must complete regardless of ctx cancellation. Callers release on
	// cleanup paths that run precisely because their context ended, so a
	// release that honored cancellation would strand the scope locked and
	// every waiter blocked. ctx carries deadlines for backend I/O only.
	Release(ctx context.Context) error
}

WriteLease owns one logical write turn for a scoped ObjectStore.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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