Skip to content

Commit

Permalink
Merge pull request #117 from cjeker/avoid_empty_deltas
Browse files Browse the repository at this point in the history
Avoid adding empty deltas to the cache
  • Loading branch information
ties authored Mar 1, 2024
2 parents c3652d3 + a1c36d6 commit b93d7a8
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 @@ -454,10 +454,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) {
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 b93d7a8

Please sign in to comment.