gcslock

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2021 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BackOffGenerator

type BackOffGenerator func() backoff.BackOff

BackOffGenerator is used to create new backoff iterators.

func DefaultBackOffGenerator

func DefaultBackOffGenerator() BackOffGenerator

DefaultBackOffGenerator provides a default exponential backoff implementation for use with WithBackOffGenerator.

type GCSLock

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

GCSLock uses the strong-consistency guarantees of Google Cloud Storage (GCS) to provide a fault-tolerant, globally-distributed lock via an HTTP API.

It does so by writing a specific object to a specified bucket on lock acquisition, retrying (with backoff) if the file already exists or when a network error occurs. To release the lock, the same object is deleted.

See https://cloud.google.com/storage/docs/consistency for more details on the consistency guarantees provided by GCS.

func NewGCSLock

func NewGCSLock(bucket string, object string, opts ...Option) (*GCSLock, error)

NewGCSLock creates a new Google Cloud Storage (GCS) globally-consistent contextlock.ContextLocker type, which will write the lock file to the provided GCS bucket and object (directory & file).

func (*GCSLock) ForceUnlockContext

func (l *GCSLock) ForceUnlockContext(ctx context.Context) error

ForceUnlockContext is a special variant of UnlockContext that will forcefully unlock the global state by deleting the GCS object even if the local lock instance did not create it.

This method can be useful to reset the global lock state when the process that acquired the lock exits abnormally and fails to release its lock.

func (*GCSLock) Lock

func (l *GCSLock) Lock()

Lock implements sync.Locker.

func (*GCSLock) LockContext

func (l *GCSLock) LockContext(ctx context.Context) error

LockContext implements contextlock.ContextLocker.

func (*GCSLock) Unlock

func (l *GCSLock) Unlock()

Unlock implements sync.Locker.

func (*GCSLock) UnlockContext

func (l *GCSLock) UnlockContext(ctx context.Context) error

UnlockContext implements contextlock.ContextLocker.

type HTTPClientDoer

type HTTPClientDoer interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPClientDoer provides an interface wrapper around a *http.Client.

func DefaultGoogleHTTPClient

func DefaultGoogleHTTPClient(ctx context.Context, scopes ...string) (HTTPClientDoer, error)

DefaultGoogleHTTPClient provides a standard Google API HTTP client to be used with WitHTTPClient.

type LockFileMetadataGenerator

type LockFileMetadataGenerator func(ctx context.Context) ([]byte, error)

LockFileMetadataGenerator creates output data to be stored in a GCS lock file when created. This may contain useful information about the locker's identity and execution path for debugging purposes.

func DefaultLockFileMetadataGenerator

func DefaultLockFileMetadataGenerator() LockFileMetadataGenerator

DefaultLockFileMetadataGenerator provides a default lock file metadata generator including information about the time, host, and call stack of the lock acquisition call to be used with WithLockFileMetadataGenerator.

type Option

type Option func(*GCSLock)

Option provides structured optional arguments to NewGCSLock.

func WitHTTPClient

func WitHTTPClient(httpClient HTTPClientDoer) Option

WitHTTPClient sets the HTTP client to use with GCSLock HTTP calls to the Google Cloud Storage API.

func WithBackOffGenerator

func WithBackOffGenerator(backOffGenerator BackOffGenerator) Option

WithBackOffGenerator sets the backoff implementation to use with GCSLock.

func WithBaseURL

func WithBaseURL(baseURL url.URL) Option

WithBaseURL sets the base URL for the Google Cloud Storage API to use with HTTP calls from GCSLock.

func WithLockFileMetadataGenerator

func WithLockFileMetadataGenerator(generator LockFileMetadataGenerator) Option

WithLockFileMetadataGenerator sets the lock file metadata generator to be used with GCSLock.

func WithLogger

func WithLogger(logger *zap.Logger) Option

WithLogger sets the Zap logger to use with the GCSLock.

Jump to

Keyboard shortcuts

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