diff --git a/.github/workflows/compatibility.yml b/.github/workflows/compatibility.yml new file mode 100644 index 000000000..ad0f9b3d4 --- /dev/null +++ b/.github/workflows/compatibility.yml @@ -0,0 +1,61 @@ +name: Compatibility + +on: + pull_request: + push: + branches: [main] + +permissions: + contents: read + +concurrency: + group: compatibility-${{ github.event_name == 'push' && github.run_id || github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + +jobs: + protobuf: + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + # actions/checkout v6 + - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 + with: + fetch-depth: 0 + persist-credentials: false + - name: Install checksum-pinned Buf + run: | + bash deploy/automation/install-buf.sh "$RUNNER_TEMP/buf-bin" + echo "$RUNNER_TEMP/buf-bin" >> "$GITHUB_PATH" + - name: Compare Protobuf contracts + env: + BASELINE_SHA: ${{ github.event.pull_request.base.sha || github.event.before }} + run: python3 deploy/automation/protobuf_compatibility.py "$BASELINE_SHA" HEAD + persistence: + runs-on: ubuntu-latest + timeout-minutes: 25 + env: + GOPROXY: https://golang.flatt.tech + steps: + # actions/checkout v6 + - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 + with: + fetch-depth: 0 + persist-credentials: false + # actions/setup-go v6 + - uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c + with: + go-version-file: go.mod + - name: Build baseline and candidate + env: + BASELINE_SHA: ${{ github.event.pull_request.base.sha || github.event.before }} + run: | + baseline=$(git rev-parse --verify --end-of-options "${BASELINE_SHA}^{commit}") + mkdir "$RUNNER_TEMP/baseline-source" + git archive "$baseline" | tar -x -C "$RUNNER_TEMP/baseline-source" + (cd "$RUNNER_TEMP/baseline-source" && go build -o "$RUNNER_TEMP/elastickv-baseline" .) + go build -o "$RUNNER_TEMP/elastickv-candidate" . + go build -o "$RUNNER_TEMP/raftadmin" ./cmd/raftadmin + - name: Install Redis test client + run: sudo apt-get install -y redis-tools + - name: Check quorum and data through rolling upgrade, downgrade, reupgrade and snapshot restart + run: bash scripts/compatibility-smoke.sh "$RUNNER_TEMP/elastickv-baseline" "$RUNNER_TEMP/elastickv-candidate" "$RUNNER_TEMP/raftadmin" diff --git a/.github/workflows/proto.yml b/.github/workflows/proto.yml index 4783b97e3..6e0321497 100644 --- a/.github/workflows/proto.yml +++ b/.github/workflows/proto.yml @@ -31,11 +31,7 @@ jobs: # actions/checkout v6 - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 with: - fetch-depth: 0 persist-credentials: false - - name: Fetch main for breaking baseline - if: github.ref != 'refs/heads/main' - run: git fetch --no-tags --prune origin +refs/heads/main:refs/heads/buf-breaking-base # actions/setup-go v6 - uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c with: @@ -46,10 +42,6 @@ jobs: run: go install google.golang.org/protobuf/cmd/protoc-gen-go@${{ env.PROTOC_GEN_GO_VERSION }} - name: Install protoc-gen-go-grpc run: go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@${{ env.PROTOC_GEN_GO_GRPC_VERSION }} - - name: buf breaking (against main) - if: github.ref != 'refs/heads/main' - working-directory: proto - run: buf breaking --against '../.git#subdir=proto,branch=buf-breaking-base' - name: Clean generated proto outputs run: find proto -maxdepth 1 -type f \( -name '*.pb.go' -o -name '*_grpc.pb.go' \) -delete - name: buf generate diff --git a/README.md b/README.md index d1d938c37..a9569e250 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,8 @@ A single node has no replica redundancy. These unauthenticated local endpoints a For Docker, persistence checks, S3/SQS setup, and troubleshooting, follow the [Getting started guide](docs/getting_started.md). For a replicated deployment, choose [Kubernetes](docs/kubernetes.md) or [multiple VMs with Docker](docs/docker_multinode_manual_run.md). +See [Compatibility CI](docs/operations/compatibility-ci.md) for schema and upgrade checks. + ## Architecture Elastickv presents several APIs over a shared sharded KV engine. diff --git a/deploy/automation/install-buf.sh b/deploy/automation/install-buf.sh new file mode 100644 index 000000000..ff47aec10 --- /dev/null +++ b/deploy/automation/install-buf.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +set -euo pipefail + +mkdir -p "$1" +curl --fail --silent --show-error --location --retry 3 --max-time 120 \ + https://github.com/bufbuild/buf/releases/download/v1.55.1/buf-Linux-x86_64 \ + --output "$1/buf" +printf '%s %s\n' 70d46fbf2e1df60b250d0954a2c6ef2cb57baa936b197a55a9c1b8de89d95c1d "$1/buf" | sha256sum --check +chmod 0755 "$1/buf" diff --git a/deploy/automation/protobuf_compatibility.py b/deploy/automation/protobuf_compatibility.py new file mode 100644 index 000000000..37e0bebea --- /dev/null +++ b/deploy/automation/protobuf_compatibility.py @@ -0,0 +1,130 @@ +"""Compare immutable Protobuf trees using a trusted Buf FILE policy.""" + +import argparse +import json +import os +import pathlib +import subprocess +import tempfile + + +def write_workspace(directory, sources): + modules = [] + has_primary_module = any(path.startswith("proto/") for path in sources) + if has_primary_module: + modules.append({"path": "proto"}) + if not sources or any(not path.startswith("proto/") for path in sources): + root_module = {"path": "."} + if has_primary_module: + root_module["excludes"] = ["proto"] + modules.append(root_module) + directory.mkdir() + for path, data in sources.items(): + relative = pathlib.PurePosixPath(path) + if ( + relative.is_absolute() + or ".." in relative.parts + or relative.as_posix() != path + ): + raise ValueError("Invalid Protobuf source path") + target = directory / relative + target.parent.mkdir(parents=True, exist_ok=True) + target.write_bytes(data) + (directory / "buf.yaml").write_text( + json.dumps({"version": "v2", "modules": modules, "breaking": {"use": ["FILE"]}}) + ) + + +def breaking_changes(baseline, candidate): + if not baseline: + if not candidate: + return [] + # Compile the first schema even though it has no prior contracts. + baseline = candidate + if not candidate: + # Buf needs a non-empty candidate. Choose a distinct path so it + # reports every baseline schema as removed. + marker = "_empty.proto" + while marker in baseline or "proto/" + marker in baseline: + marker = "_" + marker + candidate = {marker: b'syntax = "proto3";\n'} + with tempfile.TemporaryDirectory(prefix="protobuf-compatibility-") as work: + root = pathlib.Path(work) + write_workspace(root / "baseline", baseline) + write_workspace(root / "candidate", candidate) + result = subprocess.run( + [ + "buf", + "breaking", + "candidate", + "--against", + "baseline", + "--disable-symlinks", + "--error-format=json", + ], + cwd=root, + env={**os.environ, "XDG_CACHE_HOME": str(root / "cache")}, + capture_output=True, + text=True, + timeout=30, + ) + if result.returncode == 0: + return [] + try: + violations = [ + json.loads(line) + for line in (*result.stdout.splitlines(), *result.stderr.splitlines()) + ] + if ( + result.returncode == 100 + and violations + and all(row.get("type") and row.get("message") for row in violations) + ): + return sorted( + ( + row.get("path", "protobuf").split("/", 1)[-1], + row["type"], + row["message"], + ) + for row in violations + ) + except (ValueError, AttributeError): + pass + raise ValueError( + "Buf could not complete the Protobuf check: " + + ( + result.stderr or result.stdout or f"exit status {result.returncode}" + ).strip()[:4096] + ) + + +def git_schemas(revision): + commit = subprocess.check_output( + ["git", "rev-parse", "--verify", "--end-of-options", revision + "^{commit}"], + text=True, + ).strip() + entries = subprocess.check_output( + ["git", "ls-tree", "-rz", commit], text=True + ).split("\0") + sources = {} + for entry in filter(None, entries): + metadata, path = entry.split("\t", 1) + if path.endswith(".proto"): + mode, kind, blob = metadata.split() + if mode not in ("100644", "100755") or kind != "blob": + raise ValueError("Unsupported Protobuf source mode: " + path) + sources[path] = subprocess.check_output(["git", "cat-file", "blob", blob]) + return sources + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("baseline") + parser.add_argument("candidate") + args = parser.parse_args() + violations = breaking_changes( + git_schemas(args.baseline), git_schemas(args.candidate) + ) + for path, rule, message in violations: + print(f"{path}: {rule}: {message}") + raise SystemExit(bool(violations)) diff --git a/docs/operations/compatibility-ci.md b/docs/operations/compatibility-ci.md new file mode 100644 index 000000000..158e282f7 --- /dev/null +++ b/docs/operations/compatibility-ci.md @@ -0,0 +1,35 @@ +# Compatibility CI + +The [Compatibility workflow](../../.github/workflows/compatibility.yml) compares +the PR merge result with the PR's base commit. On pushes to `main`, it compares +the new commit with the branch's previous tip. + +- **Protobuf** runs Buf's `FILE` rules over the checked-in schemas, including + internal RPCs. The CI supplies the policy to both revisions. Generated code + drift is checked by the separate Proto workflow. +- **Persistence** builds both revisions and starts three loopback Raft voters + with disposable data directories. It replaces one voter at a time during + upgrade, downgrade, reupgrade, and restart. Before downgrade and the final + restart, each voter must persist a snapshot covering a new marker. The test + moves each stopped voter's Pebble state aside, preserves its Raft WAL and + snapshots, and requires a successful full snapshot restore and marker + readback from the recovered voter while it is the leader. During downgrade, + each voter first opens the candidate's intact + Pebble database with the baseline, then verifies that the baseline can also + restore the candidate-generated snapshot. + When the next voter is the leader, the test transfers leadership + first. During each replacement it samples the two remaining voters for a + shared leader and term and tests a committed Redis write and read. While the + voter is stopped, it also writes and reads data through Redis, DynamoDB, S3, + and SQS. It checks the original synthetic data after each rollout. + +Both jobs run on GitHub-hosted runners with read-only repository permissions. +The test credentials are disposable and used by the loopback listeners. +The isolated [release qualification](../../deploy/automation/README.md) +covers the deployment image and Kubernetes rollout. + +Run the schema check locally from the repository root with Buf 1.55.1: + +```sh +python3 deploy/automation/protobuf_compatibility.py origin/main HEAD +``` diff --git a/scripts/compatibility-smoke.sh b/scripts/compatibility-smoke.sh new file mode 100644 index 000000000..5319364ef --- /dev/null +++ b/scripts/compatibility-smoke.sh @@ -0,0 +1,371 @@ +#!/usr/bin/env bash +# Run in a disposable environment. All listeners and clients use loopback. +set -euo pipefail + +baseline=$1 +candidate=$2 +raftadmin=$3 +work=$(mktemp -d) +pids=("" "" "") +probe_pid= +client=0 +phase=baseline + +stop() { + local node=$1 pid=${pids[$1]} + kill -TERM "$pid" + for _ in {1..30}; do + if ! kill -0 "$pid" 2>/dev/null; then + wait "$pid" + pids[node]= + return + fi + sleep 1 + done + echo "Node $node did not stop cleanly during $phase" >&2 + return 1 +} + +cleanup() { + local status=$? pid log + touch "$work/probe-stop" + for pid in "$probe_pid" "${pids[@]}"; do + if [[ -n "$pid" ]]; then + kill -KILL "$pid" 2>/dev/null || true + wait "$pid" 2>/dev/null || true + fi + done + if (( status != 0 )); then + echo "Compatibility smoke failed during $phase" >&2 + for log in "$work"/"$phase"-*.log "$work/probe.log"; do + if [[ -f "$log" ]]; then + printf '\n--- %s ---\n' "$log" >&2 + tail -n 35 "$log" >&2 + fi + done + fi + rm -rf "$work" +} +trap cleanup EXIT + +export AWS_ACCESS_KEY_ID=compatibility-test AWS_SECRET_ACCESS_KEY=compatibility-test-local-only +export AWS_DEFAULT_REGION=us-east-1 AWS_EC2_METADATA_DISABLED=true AWS_PAGER= +export AWS_CONFIG_FILE=/dev/null AWS_SHARED_CREDENTIALS_FILE=/dev/null +export AWS_REQUEST_CHECKSUM_CALCULATION=when_required AWS_RESPONSE_CHECKSUM_VALIDATION=when_required +export AWS_MAX_ATTEMPTS=1 +export NO_PROXY=127.0.0.1 no_proxy=127.0.0.1 +unset AWS_PROFILE AWS_DEFAULT_PROFILE AWS_SESSION_TOKEN AWS_SECURITY_TOKEN + +printf '{"credentials":[{"access_key_id":"%s","secret_access_key":"%s"}]}\n' \ + "$AWS_ACCESS_KEY_ID" "$AWS_SECRET_ACCESS_KEY" > "$work/credentials.json" +python3 -c 'import sys; sys.stdout.buffer.write(bytes(range(256)) * 1024)' > "$work/object" + +raft_addr() { printf '127.0.0.1:%s' "$((15051 + $1))"; } +redis_port() { printf '%s' "$((16379 + $1))"; } +s3_port() { printf '%s' "$((19000 + $1))"; } +redis() { timeout 5 redis-cli -h 127.0.0.1 -p "$(redis_port "$client")" --raw "$@"; } +aws_local() { aws --cli-connect-timeout 3 --cli-read-timeout 10 --endpoint-url "http://127.0.0.1:$1" "${@:2}"; } +dynamo() { aws_local "$((18000 + client))" dynamodb "$@"; } +s3() { aws_local "$(s3_port "$client")" s3api "$@"; } +sqs() { aws_local "$((19324 + client))" sqs "$@"; } +admin() { + local node=$1 + shift + RAFTADMIN_RPC_TIMEOUT_SECONDS=3 "$raftadmin" "$(raft_addr "$node")" "$@" +} +ready() { curl -fs --max-time 1 "http://127.0.0.1:$((18081 + $1))/readyz" > /dev/null; } + +members='' redis_map='' s3_map='' +for node in 0 1 2; do + members+="${members:+,}n$node=$(raft_addr "$node")" + redis_map+="${redis_map:+,}$(raft_addr "$node")=127.0.0.1:$(redis_port "$node")" + s3_map+="${s3_map:+,}$(raft_addr "$node")=127.0.0.1:$(s3_port "$node")" +done + +start() { + local node=$1 binary=$2 + shift 2 + "$binary" \ + --address "$(raft_addr "$node")" --redisAddress "127.0.0.1:$(redis_port "$node")" \ + --dynamoAddress "127.0.0.1:$((18000 + node))" --metricsAddress "127.0.0.1:$((19090 + node))" \ + --healthAddress "127.0.0.1:$((18081 + node))" --pprofAddress= \ + --s3Address "127.0.0.1:$(s3_port "$node")" --s3CredentialsFile "$work/credentials.json" \ + --sqsAddress "127.0.0.1:$((19324 + node))" --sqsCredentialsFile "$work/credentials.json" \ + --sqsPublicEndpoint "http://127.0.0.1:$((19324 + node))" \ + --raftRedisMap "$redis_map" --raftS3Map "$s3_map" \ + --raftId "n$node" --raftDataDir "$work/data-$node" "$@" > "$work/$phase-$node.log" 2>&1 & + pids[node]=$! +} + +# All supplied members must be ready and agree on the same leader and term. +# The leader must itself be one of those members. +leader() { + local node status leader_node='' leader_addr='' term='' observed_addr observed_term + for node in "$@"; do + ready "$node" || return 1 + status=$(admin "$node" status) || return 1 + observed_addr=$(awk -F'"' '/^leader_address:/ {print $2}' <<< "$status") + observed_term=$(awk '/^term:/ {print $2}' <<< "$status") + [[ -n $observed_addr && -n $observed_term ]] || return 1 + [[ ${leader_addr:-$observed_addr} == "$observed_addr" && ${term:-$observed_term} == "$observed_term" ]] || return 1 + leader_addr=$observed_addr + term=$observed_term + if [[ $leader_addr == "$(raft_addr "$node")" ]] && grep -qx 'state: LEADER' <<< "$status"; then + leader_node=$node + fi + done + [[ -n $leader_node ]] || return 1 + echo "$leader_node" +} + +wait_for_leader() { + local expected=$1 excluded=$2 elected + shift 2 + for _ in {1..45}; do + if elected=$(leader "$@") && + [[ $elected != "$excluded" && ( $expected == -1 || $elected == "$expected" ) ]]; then + echo "$elected" + return + fi + sleep 1 + done + echo "No agreed leader for nodes $* during $phase" >&2 + return 1 +} + +verify() { + for i in {1..32}; do + [[ $(redis GET "compatibility:$i") == "seed-$i" ]] + done + [[ $(dynamo get-item --table-name compatibility --key '{"id":{"S":"seed"}}' \ + --consistent-read --query Item.value.S --output text) == persistent ]] + s3 get-object --bucket compatibility --key seed "$work/readback" > /dev/null + cmp "$work/object" "$work/readback" + local queue messages observed='[]' + queue=$(sqs get-queue-url --queue-name compatibility --query QueueUrl --output text) + for _ in {1..5}; do + messages=$(sqs receive-message --queue-url "$queue" --visibility-timeout 0 \ + --wait-time-seconds 2 --max-number-of-messages 10 --output json) + observed=$(jq -c --argjson observed "$observed" \ + '$observed + [.Messages[]?.Body] | unique' <<< "$messages") + if [[ $observed == '["persistent-a","persistent-b"]' ]]; then + break + fi + done + [[ $observed == '["persistent-a","persistent-b"]' ]] + echo "$phase: Redis, DynamoDB, S3 and SQS data verified" +} + +# Exercise each API while a voter is fully stopped. Each transition gets its +# own keys so the writes cannot be satisfied by data from a previous step. +verify_live() { + local key=$1 queue receipt + [[ $(redis SET "$key" "$key") == OK ]] + [[ $(redis GET "$key") == "$key" ]] + dynamo put-item --table-name compatibility --item "{\"id\":{\"S\":\"$key\"},\"value\":{\"S\":\"$key\"}}" + [[ $(dynamo get-item --table-name compatibility --key "{\"id\":{\"S\":\"$key\"}}" \ + --consistent-read --query Item.value.S --output text) == "$key" ]] + s3 put-object --bucket compatibility --key "$key" --body "$work/object" > /dev/null + s3 get-object --bucket compatibility --key "$key" "$work/live-readback" > /dev/null + cmp "$work/object" "$work/live-readback" + queue=$(sqs get-queue-url --queue-name compatibility-live --query QueueUrl --output text) + sqs send-message --queue-url "$queue" --message-body "$key" > /dev/null + receipt=$(sqs receive-message --queue-url "$queue" --wait-time-seconds 5 --output json | + jq -er --arg key "$key" '.Messages[] | select(.Body == $key) | .ReceiptHandle') + sqs delete-message --queue-url "$queue" --receipt-handle "$receipt" +} + +# Sample quorum and a committed Redis write/read once per second, with no retry +# on a failed sample. The interval begins after any planned leadership handoff. +observe() { + trap - EXIT + local sample=0 + while [[ ! -f $work/probe-stop ]]; do + if ! client=$(leader "$@"); then + echo "Voters $* lost readiness or disagreed on the leader or term" >&2 + return 1 + fi + sample=$((sample + 1)) + [[ $(redis SET compatibility:probe "$sample") == OK ]] || return 1 + [[ $(redis GET compatibility:probe) == "$sample" ]] || return 1 + echo "$sample" + sleep 1 + done +} + +probe_samples() { + awk '/^[0-9]+$/ { count++ } END { print count+0 }' "$work/probe.log" +} + +wait_for_offline_sample() { + local node=$1 previous=$2 + for _ in {1..10}; do + if ! kill -0 "$probe_pid" 2>/dev/null; then + echo "Quorum probe exited while voter $node was offline" >&2 + return 1 + fi + if (( $(probe_samples) > previous )); then + return + fi + sleep 1 + done + echo "No successful quorum sample while voter $node was offline" >&2 + return 1 +} + +raft_index() { + admin "$1" status | awk -v key="$2:" '$1 == key { print $2 }' +} + +seed_snapshot() { + local key=$1 node target index + [[ $(redis SET "$key" "$key") == OK ]] + target=$(raft_index "$client" commit_index) + [[ $target =~ ^[1-9][0-9]*$ ]] + for i in {1..48}; do + [[ $(redis SET compatibility:snapshot-padding "$i") == OK ]] + done + for node in 0 1 2; do + for _ in {1..45}; do + index=$(raft_index "$node" last_snapshot_index) + if [[ $index =~ ^[0-9]+$ ]] && (( index >= target )); then + break + fi + sleep 1 + done + if [[ ! $index =~ ^[0-9]+$ ]] || (( index < target )); then + echo "Voter $node did not persist a snapshot containing $key at index $target" >&2 + return 1 + fi + echo "$phase: voter $node persisted snapshot $index containing $key" + done +} + +assert_snapshot_restored() { + local node=$1 key=$2 metrics before after + metrics=$(curl -fs --max-time 5 "http://127.0.0.1:$((19090 + node))/metrics") + if ! awk '/^elastickv_fsm_cold_start_restore_total\{/ && /outcome="(fallback|executed)"/ && $NF > 0 { restored = 1 } + END { exit !restored }' <<< "$metrics"; then + echo "Voter $node did not report a full cold-start snapshot restore during $phase" >&2 + return 1 + fi + # A follower can proxy GET to another voter. Make the recovered voter the + # leader of this single-group fixture and require a stable term across GET. + if [[ $client != "$node" ]]; then + admin "$client" leadership_transfer_to_server "n$node" "$(raft_addr "$node")" + fi + client=$(wait_for_leader "$node" -1 0 1 2) + before=$(admin "$node" status) + grep -qx 'state: LEADER' <<< "$before" + [[ $(redis GET "$key") == "$key" ]] + after=$(admin "$node" status) + grep -qx 'state: LEADER' <<< "$after" + [[ $(awk '/^term:/ {print $2}' <<< "$before") == "$(awk '/^term:/ {print $2}' <<< "$after")" ]] + echo "$phase: voter $node restored the snapshot body and read back $key" +} + +replace() { + local phase=${4:-$phase} + local node=$1 binary=$2 snapshot_key=${3:-} target survivor key="$phase-$1" configuration samples + local survivors=() + for target in 0 1 2; do + if [[ $target != "$node" ]]; then + survivors+=("$target") + fi + done + client=$(wait_for_leader -1 -1 0 1 2) + if [[ $client == "$node" ]]; then + target=${survivors[0]} + admin "$node" leadership_transfer_to_server "n$target" "$(raft_addr "$target")" + fi + client=$(wait_for_leader -1 "$node" 0 1 2) + configuration=$(admin "$client" configuration) + if [[ $(grep -c 'suffrage: "voter"' <<< "$configuration") != 3 ]]; then + echo "Expected three configured voters during $phase" >&2 + echo "$configuration" >&2 + return 1 + fi + + rm -f "$work/probe-stop" + observe "${survivors[@]}" > "$work/probe.log" 2>&1 & + probe_pid=$! + stop "$node" + if ! client=$(leader "${survivors[@]}"); then + echo "No ready quorum after voter $node stopped during $phase" >&2 + return 1 + fi + samples=$(probe_samples) + verify_live "$key" + for survivor in "${survivors[@]}"; do + client=$survivor + [[ $(redis GET "$key") == "$key" ]] + done + wait_for_offline_sample "$node" "$samples" + if [[ -n $snapshot_key ]]; then + # Force a cold start with the local Raft WAL and snapshot intact. + mv "$work/data-$node/n$node/fsm.db" "$work/$phase-$node.fsm.db" + fi + start "$node" "$binary" + client=$(wait_for_leader -1 -1 0 1 2) + touch "$work/probe-stop" + wait "$probe_pid" + probe_pid= + if [[ -n $snapshot_key ]]; then + assert_snapshot_restored "$node" "$snapshot_key" + fi + client=$node + [[ $(redis GET "$key") == "$key" ]] + echo "$phase: voter $node replaced, quorum and all four APIs verified while it was offline" +} + +for node in 0 1 2; do + start "$node" "$baseline" --raftBootstrap --raftBootstrapMembers "$members" +done +client=$(wait_for_leader -1 -1 0 1 2) +for i in {1..32}; do + [[ $(redis SET "compatibility:$i" "seed-$i") == OK ]] +done +dynamo create-table --table-name compatibility --attribute-definitions AttributeName=id,AttributeType=S \ + --key-schema AttributeName=id,KeyType=HASH --billing-mode PAY_PER_REQUEST > /dev/null +dynamo put-item --table-name compatibility --item '{"id":{"S":"seed"},"value":{"S":"persistent"}}' +s3 create-bucket --bucket compatibility > /dev/null +s3 put-object --bucket compatibility --key seed --body "$work/object" > /dev/null +queue=$(sqs create-queue --queue-name compatibility --query QueueUrl --output text) +sqs send-message --queue-url "$queue" --message-body persistent-a > /dev/null +sqs send-message --queue-url "$queue" --message-body persistent-b > /dev/null +sqs create-queue --queue-name compatibility-live > /dev/null +verify +for phase in upgrade downgrade reupgrade; do + binary=$candidate + snapshot_key= + if [[ $phase == downgrade ]]; then + binary=$baseline + unset ELASTICKV_RAFT_SNAPSHOT_COUNT + snapshot_key=compatibility:candidate-snapshot + else + export ELASTICKV_RAFT_SNAPSHOT_COUNT=16 + fi + for node in 0 1 2; do + replace "$node" "$binary" + if [[ $phase == downgrade ]]; then + replace "$node" "$binary" "$snapshot_key" downgrade-snapshot + fi + done + client=$(wait_for_leader -1 -1 0 1 2) + verify + if [[ $phase == upgrade ]]; then + seed_snapshot compatibility:candidate-snapshot + fi +done + +phase=snapshot-restart +seed_snapshot compatibility:restart-snapshot +phase=restore +for node in 0 1 2; do + replace "$node" "$candidate" compatibility:restart-snapshot +done +client=$(wait_for_leader -1 -1 0 1 2) +verify +for node in 0 1 2; do + stop "$node" +done