Unverified Commit 0d247c1d authored by Jay Guo's avatar Jay Guo Committed by Artem Barger
Browse files

[FAB-13447] new leader should wait for in flight msg



Newly elected raft leader should wait for in flight blocks
to be committed, before accepting new envelopes and creating
new blocks. Otherwise all those blocks created would be uncle
blocks and we don't permit this situation in Fabric.

Change-Id: Ia5adac185263735eace1fc805ebea0f5c98b2fb1
Signed-off-by: default avatarJay Guo <guojiannan1101@gmail.com>
parent 348c677c
......@@ -407,13 +407,6 @@ func (c *Chain) serveRequest() {
c.justElected = true
submitC = nil
lastBlock := c.support.Block(c.support.Height() - 1)
bc = &blockCreator{
hash: lastBlock.Header.Hash(),
number: lastBlock.Header.Number,
logger: c.logger,
}
// if there is unfinished ConfChange, we should resume the effort to propose it as
// new leader, and wait for it to be committed before start serving new requests.
if cc := c.getInFlightConfChange(); cc != nil {
......@@ -496,7 +489,26 @@ func (c *Chain) serveRequest() {
c.apply(app.entries)
if !c.configInflight {
if c.justElected {
msgInflight := c.node.lastIndex() > c.appliedIndex
if msgInflight || c.configInflight {
c.logger.Debugf("There are in flight blocks, new leader should not serve requests")
continue
}
c.logger.Infof("Start accepting requests as Raft leader")
lastBlock := c.support.Block(c.support.Height() - 1)
bc = &blockCreator{
hash: lastBlock.Header.Hash(),
number: lastBlock.Header.Number,
logger: c.logger,
}
submitC = c.submitC
c.justElected = false
} else if c.configInflight {
c.logger.Debugf("Config block or ConfChange in flight, pause accepting transaction")
submitC = nil
} else {
submitC = c.submitC
}
......
......@@ -123,3 +123,8 @@ func (n *node) takeSnapshot(index uint64, cs *raftpb.ConfState, data []byte) {
n.logger.Panicf("Failed to create snapshot at index %d: %s", index, err)
}
}
func (n *node) lastIndex() uint64 {
i, _ := n.storage.ram.LastIndex()
return i
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment