github.com/true-sqn/fabric@v2.1.1+incompatible/core/ledger/kvledger/rebuild_dbs.go (about)

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