Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
61 changes: 61 additions & 0 deletions .github/workflows/compatibility.yml
Original file line number Diff line number Diff line change
@@ -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"
8 changes: 0 additions & 8 deletions .github/workflows/proto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions deploy/automation/install-buf.sh
Original file line number Diff line number Diff line change
@@ -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"
130 changes: 130 additions & 0 deletions deploy/automation/protobuf_compatibility.py
Original file line number Diff line number Diff line change
@@ -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))
35 changes: 35 additions & 0 deletions docs/operations/compatibility-ci.md
Original file line number Diff line number Diff line change
@@ -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
```
Loading
Loading