mirror of
https://github.com/tim-beatham/smegmesh.git
synced 2025-06-20 19:57:49 +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
|
// HasChanges returns true if we have changes since last time we synced
|
||||||
func (m *TwoPhaseStoreMeshManager) HasChanges() bool {
|
func (m *TwoPhaseStoreMeshManager) HasChanges() bool {
|
||||||
clockValue := m.store.GetClock()
|
clockValue := m.store.GetHash()
|
||||||
return clockValue != m.LastClock
|
return clockValue != m.LastClock
|
||||||
}
|
}
|
||||||
|
|
||||||
// Record that we have changes and save the corresponding changes
|
// Record that we have changes and save the corresponding changes
|
||||||
func (m *TwoPhaseStoreMeshManager) SaveChanges() {
|
func (m *TwoPhaseStoreMeshManager) SaveChanges() {
|
||||||
clockValue := m.store.GetClock()
|
clockValue := m.store.GetHash()
|
||||||
m.LastClock = clockValue
|
m.LastClock = clockValue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,16 +128,19 @@ func (m *TwoPhaseMap[K, D]) incrementClock() uint64 {
|
|||||||
return maxClock
|
return maxClock
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *TwoPhaseMap[K, D]) GetClock() uint64 {
|
// GetHash: Get the hash of the current state of the map
|
||||||
maxClock := uint64(0)
|
// Sums the current values of the vectors. Provides good approximation
|
||||||
|
// of increasing numbers
|
||||||
|
func (m *TwoPhaseMap[K, D]) GetHash() uint64 {
|
||||||
m.lock.RLock()
|
m.lock.RLock()
|
||||||
|
|
||||||
for _, value := range m.vectors {
|
sum := lib.Reduce(uint64(0), lib.MapValues(m.vectors), func(sum uint64, current uint64) uint64 {
|
||||||
maxClock = max(maxClock, value)
|
return current + sum
|
||||||
}
|
})
|
||||||
|
|
||||||
m.lock.RUnlock()
|
m.lock.RUnlock()
|
||||||
return maxClock
|
|
||||||
|
return sum
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetState: get the current vector clock of the add and remove
|
// 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() {
|
func (t *TwoPhaseSyncer) Complete() {
|
||||||
logging.Log.WriteInfof("SYNC COMPLETED")
|
logging.Log.WriteInfof("SYNC COMPLETED")
|
||||||
t.manager.SaveChanges()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTwoPhaseSyncer(manager *TwoPhaseStoreMeshManager) *TwoPhaseSyncer {
|
func NewTwoPhaseSyncer(manager *TwoPhaseStoreMeshManager) *TwoPhaseSyncer {
|
||||||
|
@ -76,3 +76,13 @@ func Contains[V any](list []V, proposition func(V) bool) bool {
|
|||||||
|
|
||||||
return false
|
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)
|
logging.Log.WriteInfof("SYNC COUNT: %d", s.syncCount)
|
||||||
|
|
||||||
s.infectionCount = ((s.conf.InfectionCount + s.infectionCount - 1) % s.conf.InfectionCount)
|
s.infectionCount = ((s.conf.InfectionCount + s.infectionCount - 1) % s.conf.InfectionCount)
|
||||||
|
s.manager.GetMesh(meshId).SaveChanges()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user