mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-11-29 06:04:06 +00:00
ci: keep each restart's replay and fail drop cells whose writers stop early
A server's log is named after the phase it started in, so every crash cycle's restarted server keeps its own log and replay lines. Timed writers fail unless every writer ran to its deadline, and a drop cell stops before its drop when they do. Replay results keep every region with its WAL range, and the drop summary no longer reads a release counter from the restarted process. Signed-off-by: jeremyhi <fengjiachun@gmail.com>
This commit is contained in:
@@ -20,7 +20,8 @@ batch sequence numbers, inserts `rows` rows per batch and stops at the first
|
||||
statement that is not acknowledged, so a stripe has at most one attempted but
|
||||
unacknowledged batch: the one in flight at the kill. Every request is logged
|
||||
with its status and the time it ended, on the same clock as the kill stamps.
|
||||
With `--seconds` the writers also stop once that long has passed.
|
||||
With `--seconds` the writers also stop once that long has passed, and the
|
||||
command fails unless every writer wrote until then without a failure.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -51,7 +52,7 @@ def insert(url: str, table: str, seq: int, rows: int) -> str:
|
||||
return "000"
|
||||
|
||||
|
||||
def writer(args, index: int, deadline: float) -> None:
|
||||
def writer(args, index: int, deadline: float, failures: list) -> None:
|
||||
directory, seq = Path(args.dir), args.first_seq + index
|
||||
with open(directory / f"attempted-{index}.log", "a") as attempted, \
|
||||
open(directory / f"requests-{index}.log", "a") as requests, \
|
||||
@@ -63,6 +64,7 @@ def writer(args, index: int, deadline: float) -> None:
|
||||
requests.write(f"{seq} {code} {time.time_ns()}\n")
|
||||
requests.flush()
|
||||
if code != "200":
|
||||
failures.append(f"writer {index}: batch {seq} ended with {code}")
|
||||
break
|
||||
acked.write(f"{seq}\n")
|
||||
acked.flush()
|
||||
@@ -73,11 +75,24 @@ def writer(args, index: int, deadline: float) -> None:
|
||||
def write(args) -> int:
|
||||
os.makedirs(args.dir, exist_ok=True)
|
||||
deadline = time.monotonic() + args.seconds if args.seconds else float("inf")
|
||||
threads = [threading.Thread(target=writer, args=(args, i, deadline)) for i in range(args.writers)]
|
||||
failures = []
|
||||
|
||||
def run(index):
|
||||
try:
|
||||
writer(args, index, deadline, failures)
|
||||
except Exception as error:
|
||||
failures.append(f"writer {index}: {error!r}")
|
||||
raise
|
||||
|
||||
threads = [threading.Thread(target=run, args=(i,)) for i in range(args.writers)]
|
||||
for thread in threads:
|
||||
thread.start()
|
||||
for thread in threads:
|
||||
thread.join()
|
||||
# Crash cells end their writers with a kill; timed writers must have run to the deadline.
|
||||
if args.seconds and (failures or not any(lines(Path(args.dir) / f"acked-{i}.log") for i in range(args.writers))):
|
||||
print("; ".join(failures) or "no batch was acknowledged", file=sys.stderr)
|
||||
return 1
|
||||
return 0
|
||||
|
||||
|
||||
|
||||
@@ -93,7 +93,9 @@ elapsed() { awk -v a="$1" -v b="$(now)" 'BEGIN {printf "%.3f", b - a}'; }
|
||||
server_cpu() { docker exec "$cid" cat /sys/fs/cgroup/cpu.stat 2>/dev/null | awk '/^usage_usec / {printf "%.3f", $2 / 1e6}' || true; }
|
||||
host_cpu() { awk '/^cpu / {print $2 + $3 + $4 + $7 + $8 + $9, $2 + $3 + $4 + $5 + $6 + $7 + $8 + $9}' /proc/stat 2>/dev/null || true; }
|
||||
|
||||
# A server's log is named after the phase it started in, whatever phase stops it.
|
||||
start_server() {
|
||||
server_phase=$phase
|
||||
cid=$(docker run -d --init --name "$name$phase" --label "o11ybench.owner=$OWNER" \
|
||||
--add-host host.docker.internal:host-gateway \
|
||||
-p 127.0.0.1:4000:4000 -p 127.0.0.1:4001:4001 "${docker_env[@]}" ${mounts[@]+"${mounts[@]}"} \
|
||||
@@ -114,7 +116,7 @@ stop_server() {
|
||||
killed) docker wait "$cid" >/dev/null ;;
|
||||
*) docker stop -t 120 "$cid" >/dev/null ;;
|
||||
esac
|
||||
docker logs "$cid" > "$dir/server$phase.log" 2>&1
|
||||
docker logs "$cid" > "$dir/server$server_phase.log" 2>&1
|
||||
docker rm -fv "$cid" >/dev/null
|
||||
cid=
|
||||
}
|
||||
@@ -234,7 +236,8 @@ drop_restart() {
|
||||
sql "CREATE TABLE dropped (seq BIGINT, ts TIMESTAMP TIME INDEX) WITH (append_mode = 'true')" >/dev/null
|
||||
sql "CREATE TABLE kept (seq BIGINT, ts TIMESTAMP TIME INDEX) WITH (append_mode = 'true')" >/dev/null
|
||||
python3 "$here/oswal-s3-bench-crash.py" write --dir "$dir/dropped" --url "$sql_url" --table dropped \
|
||||
--writers "$writers" --first-seq 0 --rows "$rows" --seconds "$seconds"
|
||||
--writers "$writers" --first-seq 0 --rows "$rows" --seconds "$seconds" \
|
||||
|| { echo "$id: the writers of dropped stopped before $seconds s" >&2; exit 10; }
|
||||
phase=-written; scrape_retry indexed_objects || { echo "$id: metrics scrape failed" >&2; exit 4; }
|
||||
sql "DROP TABLE dropped" >/dev/null
|
||||
stop_server kill
|
||||
@@ -244,13 +247,14 @@ drop_restart() {
|
||||
scrape_retry recovery_seconds_count || { echo "$id: metrics scrape failed" >&2; exit 4; }
|
||||
recovered=$(awk '/^greptime_logstore_object_store_wal_recovered_objects_total / {print $2}' "$dir/metrics-restart.prom")
|
||||
python3 "$here/oswal-s3-bench-crash.py" write --dir "$dir/kept" --url "$sql_url" --table kept \
|
||||
--writers 1 --first-seq 0 --rows "$rows" --seconds 2
|
||||
--writers 1 --first-seq 0 --rows "$rows" --seconds 2 \
|
||||
|| { echo "$id: the writer of kept stopped before 2 s" >&2; exit 10; }
|
||||
sql "ADMIN FLUSH_TABLE('kept')" >/dev/null
|
||||
# The flushed watermark becomes durable with the next object, so every sample writes one row.
|
||||
deadline=$((SECONDS + ${OSWAL_COLLECT_SECONDS:-120}))
|
||||
while :; do
|
||||
sql "INSERT INTO kept VALUES (-1, $SECONDS)" >/dev/null
|
||||
# The samples have their own file; the final scrape and the log keep the restart's name.
|
||||
# The samples have their own file; the final scrape keeps the restart's name.
|
||||
phase=-collected
|
||||
scrape_retry indexed_objects || { phase=-restart; echo "$id: metrics scrape failed" >&2; exit 4; }
|
||||
phase=-restart
|
||||
@@ -296,7 +300,7 @@ finish() {
|
||||
cell() {
|
||||
: "${PLAN:?}" "${RESULTS:?}" "${CORPUS_DIR:?}" "${OWNER:?}" "${RUNTIME_IMAGE:?}" "${GREPTIMEDB_IMAGE:?}"
|
||||
: "${RUN_PREFIX:?}" "${WAL_ROOT:?}" "${S3_BUCKET:?}" "${S3_REGION:?}" "${AWS_ACCESS_KEY_ID:?}" "${AWS_SECRET_ACCESS_KEY:?}"
|
||||
spec=$1 cid= wal_dir= home_dir= version= load_seconds= metrics_scraped=false id= phase=
|
||||
spec=$1 cid= wal_dir= home_dir= version= load_seconds= metrics_scraped=false id= phase= server_phase=
|
||||
restart_scraped=false restart_seconds= restart_query_seconds= restart_count= server_cpu_seconds= host_cpu_busy=
|
||||
indexed_before_kill=
|
||||
local concurrency setting started cpu_before host_before host_after corpus partitions load script
|
||||
|
||||
@@ -96,18 +96,25 @@ def replay(log: Path, metrics: dict) -> dict | None:
|
||||
regions = []
|
||||
for match in REPLAY.finditer(log.read_text(errors="replace")):
|
||||
region, provider, rows, first, last, elapsed, unit = match.groups()
|
||||
if int(rows):
|
||||
objects = (int(last) >> POSITION_BITS) - (int(first) >> POSITION_BITS) + 1 \
|
||||
if provider == "ObjectStore" else None
|
||||
regions.append({"region": int(region), "rows": int(rows), "seconds": float(elapsed) * UNITS[unit],
|
||||
"objects": objects})
|
||||
# The range runs from the first entry to replay to the last one; it is empty when first > last.
|
||||
objects = None if provider != "ObjectStore" else 0 if int(first) > int(last) else \
|
||||
(int(last) >> POSITION_BITS) - (int(first) >> POSITION_BITS) + 1
|
||||
regions.append({"region": int(region), "rows": int(rows), "first_entry_id": int(first),
|
||||
"last_entry_id": int(last), "seconds": float(elapsed) * UNITS[unit], "objects": objects})
|
||||
samples = metrics["samples"]
|
||||
return {"regions": regions, "rows": sum(r["rows"] for r in regions),
|
||||
"seconds": max((r["seconds"] for r in regions), default=None),
|
||||
"objects": sum(r["objects"] or 0 for r in regions) if regions and regions[0]["objects"] else None,
|
||||
"objects": sum(r["objects"] for r in regions) if regions and regions[0]["objects"] is not None else None,
|
||||
"read_seconds": samples.get("read_seconds_sum"), "reads": samples.get("read_seconds_count")}
|
||||
|
||||
|
||||
def replayed(regions: list) -> str:
|
||||
"""Each region that replayed rows: its rows, the objects of its range and its time."""
|
||||
return "; ".join(f"{r['region']}: {r['rows']:,} rows" + (
|
||||
f", objects {r['first_entry_id'] >> POSITION_BITS:,}–{r['last_entry_id'] >> POSITION_BITS:,}"
|
||||
if r["objects"] else "") + f", {r['seconds']:.2f} s" for r in regions if r["rows"]) or "—"
|
||||
|
||||
|
||||
def client_latency(path: Path) -> tuple:
|
||||
"""The 50th and 99th percentile of the loader's own time per write request."""
|
||||
durations = []
|
||||
@@ -124,7 +131,7 @@ def region_rows(path: Path) -> list | None:
|
||||
"""Rows per region of a partitioned load cell, as the server reported them after the load."""
|
||||
if not path.exists():
|
||||
return None
|
||||
return [int(row[2]) for row in json.loads(path.read_text())["output"][0]["records"]["rows"]]
|
||||
return [int(row[2] or 0) for row in json.loads(path.read_text())["output"][0]["records"]["rows"]]
|
||||
|
||||
|
||||
def interval_seconds(wal: dict) -> float:
|
||||
@@ -239,7 +246,6 @@ def load_cell(path: Path, spec: dict | None = None) -> dict:
|
||||
"indexed_before_drop": written.get("indexed_objects"),
|
||||
"restart_seconds": cell.get("restart_seconds"),
|
||||
"recovered_objects": restarted_samples.get("recovered_objects_total"),
|
||||
"release_records": restarted_samples.get("release_records_total"),
|
||||
"indexed_at_end": int(float(samples[-1][1])) if samples else None,
|
||||
"deleted_after_restart": restarted_samples.get("deleted_objects_total"),
|
||||
"seconds_to_collect": int(samples[-1][0]) - int(samples[0][0]) if samples else None,
|
||||
@@ -383,21 +389,22 @@ def render(run: dict, rows: list, pairs: list) -> str:
|
||||
replays += [(r["id"], fmt(c["cycle"]), c | {"wall_seconds": c.get("restart_seconds")})
|
||||
for r in crashes for c in r["cycles"] if c.get("replay")]
|
||||
if replays:
|
||||
lines += ["", "| Cell | Cycle | Restart to /health s | Recovery s | Recovered objects | Regions replayed "
|
||||
"| Rows replayed | Objects replayed | Slowest region replay s | Read seconds (reads) |",
|
||||
"| --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | --- |"]
|
||||
lines += ["", "| Cell | Cycle | Restart to /health s | Recovery s | Recovered objects | Regions opened "
|
||||
"| Rows replayed | Objects replayed | Slowest region replay s | Read seconds (reads) "
|
||||
"| Regions with rows |",
|
||||
"| --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | --- | --- |"]
|
||||
for cell, cycle, x in replays:
|
||||
y = x["replay"]
|
||||
lines.append(" | ".join([
|
||||
f"| {cell}", cycle, fmt(x.get("wall_seconds"), 2), fmt(x.get("recovery_seconds"), 3),
|
||||
fmt(x.get("recovered_objects")), fmt(len(y["regions"])), fmt(y["rows"]), fmt(y["objects"]),
|
||||
fmt(y["seconds"], 2), f"{fmt(y['read_seconds'], 2)} ({fmt(y['reads'])})"]) + " |")
|
||||
fmt(y["seconds"], 2), f"{fmt(y['read_seconds'], 2)} ({fmt(y['reads'])})",
|
||||
replayed(y["regions"])]) + " |")
|
||||
drops = [r for r in rows if r.get("drop")]
|
||||
if drops:
|
||||
lines += ["", "| Cell | Acked batches before the drop | Indexed before the drop | Restart to /health s "
|
||||
"| Recovered objects | Release records | Indexed at the end | Deleted after the restart "
|
||||
"| Seconds to collect | Verdict |",
|
||||
"| --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | --- |"]
|
||||
"| Recovered objects | Indexed at the end | Deleted after the restart | Seconds to collect | Verdict |",
|
||||
"| --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | --- |"]
|
||||
for r in drops:
|
||||
x = r["drop"]
|
||||
# Objects the release already collected before the kill leave nothing to show.
|
||||
@@ -406,7 +413,7 @@ def render(run: dict, rows: list, pairs: list) -> str:
|
||||
"collected" if r["exit_code"] == 0 else "still indexed"
|
||||
lines.append(" | ".join([
|
||||
f"| {label(r)}", fmt(x["acked_batches"]), fmt(x["indexed_before_drop"]), fmt(x["restart_seconds"], 2),
|
||||
fmt(x["recovered_objects"]), fmt(x["release_records"]), fmt(x["indexed_at_end"]),
|
||||
fmt(x["recovered_objects"]), fmt(x["indexed_at_end"]),
|
||||
fmt(x["deleted_after_restart"]), fmt(x["seconds_to_collect"]), verdict]) + " |")
|
||||
restarts = [r for r in rows if "restart" in r]
|
||||
if restarts:
|
||||
|
||||
Reference in New Issue
Block a user