github.com/osdi23p228/fabric@v0.0.0-20221218062954-77808885f5db/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 "github.com/osdi23p228/fabric/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 if err := dropHistoryDB(rootFSPath); err != nil { 31 return err 32 } 33 return nil 34 } 35 36 func dropStateLevelDB(rootFSPath string) error { 37 stateLeveldbPath := StateDBPath(rootFSPath) 38 logger.Infof("Dropping all contents in StateLevelDB at location [%s] ...if present", stateLeveldbPath) 39 return fileutil.RemoveContents(stateLeveldbPath) 40 } 41 42 func dropConfigHistoryDB(rootFSPath string) error { 43 configHistoryDBPath := ConfigHistoryDBPath(rootFSPath) 44 logger.Infof("Dropping all contents in ConfigHistoryDB at location [%s] ...if present", configHistoryDBPath) 45 return fileutil.RemoveContents(configHistoryDBPath) 46 } 47 48 func dropBookkeeperDB(rootFSPath string) error { 49 bookkeeperDBPath := BookkeeperDBPath(rootFSPath) 50 logger.Infof("Dropping all contents in BookkeeperDB at location [%s] ...if present", bookkeeperDBPath) 51 return fileutil.RemoveContents(bookkeeperDBPath) 52 } 53 54 func dropHistoryDB(rootFSPath string) error { 55 historyDBPath := HistoryDBPath(rootFSPath) 56 logger.Infof("Dropping all contents under in HistoryDB at location [%s] ...if present", historyDBPath) 57 return fileutil.RemoveContents(historyDBPath) 58 }