Skip to content
Snippets Groups Projects
Commit 19f27134 authored by Jake Taylor's avatar Jake Taylor :lips:
Browse files

Merge branch 'hotfix/CompletedTS' into 'release'

added completed timestamp to database

See merge request !28
parents c38793c7 59dc8a11
No related branches found
No related tags found
2 merge requests!30Release,!28added completed timestamp to database
......@@ -90,16 +90,6 @@ func HandleNodeUpdates(update node.UpdateNotification, pool *waitingPool, state
"not be moving to the %s state", update.Node, states.PRECOMPUTING)
}
// fixme: nodes selected from pool are assigned to precomp in start round, inherently are synced
//stateComplete := r.NodeIsReadyForTransition()
//if stateComplete {
// err := r.Update(states.PRECOMPUTING, time.Now())
// if err != nil {
// return errors.WithMessagef(err,
// "Could not move round %v from %s to %s",
// r.GetRoundID(), states.PENDING, states.PRECOMPUTING)
// }
//}
case current.STANDBY:
// Check that node in standby actually does have a round
if !hasRound {
......@@ -170,6 +160,12 @@ func HandleNodeUpdates(update node.UpdateNotification, pool *waitingPool, state
// Clear the round
n.ClearRound()
// Keep track of when the first node reached the completed state
if r.GetTopology().IsLastNode(n.GetID()) {
r.SetRealtimeCompletedTs(time.Now().UnixNano())
}
// Check if the round is ready for all the nodes
// in order to transition
stateComplete := r.NodeIsReadyForTransition()
......@@ -197,7 +193,7 @@ func HandleNodeUpdates(update node.UpdateNotification, pool *waitingPool, state
roundTracker.RemoveActiveRound(r.GetRoundID())
// Store round metric in another thread for completed round
go StoreRoundMetric(roundInfo, states.COMPLETED)
go StoreRoundMetric(roundInfo, r.GetRoundState(), r.GetRealtimeCompletedTs())
// Commit metrics about the round to storage
return nil
......@@ -219,13 +215,14 @@ func HandleNodeUpdates(update node.UpdateNotification, pool *waitingPool, state
}
// Insert metrics about the newly-completed round into storage
func StoreRoundMetric(roundInfo *pb.RoundInfo, realtimeEnd states.Round) {
func StoreRoundMetric(roundInfo *pb.RoundInfo, roundEnd states.Round, realtimeTs int64) {
metric := &storage.RoundMetric{
Id: roundInfo.ID,
PrecompStart: time.Unix(0, int64(roundInfo.Timestamps[states.PRECOMPUTING])),
PrecompEnd: time.Unix(0, int64(roundInfo.Timestamps[states.STANDBY])),
RealtimeStart: time.Unix(0, int64(roundInfo.Timestamps[states.REALTIME])),
RealtimeEnd: time.Unix(0, int64(roundInfo.Timestamps[realtimeEnd])),
RealtimeEnd: time.Unix(0, realtimeTs),
RoundEnd: time.Unix(0, int64(roundInfo.Timestamps[roundEnd])),
BatchSize: roundInfo.BatchSize,
}
......@@ -265,7 +262,7 @@ func killRound(state *storage.NetworkState, r *round.State,
go func() {
// Attempt to insert the RoundMetric for the failed round
StoreRoundMetric(roundInfo, states.FAILED)
StoreRoundMetric(roundInfo, r.GetRoundState(), 0)
// Return early if there is no roundError
if roundError == nil {
......
......@@ -202,6 +202,7 @@ type RoundMetric struct {
PrecompEnd time.Time `gorm:"NOT NULL;INDEX;"`
RealtimeStart time.Time `gorm:"NOT NULL"`
RealtimeEnd time.Time `gorm:"NOT NULL;INDEX;"` // Index for TPS calc
RoundEnd time.Time `gorm:"NOT NULL;INDEX;default:to_timestamp(0)"` // Index for TPS calc
BatchSize uint32 `gorm:"NOT NULL"`
// Each RoundMetric has many Nodes participating in each Round
......
......@@ -43,6 +43,10 @@ type State struct {
lastUpdate time.Time
// Keep track of the ns timestamp when the last node in the round reported completed
// in order to get better granularity for when realtime finished
realtimeCompletedTs int64
mux sync.RWMutex
}
......@@ -175,6 +179,16 @@ func (s *State) GetRoundID() id.Round {
return rid
}
// Return firstCompletedTs
func (s *State) GetRealtimeCompletedTs() int64 {
return s.realtimeCompletedTs
}
// Set firstCompletedTs
func (s *State) SetRealtimeCompletedTs(ts int64) {
s.realtimeCompletedTs = ts
}
// Append a round error to our list of stored rounderrors
func (s *State) AppendError(roundError *pb.RoundError) {
s.mux.Lock()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment