Skip to content

Commit 1e711a3

Browse files
committed
Remove untick in exchange for increments larger than one
Remove untick from vector clock at the risk of having increments larger than one for the local vector clock in edge cases where persistence of snapshot may fail in the midst of a cycle. This is an acceptable risk considering the difficulty in implementing transactional IPLD node storage and the application of it in this particular case.
1 parent 3972590 commit 1e711a3

File tree

3 files changed

+1
-16
lines changed

3 files changed

+1
-16
lines changed

federation/federation.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,10 @@ func (f *Federation) snapshot(ctx context.Context, t time.Time) error {
144144
node := bindnode.Wrap(newSnapshot, Prototypes.Snapshot.Type()).Representation()
145145
headSnapshotLink, err := f.linkSystem.Store(ipld.LinkContext{Ctx: ctx}, Prototypes.link, node)
146146
if err != nil {
147-
f.vc.untick(f.host.ID())
148147
return err
149148
}
150149
if err := f.setHeadLink(ctx, headSnapshotLink); err != nil {
151-
f.vc.untick(f.host.ID())
150+
return err
152151
}
153152
return nil
154153
}

federation/vector_clock.go

-9
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,6 @@ func (vc vectorClock) tick(id peer.ID) uint64 {
2121

2222
}
2323

24-
// untick decrements the vector clock for the given peer ID.
25-
// This function is primarily used for error recovery, where incrementing the clock may need to happen first before
26-
// some state is stored and the state storage itself may fail.
27-
// As an example, see Federation.snapshot.
28-
func (vc vectorClock) untick(id peer.ID) uint64 {
29-
vc[id] = vc[id] - 1
30-
return vc[id]
31-
}
32-
3324
func (vc vectorClock) reconcile(id peer.ID, c uint64) bool {
3425
if vc[id] < c {
3526
vc[id] = c

federation/vector_clock_test.go

-5
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ func TestVectorClock(t *testing.T) {
2424
require.False(t, found)
2525
require.Equal(t, uint64(0), clock)
2626

27-
subject.untick("one")
28-
clock, found = subject.clock("one")
29-
require.True(t, found)
30-
require.Equal(t, uint64(0), clock)
31-
3227
subject.reconcile("another", 1413)
3328
clock, found = subject.clock("another")
3429
require.True(t, found)

0 commit comments

Comments
 (0)