Skip to content
Snippets Groups Projects
Unverified Commit f69d4bc8 authored by capossele's avatar capossele
Browse files

:construction: Split vote context to fit into an FPC update

parent 11162ca8
Branches
No related tags found
No related merge requests found
...@@ -29,6 +29,8 @@ const ( ...@@ -29,6 +29,8 @@ const (
CfgServerAddress = "analysis.client.serverAddress" CfgServerAddress = "analysis.client.serverAddress"
// defines the report interval of the reporting in seconds. // defines the report interval of the reporting in seconds.
reportIntervalSec = 5 reportIntervalSec = 5
// maxVoteContext defines the maximum number of vote context to fit into an FPC update
maxVoteContext = 50
) )
func init() { func init() {
...@@ -148,10 +150,16 @@ func onRoundExecuted(roundStats *vote.RoundStats) { ...@@ -148,10 +150,16 @@ func onRoundExecuted(roundStats *vote.RoundStats) {
nodeID = local.GetInstance().ID().Bytes() nodeID = local.GetInstance().ID().Bytes()
} }
chunks := splitFPCVoteContext(roundStats.ActiveVoteContexts)
connLock.Lock()
defer connLock.Unlock()
for _, chunk := range chunks {
rs := vote.RoundStats{ rs := vote.RoundStats{
Duration: roundStats.Duration, Duration: roundStats.Duration,
RandUsed: roundStats.RandUsed, RandUsed: roundStats.RandUsed,
ActiveVoteContexts: roundStats.ActiveVoteContexts, ActiveVoteContexts: chunk,
} }
hb := &packet.FPCHeartbeat{ hb := &packet.FPCHeartbeat{
...@@ -167,10 +175,32 @@ func onRoundExecuted(roundStats *vote.RoundStats) { ...@@ -167,10 +175,32 @@ func onRoundExecuted(roundStats *vote.RoundStats) {
log.Info("Client: onRoundExecuted data size: ", len(data)) log.Info("Client: onRoundExecuted data size: ", len(data))
connLock.Lock()
defer connLock.Unlock()
if _, err = managedConn.Write(data); err != nil { if _, err = managedConn.Write(data); err != nil {
log.Debugw("Error while writing to connection", "Description", err) log.Debugw("Error while writing to connection", "Description", err)
return return
} }
} }
}
func splitFPCVoteContext(ctx map[string]*vote.Context) (chunk []map[string]*vote.Context) {
chunk = make([]map[string]*vote.Context, 1)
i, counter := 0, 0
chunk[i] = make(map[string]*vote.Context)
if len(ctx) < maxVoteContext {
chunk[i] = ctx
return
}
for conflictID, voteCtx := range ctx {
counter++
if counter >= maxVoteContext {
counter = 0
i++
chunk = append(chunk, make(map[string]*vote.Context))
}
chunk[i][conflictID] = voteCtx
}
return
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment