Skip to content

Commit 999ce8f

Browse files
lemmyachamayou
andauthored
Adjust the probabilities based on empirical data to achieve less uneven coverage of the action space during simulation (#6562)
Signed-off-by: Markus Alexander Kuppe <[email protected]> Co-authored-by: Amaury Chamayou <[email protected]>
1 parent dae8c25 commit 999ce8f

File tree

5 files changed

+69
-131
lines changed

5 files changed

+69
-131
lines changed

tla/consensus/SIMCoverageccfraft.R

Lines changed: 0 additions & 18 deletions
This file was deleted.

tla/consensus/SIMCoverageccfraft.cfg

Lines changed: 0 additions & 49 deletions
This file was deleted.

tla/consensus/SIMCoverageccfraft.tla

Lines changed: 31 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,40 @@
1-
---------- MODULE SIMCoverageccfraft ----------
2-
EXTENDS ccfraft, TLC, Integers, CSV, TLCExt
31

4-
CONSTANTS
5-
NodeOne, NodeTwo, NodeThree, NodeFour, NodeFive
2+
$ wget https://nightly.tlapl.us/dist/tla2tools.jar
3+
$ wget https://github.com/tlaplus/CommunityModules/releases/latest/download/CommunityModules-deps.jar
4+
## Run with as many workers as you like to parallelize the nested simulation runs (auto uses all your cores).
5+
$ java -jar tla2tools.jar -config SIMCoverageccfraft.tla SIMCoverageccfraft.tla -workers auto
66

7-
Servers_mc == {NodeOne, NodeTwo, NodeThree, NodeFour, NodeFive}
7+
----------------------------- MODULE SIMCoverageccfraft -----------------------------
8+
EXTENDS TLC, Naturals, Sequences, IOUtils
89

9-
Baseline ==
10-
{<<"Next", 0..0, 0..0, 0..0>>}
10+
CmdLine ==
11+
<<"sh", "-c",
12+
"java " \o
13+
"-XX:+UseParallelGC " \o
14+
"-Dtlc2.tool.impl.Tool.cdot=true " \o
15+
"-Dtlc2.tool.Simulator.extendedStatistics=true " \o
16+
"-jar tla2tools.jar " \o
17+
"-depth 1000 " \o
18+
"-simulate SIMccfraft.tla >> SIMCoverageccfraft.txt 2>&1">>
1119

12-
Confs ==
13-
Baseline \cup
14-
({"SIMNext"} \X {1..1, 1..10, 1..100} \X {201..201, 201..210, 201..300} \X {401..401, 401..410, 401..500})
20+
-----------------------------------------------------------------------------
1521

16-
VARIABLE conf
22+
VARIABLE c, d
1723

18-
CCF == INSTANCE ccfraft
24+
Init ==
25+
/\ c \in [ R: {10, 1000}, C: {10, 1000}, Q: {10, 1000}, T: {10, 1000} ]
26+
/\ d = FALSE
1927

20-
SIMInitReconfigurationVars ==
21-
\/ CCF!InitLogConfigServerVars(Servers, JoinedLog)
22-
\/ CCF!InitReconfigurationVars
28+
Next ==
29+
/\ ~d
30+
/\ d' = TRUE
31+
/\ PrintT(<<"conf", c>>)
32+
/\ IOEnvExec(c, CmdLine).exitValue = 0
33+
/\ UNCHANGED c
2334

24-
SIMCheckQuorum(i) ==
25-
/\ conf[1] # "Next" => RandomElement(1..1000) \in conf[3]
26-
/\ CCF!CheckQuorum(i)
27-
28-
SIMChangeConfigurationInt(i, newConfiguration) ==
29-
/\ conf[1] # "Next" => RandomElement(1..1000) \in conf[4]
30-
/\ CCF!ChangeConfigurationInt(i, newConfiguration)
31-
32-
SIMTimeout(i) ==
33-
/\ \/ RandomElement(1..1000) \in conf[2]
34-
\/ conf[1] # "Next"
35-
\* Always allow Timeout if no messages are in the network
36-
\* and no node is a candidate or leader. Otherwise, the system
37-
\* will deadlock if 1 # RandomElement(...).
38-
\/ /\ \A s \in Servers: leadershipState[s] \notin {Leader, Candidate}
39-
/\ Network!Messages = {}
40-
/\ CCF!Timeout(i)
41-
42-
SIMCoverageSpec ==
43-
/\ Init
44-
/\ conf \in Confs
45-
/\ [][UNCHANGED conf /\ Next]_<<vars, conf>>
46-
47-
------------------------------------------------------------------------------
48-
49-
CSVFile == "SIMCoverageccfraft_S" \o ToString(Cardinality(Servers)) \o ".csv"
50-
51-
CSVColumnHeaders ==
52-
"Spec#P#Q#R#currentTerm#state#commitIndex#log#node"
53-
54-
ASSUME
55-
CSVRecords(CSVFile) = 0 =>
56-
CSVWrite(CSVColumnHeaders, <<>>, CSVFile)
57-
58-
StatisticsStateConstraint ==
59-
(TLCGet("level") > TLCGet("config").depth) =>
60-
TLCDefer(\A s \in Servers : CSVWrite("%1$s#%2$s#%3$s#%4$s#%5$s#%6$s#%7$s#%8$s#%9$s",
61-
<< conf[1], Cardinality(conf[2]), Cardinality(conf[3]), Cardinality(conf[4]),
62-
currentTerm[s], leadershipState[s], commitIndex[s], Len(log[s]), s
63-
>>,
64-
CSVFile))
6535
=============================================================================
36+
---- CONFIG SIMCoverageccfraft ----
37+
INIT Init
38+
NEXT Next
39+
CHECK_DEADLOCK FALSE
40+
====

tla/consensus/SIMccfraft.cfg

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ CONSTANTS
4242
Timeout <- SIMTimeout
4343
ChangeConfigurationInt <-SIMChangeConfigurationInt
4444
CheckQuorum <- SIMCheckQuorum
45+
ClientRequest <- SIMClientRequest
4546

4647
Fairness <- SIMFairness
4748

@@ -50,8 +51,8 @@ CONSTANTS
5051
Extend <- [abs]ABSExtend
5152
CopyMaxAndExtend <- [abs]ABSCopyMaxAndExtend
5253

53-
CONSTRAINT
54-
StopAfter
54+
_PERIODIC
55+
Periodically
5556

5657
CHECK_DEADLOCK
5758
FALSE

tla/consensus/SIMccfraft.tla

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---------- MODULE SIMccfraft ----------
2-
EXTENDS ccfraft, TLC, Integers, IOUtils, MCAliases
2+
EXTENDS ccfraft, TLC, Integers, IOUtils
33

44
CONSTANTS
55
NodeOne, NodeTwo, NodeThree, NodeFour, NodeFive
@@ -16,16 +16,32 @@ SIMInitReconfigurationVars ==
1616
\* Start with any subset of servers in the active configuration.
1717
\/ CCF!InitReconfigurationVars
1818

19+
LOCAL R ==
20+
1..IF "R" \in DOMAIN IOEnv THEN atoi(IOEnv.R) ELSE 10
21+
22+
SIMClientRequest(i) ==
23+
/\ 1 = RandomElement(R)
24+
/\ CCF!ClientRequest(i)
25+
26+
LOCAL Q ==
27+
1..IF "Q" \in DOMAIN IOEnv THEN atoi(IOEnv.Q) ELSE 10
28+
1929
SIMCheckQuorum(i) ==
20-
/\ 1 = RandomElement(1..10)
30+
/\ 1 = RandomElement(Q)
2131
/\ CCF!CheckQuorum(i)
2232

33+
LOCAL C ==
34+
1..IF "C" \in DOMAIN IOEnv THEN atoi(IOEnv.C) ELSE 10
35+
2336
SIMChangeConfigurationInt(i, newConfiguration) ==
24-
/\ 1 = RandomElement(1..100)
37+
/\ 1 = RandomElement(C)
2538
/\ CCF!ChangeConfigurationInt(i, newConfiguration)
2639

40+
LOCAL T ==
41+
1..IF "T" \in DOMAIN IOEnv THEN atoi(IOEnv.T) ELSE 1000
42+
2743
SIMTimeout(i) ==
28-
/\ \/ 1 = RandomElement(1..100)
44+
/\ \/ 1 = RandomElement(T)
2945
\* Always allow Timeout if no messages are in the network
3046
\* and no node is a candidate or leader. Otherwise, the system
3147
\* will deadlock if 1 # RandomElement(...).
@@ -58,13 +74,26 @@ SIMFairness ==
5874
\E newConfiguration \in SUBSET(Servers) \ {{}}:
5975
WF_vars(CCF!ChangeConfigurationInt(s, newConfiguration))
6076

61-
\* The state constraint StopAfter stops TLC after the alloted
77+
----
78+
79+
\* StopAfter stops TLC after the alloted
6280
\* time budget is up, unless TLC encounters an error first.
6381
StopAfter ==
6482
LET timeout == IF ("SIM_TIMEOUT" \in DOMAIN IOEnv) /\ IOEnv.SIM_TIMEOUT # "" THEN atoi(IOEnv.SIM_TIMEOUT) ELSE 1200
65-
(* The smoke test has a time budget of 20 minutes. *)
6683
IN TLCSet("exit", TLCGet("duration") > timeout)
6784

85+
SerializeFilename ==
86+
"SIMccfraft_" \o "R-" \o ToString(R) \o "_T-" \o ToString(T) \o "_Q-" \o ToString(Q) \o "_C-" \o ToString(C) \o "_ts-" \o ToString(JavaTime) \o ".ndjson"
87+
88+
SerializeTLCStats ==
89+
Serialize(<<TLCGet("stats")>>, SerializeFilename, [format |-> "NDJSON", charset |-> "UTF-8", openOptions |-> <<"WRITE", "CREATE", "APPEND">>])
90+
91+
Periodically ==
92+
/\ StopAfter
93+
/\ SerializeTLCStats
94+
95+
----
96+
6897
DebugInvUpToDepth ==
6998
\* The following invariant causes TLC to terminate with a counterexample of length
7099
\* -depth after generating the first trace.

0 commit comments

Comments
 (0)