Skip to content

Commit 057148b

Browse files
committed
Experiment with different GC methods
1 parent c21049b commit 057148b

File tree

2 files changed

+61
-12
lines changed

2 files changed

+61
-12
lines changed

specifications/FiniteMonotonic/MC_ReplicatedLog.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
SPECIFICATION Spec
1+
SPECIFICATION SimpleSpec
22
CONSTANTS
33
Node = {n1, n2, n3}
44
Transaction = {tx1, tx2, tx3}

specifications/FiniteMonotonic/MC_ReplicatedLog.tla

+60-11
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Init ==
2121
/\ converge = FALSE
2222

2323
\* Experiment with combining the write & garbage collect steps
24-
WriteTx(n, tx) ==
24+
GCWriteTx(n, tx) ==
2525
LET SetMin(s) == CHOOSE e \in s : \A o \in s : e <= o IN
2626
LET MinExecuted == SetMin({executed[o] : o \in Node}) IN
2727
LET NewTxId == Len(log) - MinExecuted + 1 IN
@@ -34,31 +34,80 @@ WriteTx(n, tx) ==
3434
]
3535
/\ executed' = [
3636
o \in Node |->
37-
IF o /= n THEN executed[o] - MinExecuted ELSE NewTxId
37+
IF o = n THEN NewTxId ELSE executed[o] - MinExecuted
3838
]
3939
/\ UNCHANGED converge
4040

41-
ExecuteTx(n) ==
41+
\* Experiment with combining the execute & garbage collect steps
42+
GCExecuteTx(n) ==
43+
LET SetMin(s) == CHOOSE e \in s : \A o \in s : e <= o IN
44+
LET MinExecuted == SetMin({
45+
IF o = n THEN executed[o] + 1 ELSE executed[o] : o \in Node
46+
}) IN
47+
/\ log' = [i \in 1 .. Len(log) - MinExecuted |-> log[i + MinExecuted]]
48+
/\ executed' = [
49+
o \in Node |->
50+
IF o = n
51+
THEN executed[o] - MinExecuted + 1
52+
ELSE executed[o] - MinExecuted
53+
]
54+
/\ UNCHANGED converge
55+
56+
SimpleWriteTx(n, tx) ==
57+
/\ ~converge
58+
/\ Len(log) < Divergence
59+
/\ S!WriteTx(n, tx)
60+
/\ UNCHANGED converge
61+
62+
SimpleExecuteTx(n) ==
4263
/\ S!ExecuteTx(n)
4364
/\ UNCHANGED converge
4465

66+
GarbageCollect ==
67+
LET SetMin(s) == CHOOSE e \in s : \A o \in s : e <= o IN
68+
LET MinExecuted == SetMin({executed[o] : o \in Node}) IN
69+
/\ log' = [i \in 1 .. Len(log) - MinExecuted |-> log[i + MinExecuted]]
70+
/\ executed' = [n \in Node |-> executed[n] - MinExecuted]
71+
/\ UNCHANGED converge
72+
4573
Converge ==
4674
/\ converge' = TRUE
4775
/\ UNCHANGED <<log, executed>>
4876

49-
Next ==
50-
\/ \E n \in Node : \E tx \in Transaction : WriteTx(n, tx)
51-
\/ \E n \in Node : ExecuteTx(n)
77+
GCWriteNext ==
78+
\/ \E n \in Node : \E tx \in Transaction : GCWriteTx(n, tx)
79+
\/ \E n \in Node : SimpleExecuteTx(n)
80+
\/ Converge
81+
82+
SimpleFairness == \A n \in Node : WF_vars(SimpleExecuteTx(n))
83+
84+
GCWriteSpec ==
85+
/\ Init
86+
/\ [][GCWriteNext]_vars
87+
/\ SimpleFairness
88+
89+
GCExecuteNext ==
90+
\/ \E n \in Node : \E tx \in Transaction : GCWriteTx(n, tx)
91+
\/ \E n \in Node : SimpleExecuteTx(n)
5292
\/ Converge
5393

54-
Fairness == \A n \in Node : WF_vars(ExecuteTx(n))
94+
GCFairness == \A n \in Node : WF_vars(GCExecuteTx(n))
5595

56-
Test == Len(log) /= Divergence
96+
GCExecuteSpec ==
97+
/\ Init
98+
/\ [][GCExecuteNext]_vars
99+
/\ GCFairness
100+
101+
SimpleNext ==
102+
\/ \E n \in Node : \E tx \in Transaction : SimpleWriteTx(n, tx)
103+
\/ \E n \in Node : SimpleExecuteTx(n)
104+
\/ GarbageCollect
105+
\/ Converge
57106

58-
Spec ==
107+
SimpleSpec ==
59108
/\ Init
60-
/\ [][Next]_vars
61-
/\ Fairness
109+
/\ [][SimpleNext]_vars
110+
/\ SimpleFairness
62111

63112
=============================================================================
64113

0 commit comments

Comments
 (0)