-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pre-processing for realistic scenarios (#5825)
- Loading branch information
Showing
19 changed files
with
46 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,12 @@ | |
import argparse | ||
import sys | ||
import os | ||
import json | ||
from subprocess import Popen, PIPE | ||
from raft_scenarios_gen import generate_scenarios | ||
from contextlib import contextmanager | ||
from collections import defaultdict | ||
from heapq import merge | ||
|
||
|
||
@contextmanager | ||
|
@@ -33,15 +36,40 @@ def write_error_report(errors=None): | |
print("??? success \n") | ||
|
||
|
||
def separate_log_lines(text): | ||
def remove_reconfiguration_replicates(log): | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
achamayou
Author
Member
|
||
log_by_node = defaultdict(list) | ||
for line in log: | ||
entry = json.loads(line) | ||
node = entry["msg"]["state"]["node_id"] | ||
if entry["msg"]["function"] == "add_configuration": | ||
removed = log_by_node[node].pop() | ||
assert removed["msg"]["function"] in ( | ||
"replicate", | ||
"execute_append_entries_sync", | ||
), removed | ||
log_by_node[node].append(entry) | ||
return [ | ||
json.dumps(e) | ||
for e in merge(*log_by_node.values(), key=lambda e: int(e["h_ts"])) | ||
] | ||
|
||
|
||
def noop(log): | ||
return log | ||
|
||
|
||
def separate_log_lines(text, preprocess): | ||
mermaid = [] | ||
log = [] | ||
for line in text.split(os.linesep): | ||
if line.startswith("<RaftDriver>"): | ||
mermaid.append(line[len("<RaftDriver>") :]) | ||
elif '"raft_trace"' in line: | ||
log.append(line) | ||
return (os.linesep.join(mermaid) + os.linesep, os.linesep.join(log) + os.linesep) | ||
return ( | ||
os.linesep.join(mermaid) + os.linesep, | ||
os.linesep.join(preprocess(log)) + os.linesep, | ||
) | ||
|
||
|
||
def expand_files(files): | ||
|
@@ -94,7 +122,10 @@ def expand_files(files): | |
with block(ostream, "stderr", 3): | ||
ostream.write(err.decode()) | ||
|
||
mermaid, log = separate_log_lines(out.decode()) | ||
mermaid, log = separate_log_lines( | ||
out.decode(), | ||
noop if "deprecated" in scenario else remove_reconfiguration_replicates, | ||
) | ||
|
||
with block(ostream, "diagram", 3, "mermaid", ["sequenceDiagram"]): | ||
ostream.write(mermaid) | ||
|
Removing superfluous
replicate
andexecute_append_entries_sync
could be left to non-determinism with: