gcslock

package
v1.80.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2024 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package gcslock provides distributed locks to use with Google Cloud Storage. The distributed locking algorithm is based on the algorithm from https://www.joyfulbikeshedding.com/blog/2021-05-19-robust-distributed-locking-algorithm-based-on-google-cloud-storage.html.

It does not implement identities, and `refresh` is not allowed to fail.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Error is the error class for this package.
	Error errs.Class = "gcslock"
)

Functions

This section is empty.

Types

type Logger

type Logger interface {
	Infof(template string, args ...interface{})
	Errorf(template string, args ...interface{})
}

Logger is the most basic set of what's needed for Mutex to log state.

type Mutex

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

Mutex is a distributed lock implemented on top of Google Cloud Storage. NewMutex should always be used to construct a Mutex.

func NewMutex

func NewMutex(ctx context.Context, opt Options) (_ *Mutex, err error)

NewMutex initializes new Mutex. If TTL and RefreshInterval aren't set in opt, reasonable defaults are applied.

func (*Mutex) Lock

func (m *Mutex) Lock(ctx context.Context) (err error)

Lock locks m.

func (*Mutex) Unlock

func (m *Mutex) Unlock(ctx context.Context) (err error)

Unlock unlocks m.

type Options

type Options struct {
	// JSONKey must be set except when Client is set.
	JSONKey []byte
	Name    string
	Bucket  string
	// TTL's default is 5 minutes.
	TTL time.Duration
	// RefreshInterval's default is 37 seconds.
	RefreshInterval time.Duration
	// If Logger is not set, nothing will be logged.
	Logger Logger
	// If Client is not set, a new one will be created.
	Client *gcsops.Client
}

Options define how Mutex should be configured.

Directories

Path Synopsis
Package gcsops provides an API client implementing a fraction of Cloud Storage's API originally needed by gcslock and packages using it.
Package gcsops provides an API client implementing a fraction of Cloud Storage's API originally needed by gcslock and packages using it.

Jump to

Keyboard shortcuts

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