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

[FAB-14129] Add more logs to etcdraft chain



This CR adds more debug logs to etcdraft chain to facilitate debugging.

Change-Id: I2d70869bc8823babb3ab50782bd4472637ed5820
Signed-off-by: default avatarJay Guo <guojiannan1101@gmail.com>
parent bd791cc3
......@@ -34,12 +34,14 @@ func (bc *blockCreator) createNextBlock(envs []*cb.Envelope) *cb.Block {
}
}
block := cb.NewBlock(bc.number+1, bc.hash)
bc.number++
block := cb.NewBlock(bc.number, bc.hash)
block.Header.DataHash = data.Hash()
block.Data = data
bc.hash = block.Header.Hash()
bc.number++
bc.logger.Debugf("Created block %d", bc.number)
return block
}
......@@ -517,8 +517,14 @@ func (c *Chain) serveRequest() {
}
c.propose(bc, batches...)
if c.configInflight || c.blockInflight >= c.opts.MaxInflightMsgs {
submitC = nil // stop accepting new envelopes
if c.configInflight {
c.logger.Info("Received config block, pause accepting transaction till it is committed")
submitC = nil
} else if c.blockInflight >= c.opts.MaxInflightMsgs {
c.logger.Debugf("Number of in-flight blocks (%d) reaches limit (%d), pause accepting transaction",
c.blockInflight, c.opts.MaxInflightMsgs)
submitC = nil
}
case app := <-c.applyC:
......@@ -581,7 +587,7 @@ func (c *Chain) serveRequest() {
submitC = c.submitC
c.justElected = false
} else if c.configInflight {
c.logger.Debugf("Config block or ConfChange in flight, pause accepting transaction")
c.logger.Info("Config block or ConfChange in flight, pause accepting transaction")
submitC = nil
} else if c.blockInflight < c.opts.MaxInflightMsgs {
submitC = c.submitC
......@@ -633,6 +639,8 @@ func (c *Chain) writeBlock(block *common.Block, index uint64) {
c.blockInflight-- // only reduce on leader
}
c.logger.Debugf("Writing block %d to ledger, there are %d blocks in flight", block.Header.Number, c.blockInflight)
if utils.IsConfigBlock(block) {
c.writeConfigBlock(block, index)
return
......@@ -697,6 +705,7 @@ func (c *Chain) propose(bc *blockCreator, batches ...[]*common.Envelope) {
}
c.blockInflight++
c.logger.Debugf("Proposed block %d to raft consensus, there are %d blocks in flight", b.Header.Number, c.blockInflight)
}
return
......@@ -754,9 +763,14 @@ func (c *Chain) apply(ents []raftpb.Entry) {
for i := range ents {
switch ents[i].Type {
case raftpb.EntryNormal:
if len(ents[i].Data) == 0 {
break
}
// We need to strictly avoid re-applying normal entries,
// otherwise we are writing the same block twice.
if len(ents[i].Data) == 0 || ents[i].Index <= c.appliedIndex {
if ents[i].Index <= c.appliedIndex {
c.logger.Debugf("Received block with raft index (%d) <= applied index (%d), skip", ents[i].Index, c.appliedIndex)
break
}
......@@ -776,6 +790,15 @@ func (c *Chain) apply(ents []raftpb.Entry) {
c.confState = *c.node.ApplyConfChange(cc)
switch cc.Type {
case raftpb.ConfChangeAddNode:
c.logger.Infof("Applied config change to add node %d, current nodes in channel: %+v", cc.NodeID, c.confState.Nodes)
case raftpb.ConfChangeRemoveNode:
c.logger.Infof("Applied config change to remove node %d, current nodes in channel: %+v", cc.NodeID, c.confState.Nodes)
default:
c.logger.Panic("Programming error, encountered unsupported raft config change")
}
// This ConfChange was introduced by a previously committed config block,
// we can now unblock submitC to accept envelopes.
if c.confChangeInProgress != nil &&
......@@ -946,6 +969,15 @@ func (c *Chain) writeConfigBlock(block *common.Block, index uint64) {
c.opts.RaftMetadata = raftMetadata
c.raftMetadataLock.Unlock()
switch confChange.Type {
case raftpb.ConfChangeAddNode:
c.logger.Infof("Config block just committed adds node %d, pause accepting transactions till config change is applied", confChange.NodeID)
case raftpb.ConfChangeRemoveNode:
c.logger.Infof("Config block just committed removes node %d, pause accepting transactions till config change is applied", confChange.NodeID)
default:
c.logger.Panic("Programming error, encountered unsupported raft config change")
}
c.configInflight = true
}
}
......
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