Skip to content

Commit 9066f8f

Browse files
kopaygorodskymergify[bot]
authored andcommitted
Fixed active nodes metrics for etcdraft when a node is evicted. Instead of being frozen we set it to 0 once halt is called. Tests. (#3536)
Signed-off-by: Vladyslav Kopaihorodskyi <vlad.kopaygorodsky@gmail.com> (cherry picked from commit ba61a1b) # Conflicts: # orderer/consensus/etcdraft/chain_test.go
1 parent fb9551d commit 9066f8f

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

orderer/consensus/etcdraft/chain.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,9 @@ func (c *Chain) Halt() {
435435
if c.haltCallback != nil {
436436
c.haltCallback()
437437
}
438+
439+
// active nodes metric shouldn't be frozen once a channel is stopped.
440+
c.Metrics.ActiveNodes.Set(float64(0))
438441
}
439442

440443
func (c *Chain) isRunning() error {

orderer/consensus/etcdraft/chain_test.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,6 +1420,7 @@ var _ = Describe("Chain", func() {
14201420
c1.clock.Increment(interval)
14211421
return c2.fakeFields.fakeActiveNodes.SetCallCount()
14221422
}, LongEventualTimeout).Should(Equal(2))
1423+
Expect(c1.fakeFields.fakeActiveNodes.SetArgsForCall(1)).To(Equal(float64(2)))
14231424
Expect(c2.fakeFields.fakeActiveNodes.SetArgsForCall(1)).To(Equal(float64(2)))
14241425

14251426
By("Configuring cluster to remove node")
@@ -1432,10 +1433,75 @@ var _ = Describe("Chain", func() {
14321433
return c2.observe
14331434
}, LongEventualTimeout).Should(Receive(StateEqual(2, raft.StateLeader)))
14341435

1436+
<<<<<<< HEAD
1437+
=======
1438+
By("Asserting the haltCallback is called when the node is removed from the replica set")
1439+
Eventually(fakeHaltCallbacker.HaltCallbackCallCount).Should(Equal(1))
1440+
By("Asserting the StatusReport responds correctly after eviction")
1441+
Eventually(
1442+
func() orderer_types.ConsensusRelation {
1443+
cRel, _ := c1.StatusReport()
1444+
return cRel
1445+
},
1446+
).Should(Equal(orderer_types.ConsensusRelationConfigTracker))
1447+
_, status := c1.StatusReport()
1448+
Expect(status).To(Equal(orderer_types.StatusInactive))
1449+
1450+
By("Asserting leader can still serve requests as single-node cluster")
1451+
c2.cutter.CutNext = true
1452+
Expect(c2.Order(env, 0)).To(Succeed())
1453+
Eventually(c2.support.WriteBlockCallCount, LongEventualTimeout).Should(Equal(1))
1454+
Expect(c1.fakeFields.fakeActiveNodes.SetArgsForCall(2)).To(Equal(float64(0))) // was halted
1455+
Expect(c2.fakeFields.fakeActiveNodes.SetArgsForCall(1)).To(Equal(float64(2)))
1456+
})
1457+
1458+
It("remove leader by reconfiguring cluster, but Halt before eviction", func() {
1459+
network.elect(1)
1460+
1461+
// trigger status dissemination
1462+
Eventually(func() int {
1463+
c1.clock.Increment(interval)
1464+
return c2.fakeFields.fakeActiveNodes.SetCallCount()
1465+
}, LongEventualTimeout).Should(Equal(2))
1466+
Expect(c1.fakeFields.fakeActiveNodes.SetArgsForCall(1)).To(Equal(float64(2)))
1467+
Expect(c2.fakeFields.fakeActiveNodes.SetArgsForCall(1)).To(Equal(float64(2)))
1468+
1469+
By("Configuring cluster to remove node")
1470+
Expect(c1.Configure(configEnv, 0)).To(Succeed())
1471+
Eventually(c2.support.WriteConfigBlockCallCount, LongEventualTimeout).Should(Equal(1))
1472+
c1.clock.WaitForNWatchersAndIncrement((ELECTION_TICK-1)*interval, 2)
1473+
c1.Halt()
1474+
1475+
Eventually(func() <-chan raft.SoftState {
1476+
c2.clock.Increment(interval)
1477+
return c2.observe
1478+
}, LongEventualTimeout).Should(Receive(StateEqual(2, raft.StateLeader)))
1479+
1480+
>>>>>>> ba61a1be9 (Fixed active nodes metrics for etcdraft when a node is evicted. Instead of being frozen we set it to 0 once halt is called. Tests. (#3536))
14351481
By("Asserting leader can still serve requests as single-node cluster")
14361482
c2.cutter.CutNext = true
14371483
Expect(c2.Order(env, 0)).To(Succeed())
14381484
Eventually(c2.support.WriteBlockCallCount, LongEventualTimeout).Should(Equal(1))
1485+
<<<<<<< HEAD
1486+
=======
1487+
1488+
By("Asserting the haltCallback is not called when Halt is called before eviction")
1489+
c1.clock.Increment(interval)
1490+
Eventually(fakeHaltCallbacker.HaltCallbackCallCount).Should(Equal(0))
1491+
By("Asserting the StatusReport responds correctly if the haltCallback is not called")
1492+
Eventually(
1493+
func() orderer_types.Status {
1494+
_, status := c1.StatusReport()
1495+
return status
1496+
},
1497+
).Should(Equal(orderer_types.StatusInactive))
1498+
cRel, _ := c1.StatusReport()
1499+
Expect(cRel).To(Equal(orderer_types.ConsensusRelationConsenter))
1500+
1501+
// active nodes metric hasn't changed because c.halt() wasn't called
1502+
Expect(c1.fakeFields.fakeActiveNodes.SetArgsForCall(1)).To(Equal(float64(2)))
1503+
Expect(c2.fakeFields.fakeActiveNodes.SetArgsForCall(1)).To(Equal(float64(2)))
1504+
>>>>>>> ba61a1be9 (Fixed active nodes metrics for etcdraft when a node is evicted. Instead of being frozen we set it to 0 once halt is called. Tests. (#3536))
14391505
})
14401506

14411507
It("can remove leader by reconfiguring cluster even if leadership transfer fails", func() {

0 commit comments

Comments
 (0)