memlock

package
v0.0.0-...-a0a3655 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2019 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package memlock allows multiple appengine handlers to coordinate best-effort mutual execution via memcache. "best-effort" here means "best-effort"... memcache is not reliable. However, colliding on memcache is a lot cheaper than, for example, colliding with datastore transactions.

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyClientID = errors.New("memlock: empty clientID")

ErrEmptyClientID is returned from TryWithLock when you specify an empty clientID.

View Source
var ErrFailedToLock = errors.New("memlock: failed to obtain lock")

ErrFailedToLock is returned from TryWithLock when it fails to obtain a lock prior to invoking the user-supplied function.

Functions

func TryWithLock

func TryWithLock(ctx context.Context, key, clientID string, f func(context.Context) error) error

TryWithLock attempts to obtains the lock once, and then invokes f if successful. The context provided to f will be canceled (e.g. ctx.Done() will be closed) if memlock detects that we've lost the lock.

TryWithLock function returns ErrFailedToLock if it fails to obtain the lock, otherwise returns the error that f returns.

`key` is the memcache key to use (i.e. the name of the lock). Clients locking the same data must use the same key. clientID is the unique identifier for this client (lock-holder). If it's empty then TryWithLock() will return ErrEmptyClientID.

Note that the lock provided by TryWithLock is a best-effort lock... some other form of locking or synchronization should be used inside of f (such as Datastore transactions) to ensure that f is, in fact, operating exclusively. The purpose of TryWithLock is to have a cheap filter to prevent unnecessary contention on heavier synchronization primitives like transactions.

Types

This section is empty.

Jump to

Keyboard shortcuts

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