提交 f26388e0 作者: Brian Tiger Chow

fix(core) tear-down leveldb

@jbenet @whyrusleeping @mappum

If we permit initialization in `ipfs daemon`, then we must ensure that
the node instantiated in `ipfs init` (to create the welcome file) shuts
down and releases resources.

Kept running into "resource temporarily unavailable". Discovered that it
was our cousins Jeff and Sanjay over at LevelDB Ave.

go-datastore doesn't expose Close() so I extended the TsDs interface and
submitted a patch.

License: MIT
Signed-off-by: 's avatarBrian Tiger Chow <brian@perfmode.com>
Signed-off-by: 's avatarBrian Tiger Chow <brian.holderchow@gmail.com>
上级 ddb0189b
......@@ -48,7 +48,7 @@ type IpfsNode struct {
Peerstore peer.Peerstore
// the local datastore
Datastore ds.ThreadSafeDatastore
Datastore ds.ThreadSafeDatastoreCloser
// the network message stream
Network inet.Network
......@@ -192,6 +192,11 @@ func NewIpfsNode(cfg *config.Config, online bool) (n *IpfsNode, err error) {
return n, nil
}
func (n *IpfsNode) Close() {
n.ContextCloser.Close()
n.Datastore.Close()
}
func (n *IpfsNode) OnlineMode() bool {
return n.onlineMode
}
......
......@@ -14,7 +14,7 @@ import (
u "github.com/jbenet/go-ipfs/util"
)
func makeDatastore(cfg config.Datastore) (ds.ThreadSafeDatastore, error) {
func makeDatastore(cfg config.Datastore) (ds.ThreadSafeDatastoreCloser, error) {
if len(cfg.Type) == 0 {
return nil, fmt.Errorf("config datastore.type required")
}
......@@ -39,7 +39,7 @@ func makeDatastore(cfg config.Datastore) (ds.ThreadSafeDatastore, error) {
return nil, fmt.Errorf("Unknown datastore type: %s", cfg.Type)
}
func makeLevelDBDatastore(cfg config.Datastore) (ds.ThreadSafeDatastore, error) {
func makeLevelDBDatastore(cfg config.Datastore) (ds.ThreadSafeDatastoreCloser, error) {
if len(cfg.Path) == 0 {
return nil, fmt.Errorf("config datastore.path required for leveldb")
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论