From e90788bf7c2eb3385d9a7f0674a63551dbfe9590 Mon Sep 17 00:00:00 2001 From: Fedor Partanskiy Date: Mon, 8 Jan 2024 17:55:46 +0300 Subject: [PATCH] find and fix error Signed-off-by: Fedor Partanskiy --- integration/raft/config_test.go | 2 +- orderer/common/multichannel/registrar.go | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/integration/raft/config_test.go b/integration/raft/config_test.go index fe66e4459a7..fe1ab7dd6a4 100644 --- a/integration/raft/config_test.go +++ b/integration/raft/config_test.go @@ -1261,7 +1261,7 @@ var _ = Describe("EndToEnd reconfiguration and onboarding", func() { o2 := network.Orderer("orderer2") o3 := network.Orderer("orderer3") - By("Waiting for them to elect a leader") + By("Waiting for them to select a leader") FindLeader(ordererRunners) assertBlockReception(map[string]int{ diff --git a/orderer/common/multichannel/registrar.go b/orderer/common/multichannel/registrar.go index 61f10d44236..91998e67a13 100644 --- a/orderer/common/multichannel/registrar.go +++ b/orderer/common/multichannel/registrar.go @@ -47,9 +47,10 @@ var logger = flogging.MustGetLogger("orderer.common.multichannel") type Registrar struct { config localconfig.TopLevel - lock sync.RWMutex - chains map[string]*ChainSupport - followers map[string]*follower.Chain + lock sync.RWMutex + removeChLock sync.Mutex + chains map[string]*ChainSupport + followers map[string]*follower.Chain // existence indicates removal is in-progress or failed // when failed, the status will indicate failed all other states // denote an in-progress removal @@ -489,6 +490,11 @@ func (r *Registrar) createNewChain(configtx *cb.Envelope) *ChainSupport { // It is called when a follower detects a config block that indicates cluster membership and halts, transferring // execution to the consensus.Chain. func (r *Registrar) SwitchFollowerToChain(channelID string) { + if !r.removeChLock.TryLock() { + return + } + defer r.removeChLock.Unlock() + r.lock.Lock() defer r.lock.Unlock() @@ -504,7 +510,7 @@ func (r *Registrar) SwitchFollowerToChain(channelID string) { delete(r.followers, channelID) logger.Debugf("Removed follower for channel %s", channelID) cs := r.createNewChain(configTx(lf)) - if err := r.removeJoinBlock(channelID); err != nil { + if err = r.removeJoinBlock(channelID); err != nil { logger.Panicf("Failed removing join-block for channel: %s: %v", channelID, err) } cs.start() @@ -767,6 +773,9 @@ func (r *Registrar) createFollower( // RemoveChannel instructs the orderer to remove a channel. func (r *Registrar) RemoveChannel(channelID string) error { + r.removeChLock.Lock() + defer r.removeChLock.Unlock() + r.lock.Lock() defer r.lock.Unlock()