github.com/true-sqn/fabric@v2.1.1+incompatible/core/ledger/kvledger/pause_resume.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/util/leveldbhelper" 11 "github.com/hyperledger/fabric/core/ledger/kvledger/msgs" 12 "github.com/pkg/errors" 13 ) 14 15 // PauseChannel updates the channel status to inactive in ledgerProviders. 16 func PauseChannel(rootFSPath, ledgerID string) error { 17 if err := pauseOrResumeChannel(rootFSPath, ledgerID, msgs.Status_INACTIVE); err != nil { 18 return err 19 } 20 logger.Infof("The channel [%s] has been successfully paused", ledgerID) 21 return nil 22 } 23 24 // ResumeChannel updates the channel status to active in ledgerProviders 25 func ResumeChannel(rootFSPath, ledgerID string) error { 26 if err := pauseOrResumeChannel(rootFSPath, ledgerID, msgs.Status_ACTIVE); err != nil { 27 return err 28 } 29 logger.Infof("The channel [%s] has been successfully resumed", ledgerID) 30 return nil 31 } 32 33 func pauseOrResumeChannel(rootFSPath, ledgerID string, status msgs.Status) error { 34 fileLock := leveldbhelper.NewFileLock(fileLockPath(rootFSPath)) 35 if err := fileLock.Lock(); err != nil { 36 return errors.Wrap(err, "as another peer node command is executing,"+ 37 " wait for that command to complete its execution or terminate it before retrying") 38 } 39 defer fileLock.Unlock() 40 41 idStore, err := openIDStore(LedgerProviderPath(rootFSPath)) 42 if err != nil { 43 return err 44 } 45 defer idStore.db.Close() 46 return idStore.updateLedgerStatus(ledgerID, status) 47 }