make repo.Blockstore() idempotent; wrap in IDStore.
This commit is contained in:
parent
d8d85373f5
commit
5a98660d1b
@ -23,6 +23,7 @@ import (
|
||||
|
||||
"github.com/filecoin-project/lotus/extern/sector-storage/fsutil"
|
||||
"github.com/filecoin-project/lotus/extern/sector-storage/stores"
|
||||
lblockstore "github.com/filecoin-project/lotus/lib/blockstore"
|
||||
badgerbs "github.com/filecoin-project/lotus/lib/blockstore/badger"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
@ -259,6 +260,10 @@ type fsLockedRepo struct {
|
||||
dsErr error
|
||||
dsOnce sync.Once
|
||||
|
||||
bs blockstore.Blockstore
|
||||
bsErr error
|
||||
bsOnce sync.Once
|
||||
|
||||
storageLk sync.Mutex
|
||||
configLk sync.Mutex
|
||||
}
|
||||
@ -281,6 +286,13 @@ func (fsr *fsLockedRepo) Close() error {
|
||||
}
|
||||
}
|
||||
|
||||
// type assertion will return ok=false if fsr.bs is nil altogether.
|
||||
if c, ok := fsr.bs.(io.Closer); ok && c != nil {
|
||||
if err := c.Close(); err != nil {
|
||||
return xerrors.Errorf("could not close blockstore: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
err = fsr.closer.Close()
|
||||
fsr.closer = nil
|
||||
return err
|
||||
@ -292,14 +304,24 @@ func (fsr *fsLockedRepo) Blockstore(domain BlockstoreDomain) (blockstore.Blockst
|
||||
return nil, ErrInvalidBlockstoreDomain
|
||||
}
|
||||
|
||||
fsr.bsOnce.Do(func() {
|
||||
path := fsr.join(filepath.Join(fsDatastore, "chain"))
|
||||
readonly := fsr.readonly
|
||||
|
||||
opts, err := BadgerBlockstoreOptions(domain, path, readonly)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
fsr.bsErr = err
|
||||
return
|
||||
}
|
||||
return badgerbs.Open(opts)
|
||||
|
||||
bs, err := badgerbs.Open(opts)
|
||||
if err != nil {
|
||||
fsr.bsErr = err
|
||||
}
|
||||
fsr.bs = lblockstore.WrapIDStore(bs)
|
||||
})
|
||||
|
||||
return fsr.bs, fsr.bsErr
|
||||
}
|
||||
|
||||
// join joins path elements with fsr.path
|
||||
|
@ -161,7 +161,7 @@ func NewMemory(opts *MemRepoOptions) *MemRepo {
|
||||
|
||||
return &MemRepo{
|
||||
repoLock: make(chan struct{}, 1),
|
||||
blockstore: lblockstore.NewTemporarySync(),
|
||||
blockstore: lblockstore.WrapIDStore(lblockstore.NewTemporarySync()),
|
||||
datastore: opts.Ds,
|
||||
configF: opts.ConfigF,
|
||||
keystore: opts.KeyStore,
|
||||
|
Loading…
Reference in New Issue
Block a user