mirror of
https://github.com/tim-beatham/smegmesh.git
synced 2025-06-20 11:47:45 +02:00
BUGFIX: Hashing datastore to work out changes
Changed hashing implementation to work out if there are changes in the data store
This commit is contained in:
parent
b9ba836ae3
commit
3ef1b68ba5
@ -222,13 +222,13 @@ func (m *TwoPhaseStoreMeshManager) GetDevice() (*wgtypes.Device, error) {
|
||||
|
||||
// HasChanges returns true if we have changes since last time we synced
|
||||
func (m *TwoPhaseStoreMeshManager) HasChanges() bool {
|
||||
clockValue := m.store.GetClock()
|
||||
clockValue := m.store.GetHash()
|
||||
return clockValue != m.LastClock
|
||||
}
|
||||
|
||||
// Record that we have changes and save the corresponding changes
|
||||
func (m *TwoPhaseStoreMeshManager) SaveChanges() {
|
||||
clockValue := m.store.GetClock()
|
||||
clockValue := m.store.GetHash()
|
||||
m.LastClock = clockValue
|
||||
}
|
||||
|
||||
|
@ -128,16 +128,19 @@ func (m *TwoPhaseMap[K, D]) incrementClock() uint64 {
|
||||
return maxClock
|
||||
}
|
||||
|
||||
func (m *TwoPhaseMap[K, D]) GetClock() uint64 {
|
||||
maxClock := uint64(0)
|
||||
// GetHash: Get the hash of the current state of the map
|
||||
// Sums the current values of the vectors. Provides good approximation
|
||||
// of increasing numbers
|
||||
func (m *TwoPhaseMap[K, D]) GetHash() uint64 {
|
||||
m.lock.RLock()
|
||||
|
||||
for _, value := range m.vectors {
|
||||
maxClock = max(maxClock, value)
|
||||
}
|
||||
sum := lib.Reduce(uint64(0), lib.MapValues(m.vectors), func(sum uint64, current uint64) uint64 {
|
||||
return current + sum
|
||||
})
|
||||
|
||||
m.lock.RUnlock()
|
||||
return maxClock
|
||||
|
||||
return sum
|
||||
}
|
||||
|
||||
// GetState: get the current vector clock of the add and remove
|
||||
|
@ -125,7 +125,6 @@ func (t *TwoPhaseSyncer) RecvMessage(msg []byte) error {
|
||||
|
||||
func (t *TwoPhaseSyncer) Complete() {
|
||||
logging.Log.WriteInfof("SYNC COMPLETED")
|
||||
t.manager.SaveChanges()
|
||||
}
|
||||
|
||||
func NewTwoPhaseSyncer(manager *TwoPhaseStoreMeshManager) *TwoPhaseSyncer {
|
||||
|
@ -76,3 +76,13 @@ func Contains[V any](list []V, proposition func(V) bool) bool {
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func Reduce[A any, V any](start A, values []V, reduce func(A, V) A) A {
|
||||
accum := start
|
||||
|
||||
for _, elem := range values {
|
||||
accum = reduce(accum, elem)
|
||||
}
|
||||
|
||||
return accum
|
||||
}
|
||||
|
@ -89,6 +89,7 @@ func (s *SyncerImpl) Sync(meshId string) error {
|
||||
logging.Log.WriteInfof("SYNC COUNT: %d", s.syncCount)
|
||||
|
||||
s.infectionCount = ((s.conf.InfectionCount + s.infectionCount - 1) % s.conf.InfectionCount)
|
||||
s.manager.GetMesh(meshId).SaveChanges()
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user