MCPcopy
hub / github.com/hyperledger/fabric / Lock

Method Lock

common/ledger/util/leveldbhelper/leveldb_helper.go:206–226  ·  view source on GitHub ↗

Lock acquire a file lock. We achieve this by opening a db for the given filePath. Internally, leveldb acquires a file lock while opening a db. If the db is opened again by the same or another process, error would be returned. When the db is closed or the owner process dies, the lock would be release

()

Source from the content-addressed store, hash-verified

204// functionality to acquire and release file lock as the leveldb
205// supports this for Windows, Solaris, and Unix.
206func (f *FileLock) Lock() error {
207 dbOpts := &opt.Options{}
208 var err error
209 var dirEmpty bool
210 if dirEmpty, err = fileutil.CreateDirIfMissing(f.filePath); err != nil {
211 panic(fmt.Sprintf("Error creating dir if missing: %s", err))
212 }
213 dbOpts.ErrorIfMissing = !dirEmpty
214 db, err := leveldb.OpenFile(f.filePath, dbOpts)
215 if err != nil && err == syscall.EAGAIN {
216 return errors.Errorf("lock is already acquired on file %s", f.filePath)
217 }
218 if err != nil {
219 panic(fmt.Sprintf("Error acquiring lock on file %s: %s", f.filePath, err))
220 }
221
222 // only mutate the lock db reference AFTER validating that the lock was held.
223 f.db = db
224
225 return nil
226}
227
228// Determine if the lock is currently held open.
229func (f *FileLock) IsLocked() bool {

Callers 15

NewStoreProviderFunction · 0.95
DropFunction · 0.95
ResetAllKVLedgersFunction · 0.95
NewProviderFunction · 0.95
UpgradeDBsFunction · 0.95
RollbackKVLedgerFunction · 0.95
RebuildDBsFunction · 0.95
UnjoinChannelFunction · 0.95
pauseOrResumeChannelFunction · 0.95
TestFileLockFunction · 0.95

Calls 2

CreateDirIfMissingFunction · 0.92
ErrorfMethod · 0.65

Tested by 15

TestFileLockFunction · 0.76
measureTPSFunction · 0.64
FetchStateMethod · 0.64
thatMapsToMethod · 0.64
AccessFilterMethod · 0.64