Skip to content

Commit

Permalink
seperate entry times from values
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin C Presley committed Feb 28, 2024
1 parent 202fc86 commit be94eb5
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
## [Unreleased]
## Added
- `RWMutex` is embedded into `StateVector`.
- `Update()` for `StateVector` that functions the same as `Set()` but updates the time for that entry. `LastUpdated()` pulls the time for a certain entry.
- `Update()` for `StateVector` that updates the time for an entry. `LastUpdated()` pulls the time for a certain entry.

## Changed
- `Scheduler` operates entirely with `time.Duration` instead of `int64` internally. This removes many type conversions and makes it more readable. (made possible with `math/rand/v2`)
Expand Down
3 changes: 2 additions & 1 deletion pkg/svs/onestate_core.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ func (c *oneStateCore) Update(dsname enc.Name, seqno uint64) {
}
}
c.local.Lock()
c.local.Update(dsstr, dsname, seqno, false)
c.local.Set(dsstr, dsname, seqno, false)
c.local.Update(dsstr)
c.local.Unlock()
c.scheduler.Skip()
}
Expand Down
6 changes: 1 addition & 5 deletions pkg/svs/state_vector.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ func ParseStateVector(reader enc.ParseReader, formal bool) (*StateVector, error)
}
}

func (sv *StateVector) Update(dsstr string, dsname enc.Name, seqno uint64, old bool) {
sv.entries.Set(dsstr, dsname, seqno, nm.MetaV{Old: old})
sv.times[dsstr] = time.Now()
}

func (sv *StateVector) Set(dsstr string, dsname enc.Name, seqno uint64, old bool) {
sv.entries.Set(dsstr, dsname, seqno, nm.MetaV{Old: old})
}
Expand Down Expand Up @@ -70,6 +65,7 @@ func (sv *StateVector) Sum() uint64 {
return ret
}

func (sv *StateVector) Update(dsstr string) { sv.times[dsstr] = time.Now() }
func (sv *StateVector) LastUpdated(dsstr string) time.Time { return sv.times[dsstr] }
func (sv *StateVector) Len() int { return sv.entries.Len() }
func (sv *StateVector) Entries() *nm.NameMap[uint64] { return sv.entries }
Expand Down
9 changes: 6 additions & 3 deletions pkg/svs/twostate_core.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ func (c *twoStateCore) Update(dsname enc.Name, seqno uint64) {
}
}
c.local.Lock()
c.local.Update(dsstr, dsname, seqno, false)
c.local.Set(dsstr, dsname, seqno, false)
c.local.Update(dsstr)
c.local.Unlock()
c.scheduler.Skip()
}
Expand Down Expand Up @@ -205,7 +206,8 @@ func (c *twoStateCore) mergeVectorToLocal(vector *StateVector) bool {
lVal = c.local.Get(p.Kstr)
if lVal < p.Val {
missing = append(missing, MissingData{Dataset: p.Kname, StartSeq: lVal + 1, EndSeq: p.Val})
c.local.Update(p.Kstr, p.Kname, p.Val, false)
c.local.Set(p.Kstr, p.Kname, p.Val, false)
c.local.Update(p.Kstr)
} else if lVal > p.Val {
if (c.effSuppress || slices.Contains(c.selfsets, p.Kstr)) && time.Since(c.local.LastUpdated(p.Kstr)) < c.constants.SuppressionInterval {
continue
Expand Down Expand Up @@ -235,7 +237,8 @@ func (c *twoStateCore) recordVector(vector *StateVector) {
}
if c.local.Get(p.Kstr) < p.Val {
missing = append(missing, MissingData{Dataset: p.Kname, StartSeq: c.local.Get(p.Kstr) + 1, EndSeq: p.Val})
c.local.Update(p.Kstr, p.Kname, p.Val, false)
c.local.Set(p.Kstr, p.Kname, p.Val, false)
c.local.Update(p.Kstr)
}
}
c.record.Unlock()
Expand Down

0 comments on commit be94eb5

Please sign in to comment.