heckj / CRDT

Conflict-free Replicated Data Types in Swift
https://swiftpackageindex.com/heckj/CRDT/main/documentation/crdt
MIT License
154 stars 3 forks source link

ORSet and GSet need more replication verification tests #13

Closed heckj closed 2 years ago

heckj commented 2 years ago

While looking at sizing numbers, I ran across the following delta's and numbers (GSet and ORSet):

let orset_1 = ORSet(actorId: UInt(31), [1, 2, 3, 4])
let orset_2 = ORSet(actorId: UInt(31), [4, 5])

print("ORSet1(4 elements, UInt actorId) = \(orset_1.sizeInBytes())")
print("ORSet2(2 elements, UInt actorId) = \(orset_2.sizeInBytes())")
print("ORSet1's state size: \(orset_1.state.sizeInBytes())")
print("ORSet2's state size: \(orset_1.state.sizeInBytes())")
print("Delta size of Set1 merging into Set2: \(orset_2.delta(orset_1.state).sizeInBytes())")
print("Delta size of Set2 merging into Set1: \(orset_1.delta(orset_2.state).sizeInBytes())")

Delta Numbers for GSet:

GSet1(4 elements, UInt actorId) = 64
GSet2(2 elements, UInt actorId) = 40
GSet1's state size: 48
GSet2's state size: 48
Delta size of Set1 merging into Set2: 24
Delta size of Set2 merging into Set1: 40

Delta Numbers for ORSet:

ORSet1(4 elements, UInt actorId) = 116
ORSet2(2 elements, UInt actorId) = 66
ORSet1's state size: 16
ORSet2's state size: 16
Delta size of Set1 merging into Set2: 0
Delta size of Set2 merging into Set1: 50

The 0 in set1 merging into set2 is a notable issue - means something in the delta/state computation logic is screwed up. ORSet has fairly complicated state, delta, and diffing logic - so best to work the corners there and verify its all operating as expected.