github.com/true-sqn/fabric@v2.1.1+incompatible/core/ledger/kvledger/drop_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 "os" 11 12 "github.com/pkg/errors" 13 ) 14 15 func dropDBs(rootFSPath string) error { 16 // During block commits to stateDB, the transaction manager updates the bookkeeperDB and one of the 17 // state listener updates the config historyDB. As we drop the stateDB, we need to drop the 18 // configHistoryDB and bookkeeperDB too so that during the peer startup after the reset/rollback, 19 // we can get a correct configHistoryDB. 20 // Note that it is necessary to drop the stateDB first before dropping the config history and 21 // bookkeeper. Suppose if the config or bookkeeper is dropped first and the peer reset/rollback 22 // command fails before dropping the stateDB, peer cannot start with consistent data (if the 23 // user decides to start the peer without retrying the reset/rollback) as the stateDB would 24 // not be rebuilt. 25 if err := dropStateLevelDB(rootFSPath); err != nil { 26 return err 27 } 28 if err := dropConfigHistoryDB(rootFSPath); err != nil { 29 return err 30 } 31 if err := dropBookkeeperDB(rootFSPath); err != nil { 32 return err 33 } 34 if err := dropHistoryDB(rootFSPath); err != nil { 35 return err 36 } 37 return nil 38 } 39 40 func dropStateLevelDB(rootFSPath string) error { 41 stateLeveldbPath := StateDBPath(rootFSPath) 42 logger.Infof("Dropping StateLevelDB at location [%s] ...if present", stateLeveldbPath) 43 return os.RemoveAll(stateLeveldbPath) 44 } 45 46 func dropConfigHistoryDB(rootFSPath string) error { 47 configHistoryDBPath := ConfigHistoryDBPath(rootFSPath) 48 logger.Infof("Dropping ConfigHistoryDB at location [%s]", configHistoryDBPath) 49 err := os.RemoveAll(configHistoryDBPath) 50 return errors.Wrapf(err, "error removing the ConfigHistoryDB located at %s", configHistoryDBPath) 51 } 52 53 func dropBookkeeperDB(rootFSPath string) error { 54 bookkeeperDBPath := BookkeeperDBPath(rootFSPath) 55 logger.Infof("Dropping BookkeeperDB at location [%s]", bookkeeperDBPath) 56 err := os.RemoveAll(bookkeeperDBPath) 57 return errors.Wrapf(err, "error removing the BookkeeperDB located at %s", bookkeeperDBPath) 58 } 59 60 func dropHistoryDB(rootFSPath string) error { 61 historyDBPath := HistoryDBPath(rootFSPath) 62 logger.Infof("Dropping HistoryDB at location [%s] ...if present", historyDBPath) 63 return os.RemoveAll(historyDBPath) 64 }