Skip to content
Snippets Groups Projects
Commit 67a686ac authored by Benjamin Wenger's avatar Benjamin Wenger
Browse files

Merge branch 'hotfix/refactorKillRound' into 'release'

refactor killround to be clearer and more efficient

See merge request !69
parents 46ae14ad 423f1b46
No related branches found
No related tags found
2 merge requests!70Release,!69refactor killround to be clearer and more efficient
......@@ -290,6 +290,27 @@ func killRound(state *storage.NetworkState, r *round.State,
"update to kill round %v", roundId)
}
// Determine how many nodes have killed the round
numClearedNodes := 0
topology := r.GetTopology()
topologyLen := topology.Len()
for i := 0; i < topologyLen; i++ {
nId := topology.GetNodeAtIndex(i)
nodeState := state.GetNodeMap().GetNode(nId)
hasRound, roundState := nodeState.GetCurrentRound()
if !hasRound || roundState.GetRoundID() != roundId {
numClearedNodes += 1
}
}
if allNodesCleared := numClearedNodes == topologyLen; allNodesCleared {
// Ensure that every member of the round topology is done with the round
// inside the NodeMap before finally removing it in order to prevent
// infinite growth.
state.GetRoundMap().DeleteRound(roundId)
} else if isFirstToClear := numClearedNodes == 1; isFirstToClear {
// Ensure we only store round metrics for the first node to kill
// the round in order to prevent pointless duplicate inserts.
go func() {
// Attempt to insert the RoundMetric for the failed round
StoreRoundMetric(roundInfo, r.GetRoundState(), 0)
......@@ -316,19 +337,7 @@ func killRound(state *storage.NetworkState, r *round.State,
jww.WARN.Printf("Could not insert round error: %+v", err)
}
}()
// Ensure that every member of the round topology is done with the round
// inside the NodeMap before finally removing it in order to prevent
// infinite growth.
topology := r.GetTopology()
for i := 0; i < topology.Len(); i++ {
nId := topology.GetNodeAtIndex(i)
nodeState := state.GetNodeMap().GetNode(nId)
hasRound, roundState := nodeState.GetCurrentRound()
if hasRound && roundState.GetRoundID() == roundId {
return nil
}
}
state.GetRoundMap().DeleteRound(roundId)
return nil
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment