file_lock

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2026 License: Apache-2.0 Imports: 9 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LegacyHashFunction = false

Functions

func GCLockFileDir added in v0.2.0

func GCLockFileDir(dirPath string, minAge time.Duration) error

GCLockFileDir removes stale lock files from dirPath (recursively).

Lock files accumulate because Unlock never deletes them. A file is removed only when all of these hold:

  • its mtime is older than minAge (skips hot locks and makes the pass cheap over huge directories: the mtime check happens before any lock attempt);
  • GC can acquire an exclusive flock on it via TryLock (so it is not held by anyone else right now).

This is safe against the flock+unlink race only in combination with the inode-safe acquire path (see file_locker.go): a concurrent acquirer that opened the file just before GC unlinked it will detect the dead inode (Nlink==0) and retry on a freshly created file.

Errors for individual files are collected and returned joined; a single bad file does not abort the whole pass. Files that disappear concurrently are ignored.

Types

type BaseLock

type BaseLock struct {
	Name        string
	ActiveLocks int
}

func (*BaseLock) GetName

func (lock *BaseLock) GetName() string

func (*BaseLock) Lock

func (lock *BaseLock) Lock(l locker) error

func (*BaseLock) TryLock

func (lock *BaseLock) TryLock(l locker) (bool, error)

func (*BaseLock) Unlock

func (lock *BaseLock) Unlock(l locker) error

type FileLock

type FileLock struct {
	BaseLock
	LocksDir string
	// contains filtered or unexported fields
}

func (*FileLock) Lock

func (lock *FileLock) Lock(timeout time.Duration, readOnly bool, onWait func(doWait func() error) error) error

func (*FileLock) LockFilePath

func (lock *FileLock) LockFilePath() string

func (*FileLock) TryLock

func (lock *FileLock) TryLock(readOnly bool) (bool, error)

func (*FileLock) Unlock

func (lock *FileLock) Unlock() error

type LockObject

type LockObject interface {
	GetName() string
	TryLock(readOnly bool) (bool, error)
	Lock(timeout time.Duration, readOnly bool, onWait func(doWait func() error) error) error
	Unlock() error
}

func NewFileLock

func NewFileLock(name, locksDir string) LockObject

Jump to

Keyboard shortcuts

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