diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index d218914..b0cd037 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -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`) diff --git a/pkg/svs/onestate_core.go b/pkg/svs/onestate_core.go index a0a5ff9..cf50b0d 100644 --- a/pkg/svs/onestate_core.go +++ b/pkg/svs/onestate_core.go @@ -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() } diff --git a/pkg/svs/state_vector.go b/pkg/svs/state_vector.go index 0d5b973..7cb5318 100644 --- a/pkg/svs/state_vector.go +++ b/pkg/svs/state_vector.go @@ -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}) } @@ -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 } diff --git a/pkg/svs/twostate_core.go b/pkg/svs/twostate_core.go index 08494d1..08b6a7d 100644 --- a/pkg/svs/twostate_core.go +++ b/pkg/svs/twostate_core.go @@ -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() } @@ -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 @@ -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()