Skip to content

Commit 492c2bb

Browse files
committed
[FAB-14462] Stop eviction check when chain halts
This change set stop the eviction once-per-10-seconds check when the chain is halted. Change-Id: Ifa51419a731fa2ea19046e2cb1e49e60c5af4aba Signed-off-by: yacovm <yacovm@il.ibm.com>
1 parent f5deb0f commit 492c2bb

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

integration/e2e/etcdraft_reconfig_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,7 @@ var _ = Describe("EndToEnd reconfiguration and onboarding", func() {
540540
Eventually(ordererRunner.Err(), time.Minute, time.Second).Should(evictionDetection)
541541

542542
By("Ensuring all blocks are pulled up to the block that evicts the OSN")
543+
Eventually(ordererRunner.Err(), time.Minute, time.Second).Should(gbytes.Say("Periodic check is stopping. channel=testchannel"))
543544
Eventually(ordererRunner.Err(), time.Minute, time.Second).Should(gbytes.Say("Pulled all blocks up to eviction block. channel=testchannel"))
544545

545546
By("Killing the evicted orderer")

orderer/consensus/etcdraft/chain.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ type Chain struct {
174174
logger *flogging.FabricLogger
175175

176176
migrationStatus migration.Status // The consensus-type migration status
177+
178+
periodicChecker *PeriodicCheck
177179
}
178180

179181
// NewChain constructs a chain object.
@@ -320,13 +322,13 @@ func (c *Chain) Start() {
320322

321323
es := c.newEvictionSuspector()
322324

323-
evictionFromChain := &PeriodicCheck{
325+
c.periodicChecker = &PeriodicCheck{
326+
Logger: c.logger,
324327
Report: es.confirmSuspicion,
325328
CheckInterval: time.Second * 10,
326329
Condition: c.suspectEviction,
327330
}
328-
329-
evictionFromChain.Run()
331+
c.periodicChecker.Run()
330332
}
331333

332334
// detectMigration detects if the orderer restarts right after consensus-type migration,
@@ -781,6 +783,7 @@ func (c *Chain) serveRequest() {
781783
}
782784

783785
c.logger.Infof("Stop serving requests")
786+
c.periodicChecker.Stop()
784787
return
785788
}
786789
}

orderer/consensus/etcdraft/util.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"encoding/pem"
1212
"fmt"
1313
"sync"
14+
"sync/atomic"
1415
"time"
1516

1617
"github.com/golang/protobuf/proto"
@@ -395,25 +396,40 @@ func ConfChange(raftMetadata *etcdraft.RaftMetadata, confState *raftpb.ConfState
395396
// PeriodicCheck checks periodically a condition, and reports
396397
// the cumulative consecutive period the condition was fulfilled.
397398
type PeriodicCheck struct {
399+
Logger *flogging.FabricLogger
398400
CheckInterval time.Duration
399401
Condition func() bool
400402
Report func(cumulativePeriod time.Duration)
401403
conditionHoldsSince time.Time
402404
once sync.Once // Used to prevent double initialization
405+
stopped uint32
403406
}
404407

405408
// Run runs the PeriodicCheck
406409
func (pc *PeriodicCheck) Run() {
407410
pc.once.Do(pc.check)
408411
}
409412

413+
// Stop stops the periodic checks
414+
func (pc *PeriodicCheck) Stop() {
415+
pc.Logger.Info("Periodic check is stopping.")
416+
atomic.AddUint32(&pc.stopped, 1)
417+
}
418+
419+
func (pc *PeriodicCheck) shouldRun() bool {
420+
return atomic.LoadUint32(&pc.stopped) == 0
421+
}
422+
410423
func (pc *PeriodicCheck) check() {
411424
if pc.Condition() {
412425
pc.conditionFulfilled()
413426
} else {
414427
pc.conditionNotFulfilled()
415428
}
416429

430+
if !pc.shouldRun() {
431+
return
432+
}
417433
time.AfterFunc(pc.CheckInterval, pc.check)
418434
}
419435

orderer/consensus/etcdraft/util_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ func TestPeriodicCheck(t *testing.T) {
296296
}
297297

298298
check := &PeriodicCheck{
299+
Logger: flogging.MustGetLogger("test"),
299300
Condition: condition,
300301
CheckInterval: time.Millisecond,
301302
Report: report,
@@ -346,6 +347,13 @@ func TestPeriodicCheck(t *testing.T) {
346347
// so the countdown has been reset when the condition was reset
347348
firstReport = <-reports
348349
g.Expect(lastReport).To(gomega.BeNumerically(">", firstReport))
350+
// Stop the periodic check.
351+
check.Stop()
352+
checkCountAfterStop := atomic.LoadUint32(&checkNum)
353+
// Wait 50 times the check interval.
354+
time.Sleep(check.CheckInterval * 50)
355+
// Ensure that we cease checking the condition, hence the PeriodicCheck is stopped.
356+
g.Expect(atomic.LoadUint32(&checkNum)).To(gomega.BeNumerically("<", checkCountAfterStop+2))
349357
}
350358

351359
func TestEvictionSuspector(t *testing.T) {

0 commit comments

Comments
 (0)