Documentation
¶
Overview ¶
Package lockfile is a Linux tool to lock cooperating processes based on syscall `flock`. While a sync.Mutex helps against concurrency issues within a single process, this package is designed to help against concurrency issues between cooperating processes. This package can be only used in Linux, and cannot be used as a `sync.Mutex` in a single process.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrBusy means that the lock is being acquired by anthor process. // If you get this, retry after a short sleep might help. ErrBusy = TemporaryError("locked by other process") )
Functions ¶
This section is empty.
Types ¶
type Lockfile ¶
type Lockfile struct { // Path represents the file lock path. It should be shared between different process. // Each path can represent an independent lock file. Path string // contains filtered or unexported fields }
Lockfile is a Linux signal file to implement cross-process locks. The file content does not contain anything, it will be always overwritten.
The Lockfile should be used in different process, it cannot be used as a mutex lock in a single process. If you use it in a single process, the Lock and TryLock will always success.
If the process crashed, all its Lockfile will be released automatically, you donot need to handle the deadlock situation.
func (*Lockfile) TryLock ¶
TryLock tries to acquire the lock. If the current process successful acquire the lock, this will return nil. If the lock is busy, this will return ErrBusy. In this case, you should do some retries.
type TemporaryError ¶
type TemporaryError string
TemporaryError is a type of error where a retry after a random amount of sleep should help to mitigate it.
func (TemporaryError) Error ¶
func (t TemporaryError) Error() string
func (TemporaryError) Temporary ¶
func (t TemporaryError) Temporary() bool