core/rawdb: use tryRLock if readonly

Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
jsvisa 2023-09-22 16:18:37 +08:00
parent 83f3fc2e80
commit 637347f2ac

View file

@ -108,7 +108,13 @@ func NewFreezer(datadir string, namespace string, readonly bool, maxTableSize ui
// Leveldb uses LOCK as the filelock filename. To prevent the
// name collision, we use FLOCK as the lock name.
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
} else if !locked {
return nil, errors.New("locking failed")