forked from hyperledger/fabric
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rebuild_dbs.go
32 lines (26 loc) · 916 Bytes
/
rebuild_dbs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package kvledger
import (
"github.com/hyperledger/fabric/common/ledger/blkstorage/fsblkstorage"
"github.com/hyperledger/fabric/common/ledger/util/leveldbhelper"
"github.com/pkg/errors"
)
// RebuildDBs drops existing ledger databases.
// Dropped database will be rebuilt upon server restart
func RebuildDBs(rootFSPath string) error {
fileLockPath := fileLockPath(rootFSPath)
fileLock := leveldbhelper.NewFileLock(fileLockPath)
if err := fileLock.Lock(); err != nil {
return errors.Wrap(err, "as another peer node command is executing,"+
" wait for that command to complete its execution or terminate it before retrying")
}
defer fileLock.Unlock()
if err := dropDBs(rootFSPath); err != nil {
return err
}
blockstorePath := BlockStorePath(rootFSPath)
return fsblkstorage.DeleteBlockStoreIndex(blockstorePath)
}