MCPcopy
hub / github.com/prometheus/prometheus / Lock

Method Lock

tsdb/tsdbutil/dir_locker.go:69–88  ·  view source on GitHub ↗

Lock obtains the lock on the locker directory.

()

Source from the content-addressed store, hash-verified

67
68// Lock obtains the lock on the locker directory.
69func (l *DirLocker) Lock() error {
70 if l.releaser != nil {
71 return errors.New("DB lock already obtained")
72 }
73
74 if _, err := os.Stat(l.path); err == nil {
75 l.logger.Warn("A lockfile from a previous execution already existed. It was replaced", "file", l.path)
76
77 l.createdCleanly.Set(lockfileReplaced)
78 } else {
79 l.createdCleanly.Set(lockfileCreatedCleanly)
80 }
81
82 lockf, _, err := fileutil.Flock(l.path)
83 if err != nil {
84 return fmt.Errorf("lock DB directory: %w", err)
85 }
86 l.releaser = lockf
87 return nil
88}
89
90// Release releases the lock. No-op if the lock is not held.
91func (l *DirLocker) Release() error {

Callers 15

TestLockfileFunction · 0.95
OpenFunction · 0.95
TrackReadAfterMethod · 0.80
CloseMethod · 0.80
TestDelayedCompactionFunction · 0.80
TestHeadChunkReaderCacheFunction · 0.80
AppendMethod · 0.80
appendFloatMethod · 0.80
appendHistogramMethod · 0.80
appendFloatHistogramMethod · 0.80

Calls 3

FlockFunction · 0.92
StatMethod · 0.80
SetMethod · 0.65