Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate scenario from trace #5875

Merged
merged 25 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
34e079e
draft
achamayou Dec 19, 2023
de279f3
first draft
achamayou Dec 19, 2023
2f6ce65
Merge branch 'generate_scenario_from_trace' of https://github.com/ach…
achamayou Dec 19, 2023
9b9b905
unbreak
achamayou Dec 19, 2023
f782247
Merge branch 'main' into generate_scenario_from_trace
achamayou Dec 19, 2023
d9a0bd3
Merge branch 'main' into generate_scenario_from_trace
achamayou Dec 19, 2023
bffd4fc
Initial state
achamayou Dec 19, 2023
8eeb3e3
driver wants the term
achamayou Dec 19, 2023
0e45b5e
Post commit checks
achamayou Dec 19, 2023
69ae6e3
Merge branch 'main' into generate_scenario_from_trace
achamayou Dec 20, 2023
9359525
fix reconfig mapping
achamayou Dec 20, 2023
2ee5cb2
Merge branch 'generate_scenario_from_trace' of https://github.com/ach…
achamayou Dec 20, 2023
afe0c99
should not have been committed
achamayou Dec 20, 2023
75ae571
Move asserts to end of scenario
achamayou Dec 20, 2023
6605e74
add node id
achamayou Dec 20, 2023
a87f16d
assert node state
achamayou Dec 20, 2023
e0820b2
unbreak
achamayou Dec 20, 2023
46409e0
really
achamayou Dec 20, 2023
dcdb288
Merge branch 'main' into generate_scenario_from_trace
lemmy Dec 21, 2023
00df448
Merge branch 'main' into generate_scenario_from_trace
achamayou Jan 5, 2024
ef3fb4e
Simplify config change, and add missing actions
achamayou Jan 5, 2024
dfa1a07
Merge branch 'main' into generate_scenario_from_trace
achamayou Jan 5, 2024
518ed31
Merge branch 'main' into generate_scenario_from_trace
achamayou Jan 5, 2024
46ff46c
Merge branch 'main' into generate_scenario_from_trace
achamayou Jan 9, 2024
bc518d1
Merge branch 'main' into generate_scenario_from_trace
achamayou Jan 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/consensus/aft/test/driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,7 @@ class RaftDriver

if (_nodes.find(node_id) == _nodes.end())
{
throw std::runtime_error(fmt::format(
"Node {} does not exist yet. Use \"create_new_node, <node_id>\"",
node_id));
create_new_node(node_id_s);
}

configuration.try_emplace(node_id);
Expand Down Expand Up @@ -1053,7 +1051,8 @@ class RaftDriver
idx)
<< std::endl;
throw std::runtime_error(fmt::format(
"Node not at expected commit idx ({}) on line {} : {}",
"Node {} not at expected commit idx ({}) on line {} : {}",
node_id,
idx,
std::to_string((int)lineno),
_nodes.at(node_id).raft->get_committed_seqno()));
Expand Down
73 changes: 73 additions & 0 deletions tla/trace2scen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the Apache 2.0 License.

import sys
import json
import os

def comment(action):
return f"# {action['name']} {action['location']['module']}:{action['location']['beginLine']}"

def term(ctx, pre):
return str(pre["currentTerm"][ctx['i']])

def noop(ctx, pre, post):
return ["# Noop"]

MAP = {
"ClientRequest": lambda ctx, pre, post: ["replicate", term(ctx, pre), "42"],
achamayou marked this conversation as resolved.
Show resolved Hide resolved
"MCClientRequest": lambda ctx, pre, post: ["replicate", term(ctx, pre), "42"],
"CheckQuorum": lambda ctx, pre, post: ["periodic_one", ctx['i'], "110"],
"Timeout": lambda ctx, pre, post: ["periodic_one", ctx['i'], "110"],
"MCTimeout": lambda ctx, pre, post: ["periodic_one", ctx['i'], "110"],
"RequestVote": noop,
"AppendEntries": lambda _, __, ___: ["dispatch_all"],
"BecomeLeader": noop,
"SignCommittableMessages": lambda ctx, pre, post: ["emit_signature", term(ctx, pre)],
"MCSignCommittableMessages": lambda ctx, pre, post: ["emit_signature", term(ctx, pre)],
"ChangeConfigurationInt": lambda ctx, pre, post: ["replicate_new_configuration", term(ctx, pre), *ctx["newConfiguration"]],
"AdvanceCommitIndex": noop,
achamayou marked this conversation as resolved.
Show resolved Hide resolved
"HandleRequestVoteRequest": lambda _, __, ___: ["dispatch_all"],
"HandleRequestVoteResponse": noop,
"RejectAppendEntriesRequest": noop,
"ReturnToFollowerState": noop,
"AppendEntriesAlreadyDone": noop,
"RcvDropIgnoredMessage": noop,
"RcvUpdateTerm": noop,
"RcvRequestVoteRequest": noop,
"RcvRequestVoteResponse": noop,
}

def post_commit(post):
return [["assert_commit_idx", node, str(idx)] for node, idx in post["commitIndex"].items()]

def post_state(post):
entries = []
for node, state in post["state"].items():
if state == "Leader":
entries.append(["assert_is_primary", node])
elif state == "Follower":
entries.append(["assert_is_backup", node])
elif state == "Candidate":
entries.append(["assert_is_candidate", node])
return entries

def step_to_action(pre_state, action, post_state):
return os.linesep.join([
comment(action),
','.join(MAP[action['name']](action['context'], pre_state[1], post_state[1]))])

def asserts(pre_state, action, post_state, assert_gen):
return os.linesep.join([','.join(assertion) for assertion in assert_gen(post_state[1])])

if __name__ == "__main__":
with open(sys.argv[1]) as trace:
steps = json.load(trace)["action"]
initial_state = steps[0][0][1]
initial_node, = [node for node, log in initial_state["log"].items() if log]
print(f"start_node,{initial_node}")
print(f"emit_signature,2")
for step in steps:
print(step_to_action(*step))
print(asserts(*step, post_state))
print(asserts(*steps[-1], post_commit))