From 4cc5852e954e714cb0fead0a7ea401462bd621b9 Mon Sep 17 00:00:00 2001 From: Amaury Chamayou Date: Thu, 9 Nov 2023 15:04:10 +0000 Subject: [PATCH] Add pre-processing for realistic scenarios --- .../trace_validation.yml | 24 ++++++------ .../{4582.2 => 4582.2_deprecated} | 0 .../raft_scenarios/{4806 => 4806_deprecated} | 0 .../{bad_network => bad_network_deprecated} | 0 .../{check_quorum => check_quorum_deprecated} | 0 .../{election => election_deprecated} | 0 ...election_while_reconfiguration_deprecated} | 0 ...election.1 => fancy_election.1_deprecated} | 0 ...election.2 => fancy_election.2_deprecated} | 0 ...lti_election => multi_election_deprecated} | 0 ...nfiguration => reconfiguration_deprecated} | 0 .../{reconnect => reconnect_deprecated} | 0 ...connect_node => reconnect_node_deprecated} | 0 .../{replicate => replicate_deprecated} | 0 ...soft_rollback => soft_rollback_deprecated} | 0 ...lision.1 => suffix_collision.1_deprecated} | 0 ...lision.2 => suffix_collision.2_deprecated} | 0 ...lision.3 => suffix_collision.3_deprecated} | 0 tests/raft_scenarios_runner.py | 37 +++++++++++++++++-- 19 files changed, 46 insertions(+), 15 deletions(-) rename tests/raft_scenarios/{4582.2 => 4582.2_deprecated} (100%) rename tests/raft_scenarios/{4806 => 4806_deprecated} (100%) rename tests/raft_scenarios/{bad_network => bad_network_deprecated} (100%) rename tests/raft_scenarios/{check_quorum => check_quorum_deprecated} (100%) rename tests/raft_scenarios/{election => election_deprecated} (100%) rename tests/raft_scenarios/{election_while_reconfiguration => election_while_reconfiguration_deprecated} (100%) rename tests/raft_scenarios/{fancy_election.1 => fancy_election.1_deprecated} (100%) rename tests/raft_scenarios/{fancy_election.2 => fancy_election.2_deprecated} (100%) rename tests/raft_scenarios/{multi_election => multi_election_deprecated} (100%) rename tests/raft_scenarios/{reconfiguration => reconfiguration_deprecated} (100%) rename tests/raft_scenarios/{reconnect => reconnect_deprecated} (100%) rename tests/raft_scenarios/{reconnect_node => reconnect_node_deprecated} (100%) rename tests/raft_scenarios/{replicate => replicate_deprecated} (100%) rename tests/raft_scenarios/{soft_rollback => soft_rollback_deprecated} (100%) rename tests/raft_scenarios/{suffix_collision.1 => suffix_collision.1_deprecated} (100%) rename tests/raft_scenarios/{suffix_collision.2 => suffix_collision.2_deprecated} (100%) rename tests/raft_scenarios/{suffix_collision.3 => suffix_collision.3_deprecated} (100%) diff --git a/.azure-pipelines-templates/trace_validation.yml b/.azure-pipelines-templates/trace_validation.yml index 09d0a4b58627..1e7a9ad9a1f6 100644 --- a/.azure-pipelines-templates/trace_validation.yml +++ b/.azure-pipelines-templates/trace_validation.yml @@ -10,16 +10,16 @@ steps: set -ex cd tla/ parallel 'JSON={} ./tlc.sh consensus/Traceccfraft.tla' ::: \ - ../build/replicate.ndjson \ - ../build/election.ndjson \ - ../build/multi_election.ndjson \ - ../build/check_quorum.ndjson \ - ../build/reconnect.ndjson \ - ../build/reconnect_node.ndjson \ - ../build/bad_network.ndjson \ - ../build/fancy_election.1.ndjson \ - ../build/fancy_election.2.ndjson \ - ../build/suffix_collision.1.ndjson \ - ../build/suffix_collision.2.ndjson \ - ../build/suffix_collision.3.ndjson + ../build/replicate_deprecated.ndjson \ + ../build/election_deprecated.ndjson \ + ../build/multi_election_deprecated.ndjson \ + ../build/check_quorum_deprecated.ndjson \ + ../build/reconnect_deprecated.ndjson \ + ../build/reconnect_node_deprecated.ndjson \ + ../build/bad_network_deprecated.ndjson \ + ../build/fancy_election.1_deprecated.ndjson \ + ../build/fancy_election.2_deprecated.ndjson \ + ../build/suffix_collision.1_deprecated.ndjson \ + ../build/suffix_collision.2_deprecated.ndjson \ + ../build/suffix_collision.3_deprecated.ndjson displayName: "Run trace validation" diff --git a/tests/raft_scenarios/4582.2 b/tests/raft_scenarios/4582.2_deprecated similarity index 100% rename from tests/raft_scenarios/4582.2 rename to tests/raft_scenarios/4582.2_deprecated diff --git a/tests/raft_scenarios/4806 b/tests/raft_scenarios/4806_deprecated similarity index 100% rename from tests/raft_scenarios/4806 rename to tests/raft_scenarios/4806_deprecated diff --git a/tests/raft_scenarios/bad_network b/tests/raft_scenarios/bad_network_deprecated similarity index 100% rename from tests/raft_scenarios/bad_network rename to tests/raft_scenarios/bad_network_deprecated diff --git a/tests/raft_scenarios/check_quorum b/tests/raft_scenarios/check_quorum_deprecated similarity index 100% rename from tests/raft_scenarios/check_quorum rename to tests/raft_scenarios/check_quorum_deprecated diff --git a/tests/raft_scenarios/election b/tests/raft_scenarios/election_deprecated similarity index 100% rename from tests/raft_scenarios/election rename to tests/raft_scenarios/election_deprecated diff --git a/tests/raft_scenarios/election_while_reconfiguration b/tests/raft_scenarios/election_while_reconfiguration_deprecated similarity index 100% rename from tests/raft_scenarios/election_while_reconfiguration rename to tests/raft_scenarios/election_while_reconfiguration_deprecated diff --git a/tests/raft_scenarios/fancy_election.1 b/tests/raft_scenarios/fancy_election.1_deprecated similarity index 100% rename from tests/raft_scenarios/fancy_election.1 rename to tests/raft_scenarios/fancy_election.1_deprecated diff --git a/tests/raft_scenarios/fancy_election.2 b/tests/raft_scenarios/fancy_election.2_deprecated similarity index 100% rename from tests/raft_scenarios/fancy_election.2 rename to tests/raft_scenarios/fancy_election.2_deprecated diff --git a/tests/raft_scenarios/multi_election b/tests/raft_scenarios/multi_election_deprecated similarity index 100% rename from tests/raft_scenarios/multi_election rename to tests/raft_scenarios/multi_election_deprecated diff --git a/tests/raft_scenarios/reconfiguration b/tests/raft_scenarios/reconfiguration_deprecated similarity index 100% rename from tests/raft_scenarios/reconfiguration rename to tests/raft_scenarios/reconfiguration_deprecated diff --git a/tests/raft_scenarios/reconnect b/tests/raft_scenarios/reconnect_deprecated similarity index 100% rename from tests/raft_scenarios/reconnect rename to tests/raft_scenarios/reconnect_deprecated diff --git a/tests/raft_scenarios/reconnect_node b/tests/raft_scenarios/reconnect_node_deprecated similarity index 100% rename from tests/raft_scenarios/reconnect_node rename to tests/raft_scenarios/reconnect_node_deprecated diff --git a/tests/raft_scenarios/replicate b/tests/raft_scenarios/replicate_deprecated similarity index 100% rename from tests/raft_scenarios/replicate rename to tests/raft_scenarios/replicate_deprecated diff --git a/tests/raft_scenarios/soft_rollback b/tests/raft_scenarios/soft_rollback_deprecated similarity index 100% rename from tests/raft_scenarios/soft_rollback rename to tests/raft_scenarios/soft_rollback_deprecated diff --git a/tests/raft_scenarios/suffix_collision.1 b/tests/raft_scenarios/suffix_collision.1_deprecated similarity index 100% rename from tests/raft_scenarios/suffix_collision.1 rename to tests/raft_scenarios/suffix_collision.1_deprecated diff --git a/tests/raft_scenarios/suffix_collision.2 b/tests/raft_scenarios/suffix_collision.2_deprecated similarity index 100% rename from tests/raft_scenarios/suffix_collision.2 rename to tests/raft_scenarios/suffix_collision.2_deprecated diff --git a/tests/raft_scenarios/suffix_collision.3 b/tests/raft_scenarios/suffix_collision.3_deprecated similarity index 100% rename from tests/raft_scenarios/suffix_collision.3 rename to tests/raft_scenarios/suffix_collision.3_deprecated diff --git a/tests/raft_scenarios_runner.py b/tests/raft_scenarios_runner.py index f92154379d4c..92f89deed5a0 100644 --- a/tests/raft_scenarios_runner.py +++ b/tests/raft_scenarios_runner.py @@ -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,7 +36,29 @@ def write_error_report(errors=None): print("??? success \n") -def separate_log_lines(text): +def remove_reconfiguration_replicates(log): + 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): @@ -41,7 +66,10 @@ def separate_log_lines(text): mermaid.append(line[len("") :]) 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)