Skip to content

Commit

Permalink
Return true or false from AddData().
Browse files Browse the repository at this point in the history
Returns false and aborts the data addition if there is no change in the delta.
Use this to shortcut applyUpdateFromNewState() which prevents sending out
notifications for empty deltas.
  • Loading branch information
cjeker committed Feb 29, 2024
1 parent 03532ba commit 277cd1e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
7 changes: 5 additions & 2 deletions cmd/stayrtr/stayrtr.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,10 +445,13 @@ func (s *state) applyUpdateFromNewState(vrps []rtr.VRP, brks []rtr.BgpsecKey, va
for _, v := range vaps {
SDs = append(SDs, v.Copy())
}
s.server.AddData(SDs)
if (s.server.AddData(SDs) == false) {
log.Info("No difference to current cache")
return nil
}

serial, _ := s.server.GetCurrentSerial(sessid)
log.Infof("Updated added, new serial %v", serial)
log.Infof("Update added, new serial %v", serial)
if s.sendNotifs {
log.Debugf("Sending notifications to clients")
s.server.NotifyClientsLatest()
Expand Down
9 changes: 7 additions & 2 deletions lib/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ func (s *Server) CountSDs() int {
return len(s.sdCurrent)
}

func (s *Server) AddData(new []SendableData) {
func (s *Server) AddData(new []SendableData) bool {
s.sdlock.RLock()

added, removed, _ := ComputeDiff(new, s.sdCurrent, false)
Expand All @@ -373,7 +373,12 @@ func (s *Server) AddData(new []SendableData) {
curDiff := append(added, removed...)
s.sdlock.RUnlock()

s.AddSDsDiff(curDiff)
if (len(curDiff) == 0) {
return false
} else {
s.AddSDsDiff(curDiff)
return true
}
}

func (s *Server) addSerial(serial uint32) []uint32 {
Expand Down

0 comments on commit 277cd1e

Please sign in to comment.