mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
core/rawdb: use tryRLock if readonly
Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
parent
83f3fc2e80
commit
637347f2ac
1 changed files with 7 additions and 1 deletions
|
|
@ -108,7 +108,13 @@ func NewFreezer(datadir string, namespace string, readonly bool, maxTableSize ui
|
||||||
// Leveldb uses LOCK as the filelock filename. To prevent the
|
// Leveldb uses LOCK as the filelock filename. To prevent the
|
||||||
// name collision, we use FLOCK as the lock name.
|
// name collision, we use FLOCK as the lock name.
|
||||||
lock := flock.New(flockFile)
|
lock := flock.New(flockFile)
|
||||||
if locked, err := lock.TryLock(); err != nil {
|
tryLock := func() (bool, error) {
|
||||||
|
if readonly {
|
||||||
|
return lock.TryRLock()
|
||||||
|
}
|
||||||
|
return lock.TryLock()
|
||||||
|
}
|
||||||
|
if locked, err := tryLock(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else if !locked {
|
} else if !locked {
|
||||||
return nil, errors.New("locking failed")
|
return nil, errors.New("locking failed")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue