core/rawdb, node: use standalone flock dependency (#26633)
This commit is contained in:
+16
-16
@@ -37,7 +37,7 @@ import (
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/p2p"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
"github.com/prometheus/tsdb/fileutil"
|
||||
"github.com/gofrs/flock"
|
||||
)
|
||||
|
||||
// Node is a container on which services can be registered.
|
||||
@@ -46,13 +46,13 @@ type Node struct {
|
||||
config *Config
|
||||
accman *accounts.Manager
|
||||
log log.Logger
|
||||
keyDir string // key store directory
|
||||
keyDirTemp bool // If true, key directory will be removed by Stop
|
||||
dirLock fileutil.Releaser // prevents concurrent use of instance directory
|
||||
stop chan struct{} // Channel to wait for termination notifications
|
||||
server *p2p.Server // Currently running P2P networking layer
|
||||
startStopLock sync.Mutex // Start/Stop are protected by an additional lock
|
||||
state int // Tracks state of node lifecycle
|
||||
keyDir string // key store directory
|
||||
keyDirTemp bool // If true, key directory will be removed by Stop
|
||||
dirLock *flock.Flock // prevents concurrent use of instance directory
|
||||
stop chan struct{} // Channel to wait for termination notifications
|
||||
server *p2p.Server // Currently running P2P networking layer
|
||||
startStopLock sync.Mutex // Start/Stop are protected by an additional lock
|
||||
state int // Tracks state of node lifecycle
|
||||
|
||||
lock sync.Mutex
|
||||
lifecycles []Lifecycle // All registered backends, services, and auxiliary services that have a lifecycle
|
||||
@@ -320,20 +320,20 @@ func (n *Node) openDataDir() error {
|
||||
}
|
||||
// Lock the instance directory to prevent concurrent use by another instance as well as
|
||||
// accidental use of the instance directory as a database.
|
||||
release, _, err := fileutil.Flock(filepath.Join(instdir, "LOCK"))
|
||||
if err != nil {
|
||||
return convertFileLockError(err)
|
||||
n.dirLock = flock.New(filepath.Join(instdir, "LOCK"))
|
||||
|
||||
if locked, err := n.dirLock.TryLock(); err != nil {
|
||||
return err
|
||||
} else if !locked {
|
||||
return ErrDatadirUsed
|
||||
}
|
||||
n.dirLock = release
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n *Node) closeDataDir() {
|
||||
// Release instance directory lock.
|
||||
if n.dirLock != nil {
|
||||
if err := n.dirLock.Release(); err != nil {
|
||||
n.log.Error("Can't release datadir lock", "err", err)
|
||||
}
|
||||
if n.dirLock != nil && n.dirLock.Locked() {
|
||||
n.dirLock.Unlock()
|
||||
n.dirLock = nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user