#!/usr/bin/env bash # CTR empirical test A: client-visible ROLLBACK latency vs undo-chain length N. # # The design (README.undo:20-25, 105-112) claims ROLLBACK returns in O(1) to # the client for "sparse" transactions: physical undo is deferred to background # workers above undo_instant_abort_threshold, and applied INLINE (in the # aborting backend, before ROLLBACK returns) below it. # # We measure the client-visible ROLLBACK latency as N (number of undo-generating # file ops in one transaction) grows, at three settings of the threshold # (session-local SET; the GUC is PGC_USERSET), to separate the two regimes and # prove the knee is caused by the threshold (calibration), not something else. # # Metric: wall time of the ROLLBACK statement only (psql \timing), median of R # repeats. The N chmods hit one pre-created file; each records one undo record # (prior mode). Nothing commits, so filesystem state is trivial and the only # thing that scales is the undo chain length. set -u PORT=${PORT:-5467} BIN=$HOME/undo-v2-inst/bin PSQL="$BIN/psql -p $PORT -U postgres -X -q -t -A" REPEATS=${REPEATS:-5} NS=${NS:-"100 300 1000 3000 10000 30000 100000"} # threshold regimes: default, forced-inline (huge), forced-deferred (tiny) THRS=${THRS:-"65536 1000000000 1"} OUT=${OUT:-/home/manu/Proyectos/yggdrasil/aportes/postgres-undo-ctr/logs_v2/ctr_rollback_latency.tsv} mkdir -p "$(dirname "$OUT")" $PSQL -c "CREATE EXTENSION IF NOT EXISTS test_fileops;" >/dev/null 2>&1 F=$($PSQL -c "SELECT test_fileops_create_tempfile('ctr_lat.dat');") median() { sort -n | awk '{a[NR]=$1} END{ if(NR==0){print "NA"} else if(NR%2){print a[(NR+1)/2]} else {printf "%.3f\n",(a[NR/2]+a[NR/2+1])/2} }'; } # ROLLBACK latency (ms) for one trial at chain length N and threshold THR. # Everything in one psql session; the LAST "Time:" line is the ROLLBACK. one_trial() { local n=$1 thr=$2 $PSQL 2>/dev/null <