github.com/hechain20/hechain@v0.0.0-20220316014945-b544036ba106/core/ledger/kvledger/drop_dbs.go (about) 1 /* 2 Copyright hechain. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package kvledger 8 9 import "github.com/hechain20/hechain/internal/fileutil" 10 11 func dropDBs(rootFSPath string) error { 12 // During block commits to stateDB, the transaction manager updates the bookkeeperDB and one of the 13 // state listener updates the config historyDB. As we drop the stateDB, we need to drop the 14 // configHistoryDB and bookkeeperDB too so that during the peer startup after the reset/rollback, 15 // we can get a correct configHistoryDB. 16 // Note that it is necessary to drop the stateDB first before dropping the config history and 17 // bookkeeper. Suppose if the config or bookkeeper is dropped first and the peer reset/rollback 18 // command fails before dropping the stateDB, peer cannot start with consistent data (if the 19 // user decides to start the peer without retrying the reset/rollback) as the stateDB would 20 // not be rebuilt. 21 if err := dropStateLevelDB(rootFSPath); err != nil { 22 return err 23 } 24 if err := dropConfigHistoryDB(rootFSPath); err != nil { 25 return err 26 } 27 if err := dropBookkeeperDB(rootFSPath); err != nil { 28 return err 29 } 30 return dropHistoryDB(rootFSPath) 31 } 32 33 func dropStateLevelDB(rootFSPath string) error { 34 stateLeveldbPath := StateDBPath(rootFSPath) 35 logger.Infof("Dropping all contents in StateLevelDB at location [%s] ...if present", stateLeveldbPath) 36 return fileutil.RemoveContents(stateLeveldbPath) 37 } 38 39 func dropConfigHistoryDB(rootFSPath string) error { 40 configHistoryDBPath := ConfigHistoryDBPath(rootFSPath) 41 logger.Infof("Dropping all contents in ConfigHistoryDB at location [%s] ...if present", configHistoryDBPath) 42 return fileutil.RemoveContents(configHistoryDBPath) 43 } 44 45 func dropBookkeeperDB(rootFSPath string) error { 46 bookkeeperDBPath := BookkeeperDBPath(rootFSPath) 47 logger.Infof("Dropping all contents in BookkeeperDB at location [%s] ...if present", bookkeeperDBPath) 48 return fileutil.RemoveContents(bookkeeperDBPath) 49 } 50 51 func dropHistoryDB(rootFSPath string) error { 52 historyDBPath := HistoryDBPath(rootFSPath) 53 logger.Infof("Dropping all contents under in HistoryDB at location [%s] ...if present", historyDBPath) 54 return fileutil.RemoveContents(historyDBPath) 55 }