node.go depend

This commit is contained in:
bai 2018-11-06 14:17:17 +08:00
parent ef1b8f65ae
commit 297e053a87

View file

@ -33,7 +33,7 @@ import (
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/rpc"
"github.com/prometheus/prometheus/util/flock" "github.com/theckman/go-flock"
) )
// Node is a container on which services can be registered. // Node is a container on which services can be registered.
@ -43,7 +43,7 @@ type Node struct {
accman *accounts.Manager accman *accounts.Manager
ephemeralKeystore string // if non-empty, the key directory that will be removed by Stop ephemeralKeystore string // if non-empty, the key directory that will be removed by Stop
instanceDirLock flock.Releaser // prevents concurrent use of instance directory instanceDirLock *flock.Flock // prevents concurrent use of instance directory
serverConfig p2p.Config serverConfig p2p.Config
server *p2p.Server // Currently running P2P networking layer server *p2p.Server // Currently running P2P networking layer
@ -238,11 +238,11 @@ func (n *Node) openDataDir() error {
} }
// Lock the instance directory to prevent concurrent use by another instance as well as // Lock the instance directory to prevent concurrent use by another instance as well as
// accidental use of the instance directory as a database. // accidental use of the instance directory as a database.
release, _, err := flock.New(filepath.Join(instdir, "LOCK")) n.instanceDirLock=flock.NewFlock(filepath.Join(instdir, "LOCK"))
_, err :=n.instanceDirLock.TryLock()
if err != nil { if err != nil {
return convertFileLockError(err) return convertFileLockError(err)
} }
n.instanceDirLock = release
return nil return nil
} }
@ -426,7 +426,7 @@ func (n *Node) Stop() error {
// Release instance directory lock. // Release instance directory lock.
if n.instanceDirLock != nil { if n.instanceDirLock != nil {
if err := n.instanceDirLock.Release(); err != nil { if err := n.instanceDirLock.Unlock(); err != nil {
n.log.Error("Can't release datadir lock", "err", err) n.log.Error("Can't release datadir lock", "err", err)
} }
n.instanceDirLock = nil n.instanceDirLock = nil