distributed

package
v1.72.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var File_distributed_mc_owner_proto protoreflect.FileDescriptor

Functions

This section is empty.

Types

type MostlyCorrectOwner

type MostlyCorrectOwner struct {

	// Log is used for logs. Everything is at a fine granularity,
	// usually TRACE.
	Log logging.Logger
	// Store is used to synchronize ownership across
	// goroutiness on multiple cooperating processes.
	Store kv.Store
	// Prefix is used to separate "locking" keys between different
	// instances of MostlyCorrectOwner.
	Prefix string
	// contains filtered or unexported fields
}

MostlyCorrectOwner uses a Store to allow roughly at most a single goroutine to handle an operation for a key, across all processes sharing that store. It can block but never deadlock. "Rough" ownership means that when the owner is too slow another owner might mistakenly be added.

If:

  • single ownership is not required for correctness, AND
  • only one concurrent goroutine can succeed

then using a MostlyCorrectOwner can help improve performance by usually allowing only one goroutine into a critical section. This reduces retries.

MostlyCorrectOwner works by setting an ownership key with timed expiration along with a goroutine that refreshes expiration of that key. This can fail:

  • if clocks are not synchronized
  • if the refreshing goroutine is late

So it *cannot* guarantee correctness. However it usually works, and if it does work, the owning goroutine wins all races by default.

MostlyCorrectOwner creates some additional load on its KV partition:

  • Acquiring ownership reads at least once and writes (SetIf) once. If the key is already held, each acquisition reads once every acquireInterval and once every time ownership expires.

  • Holding a lock reads and writes (SetIf) once every refreshInterval.

func NewMostlyCorrectOwner

func NewMostlyCorrectOwner(log logging.Logger, store kv.Store, prefix string, acquireInterval, refreshInterval time.Duration) *MostlyCorrectOwner

func (*MostlyCorrectOwner) Own

func (w *MostlyCorrectOwner) Own(ctx context.Context, owner, key string) (func(), error)

Own blocks until it gets mostly-correct ownership of key for owner. Ownership will be refreshed at resolution interval. It returns a function to stop owning key. Own appends its random slug to owner, to identify the owner uniquely.

type MostlyCorrectOwnership

type MostlyCorrectOwnership struct {

	// owner is a unique identifier for this particular instantiation.  Different concurrent owners
	// must have different owner strings.  Easiest to set it to something random.
	Owner   string                 `protobuf:"bytes,1,opt,name=owner,proto3" json:"owner,omitempty"`
	Expires *timestamppb.Timestamp `protobuf:"bytes,2,opt,name=expires,proto3" json:"expires,omitempty"`
	Comment string                 `protobuf:"bytes,3,opt,name=comment,proto3" json:"comment,omitempty"`
	// contains filtered or unexported fields
}

message data model for mostly-correct ownership

func (*MostlyCorrectOwnership) Descriptor deprecated

func (*MostlyCorrectOwnership) Descriptor() ([]byte, []int)

Deprecated: Use MostlyCorrectOwnership.ProtoReflect.Descriptor instead.

func (*MostlyCorrectOwnership) GetComment

func (x *MostlyCorrectOwnership) GetComment() string

func (*MostlyCorrectOwnership) GetExpires

func (x *MostlyCorrectOwnership) GetExpires() *timestamppb.Timestamp

func (*MostlyCorrectOwnership) GetOwner

func (x *MostlyCorrectOwnership) GetOwner() string

func (*MostlyCorrectOwnership) ProtoMessage

func (*MostlyCorrectOwnership) ProtoMessage()

func (*MostlyCorrectOwnership) ProtoReflect

func (x *MostlyCorrectOwnership) ProtoReflect() protoreflect.Message

func (*MostlyCorrectOwnership) Reset

func (x *MostlyCorrectOwnership) Reset()

func (*MostlyCorrectOwnership) String

func (x *MostlyCorrectOwnership) String() string

Jump to

Keyboard shortcuts

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