mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-07-22 07:53:38 +00:00
76783f3d71
* test: add FUSE database load/durability/perf benchmark Runs MySQL (InnoDB) and SQLite with ~1GB datadirs on a SeaweedFS FUSE mount. Two parts: - durability: normal shutdown, kill -9, and crash-during-write all keep every fsync-committed row (verified by integrity check + row count + contiguous prefix + per-row CRC). - performance: FUSE vs the same local disk. fsync/commit latency is the dominant cost (~0.13ms -> ~1.18ms), so small transactions run ~9-12x slower while bulk loads and warm reads stay close. Harness is path-independent (runtime under $SEAWEED_BENCH_WORK) and only touches its own processes on non-default ports. * test/benchmark/fuse_db: portable to Linux + crash-safe progress - export MYSQL_BIN; mysql_bench.py falls back to PATH when unset - unmount via fusermount/fusermount3 (non-root Linux), then umount/diskutil - atomic progress write (tmp+fsync+rename); treat empty progress file as 0 - reuse a single PRNG in the perf probe so RNG init doesn't skew timings * test/benchmark/fuse_db: validate inputs, add subprocess timeout - mysql_bench.py: 1800s timeout on mysql CLI calls; reject db names that aren't plain identifiers (interpolated into SQL) - sqlite_gen.py / sqlite_verify.py: allowlist journal/synchronous modes and the verify mode so a typo can't silently weaken durability or relax checks - run_mysql.sh: durable atomic progress write (tmp+fsync+rename), matching sqlite_gen.py; quote $LB in both crash-test verify calls
71 lines
3.0 KiB
Python
71 lines
3.0 KiB
Python
#!/usr/bin/env python3
|
|
# Verify a SQLite DB after a crash/restart.
|
|
# - PRAGMA integrity_check (structural consistency of the b-tree / pages)
|
|
# - row count / sum(chk) / sum(id) vs expected
|
|
# - recompute crc32(payload) for every row vs stored chk (byte corruption)
|
|
#
|
|
# usage: sqlite_verify.py <db> <expected_rows> [mode]
|
|
# mode=exact (default): count must == expected_rows (normal/unexpected shutdown
|
|
# of a fully-loaded DB -- nothing may be lost or extra).
|
|
# mode=atleast: expected_rows is a LOWER BOUND (durable committed progress at
|
|
# crash time). count must be >= expected_rows and form a contiguous
|
|
# prefix 0..count-1 (the in-flight txn may or may not have committed,
|
|
# but no committed row may be lost and recovery must be consistent).
|
|
import sys, sqlite3, zlib, random
|
|
|
|
db_path = sys.argv[1]
|
|
expected_rows = int(sys.argv[2])
|
|
mode = sys.argv[3] if len(sys.argv) > 3 else "exact"
|
|
if mode not in ("exact", "atleast"): # a typo must not silently relax checks
|
|
raise SystemExit(f"invalid mode: {mode!r} (want exact|atleast)")
|
|
|
|
def payload(i: int) -> bytes:
|
|
return random.Random(i).randbytes(4096)
|
|
|
|
con = sqlite3.connect(db_path)
|
|
ok = True
|
|
|
|
ic = con.execute("PRAGMA integrity_check;").fetchone()[0]
|
|
print(f"integrity_check: {ic}")
|
|
if ic != "ok": ok = False
|
|
|
|
cnt = con.execute("SELECT COUNT(*) FROM t;").fetchone()[0]
|
|
minid = con.execute("SELECT MIN(id) FROM t;").fetchone()[0]
|
|
maxid = con.execute("SELECT MAX(id) FROM t;").fetchone()[0]
|
|
sum_chk= con.execute("SELECT COALESCE(SUM(chk),0) FROM t;").fetchone()[0]
|
|
sum_id = con.execute("SELECT COALESCE(SUM(id),0) FROM t;").fetchone()[0]
|
|
|
|
if mode == "exact":
|
|
target = expected_rows
|
|
if cnt != expected_rows:
|
|
print(f"rows: got={cnt} expected={expected_rows} MISMATCH"); ok = False
|
|
else:
|
|
print(f"rows: got={cnt} expected={expected_rows} OK")
|
|
else: # atleast
|
|
print(f"rows: got={cnt} committed-lower-bound={expected_rows} "
|
|
f"{'OK' if cnt >= expected_rows else 'LOST COMMITTED DATA'}")
|
|
if cnt < expected_rows: ok = False
|
|
target = cnt
|
|
# contiguous prefix 0..cnt-1 ?
|
|
if cnt > 0 and (minid != 0 or maxid != cnt - 1):
|
|
print(f"prefix: MIN={minid} MAX={maxid} expected 0..{cnt-1} NON-CONTIGUOUS"); ok = False
|
|
else:
|
|
print(f"prefix: 0..{maxid} contiguous OK")
|
|
|
|
exp_sum_chk = sum(zlib.crc32(payload(i)) for i in range(target))
|
|
exp_sum_id = target * (target - 1) // 2
|
|
print(f"sum(chk): got={sum_chk} expected={exp_sum_chk} {'OK' if sum_chk==exp_sum_chk else 'MISMATCH'}")
|
|
print(f"sum(id): got={sum_id} expected={exp_sum_id} {'OK' if sum_id==exp_sum_id else 'MISMATCH'}")
|
|
if sum_chk != exp_sum_chk or sum_id != exp_sum_id: ok = False
|
|
|
|
corrupt = 0; scanned = 0
|
|
for rid, p, c in con.execute("SELECT id,payload,chk FROM t;"):
|
|
scanned += 1
|
|
if zlib.crc32(p) != c: corrupt += 1
|
|
print(f"payload byte-check: scanned={scanned} corrupt={corrupt} {'OK' if corrupt==0 else 'CORRUPT'}")
|
|
if corrupt != 0: ok = False
|
|
|
|
con.close()
|
|
print("VERIFY: " + ("PASS" if ok else "FAIL"))
|
|
sys.exit(0 if ok else 1)
|