mirror of
https://github.com/tim-beatham/smegmesh.git
synced 2025-08-18 08:59:45 +02:00
45-use-statistical-testing
Keepalive is based on per mesh and not per node. Using total ordering mechanism similar to paxos to elect a leader if leader doesn't update it's timestamp within 3 * keepAlive then give the leader a gravestone and elect the next leader. Leader is bassed on lexicographically ordered public key.
This commit is contained in:
@@ -2,9 +2,8 @@
|
||||
package crdt
|
||||
|
||||
import (
|
||||
"cmp"
|
||||
"sync"
|
||||
|
||||
"github.com/tim-beatham/wgmesh/pkg/lib"
|
||||
)
|
||||
|
||||
type Bucket[D any] struct {
|
||||
@@ -14,7 +13,7 @@ type Bucket[D any] struct {
|
||||
}
|
||||
|
||||
// GMap is a set that can only grow in size
|
||||
type GMap[K comparable, D any] struct {
|
||||
type GMap[K cmp.Ordered, D any] struct {
|
||||
lock sync.RWMutex
|
||||
contents map[K]Bucket[D]
|
||||
clock *VectorClock[K]
|
||||
@@ -155,18 +154,17 @@ func (g *GMap[K, D]) GetHash() uint64 {
|
||||
}
|
||||
|
||||
func (g *GMap[K, D]) Prune() {
|
||||
outliers := lib.GetOutliers(g.clock.GetClock(), 0.05)
|
||||
|
||||
stale := g.clock.getStale()
|
||||
g.lock.Lock()
|
||||
|
||||
for _, outlier := range outliers {
|
||||
for _, outlier := range stale {
|
||||
delete(g.contents, outlier)
|
||||
}
|
||||
|
||||
g.lock.Unlock()
|
||||
}
|
||||
|
||||
func NewGMap[K comparable, D any](clock *VectorClock[K]) *GMap[K, D] {
|
||||
func NewGMap[K cmp.Ordered, D any](clock *VectorClock[K]) *GMap[K, D] {
|
||||
return &GMap[K, D]{
|
||||
contents: make(map[K]Bucket[D]),
|
||||
clock: clock,
|
||||
|
Reference in New Issue
Block a user