diff --git a/src/sqlancer/voltdb/README.md b/src/sqlancer/voltdb/README.md index 7a87784db..dd764a290 100644 --- a/src/sqlancer/voltdb/README.md +++ b/src/sqlancer/voltdb/README.md @@ -4,7 +4,7 @@ A SQLancer provider for [VoltDB](https://www.voltactivedata.com/), developed for VoltDB schemas, both replicated and partitioned tables, fills them with single-row inserts, upserts, updates and deletes, and runs SQLancer's oracles against them through the VoltDB JDBC driver. -**Status: milestone 39.** The provider creates schemas and data and runs these logic-bug oracles: NoREC (the default, +**Status: milestone 40.** The provider creates schemas and data and runs these logic-bug oracles: NoREC (the default, milestone 2), TLP WHERE (milestone 3), TLP DISTINCT, TLP HAVING and TLP AGGREGATE (milestone 5), PQS (milestone 6), and PARAMS, literals against JDBC parameters (milestone 8). Since milestone 9 each database's rows are also updated, upserted and deleted before the oracles run. Since milestone 10 each database also has materialized views, which the @@ -51,7 +51,8 @@ Since milestone 36 the CONFIG oracle changes the configuration while the databas snapshot; see [The SNAPSHOT oracle](#the-snapshot-oracle). Since milestone 38 the XCONFLICT oracle makes XDCR conflicts on purpose and checks that every divergence they leave is reported; see [The XCONFLICT oracle](#the-xconflict-oracle). Since milestone 39 the TASK oracle runs scheduled tasks and checks that -they run as scheduled and stop when disabled; see [The TASK oracle](#the-task-oracle). +they run as scheduled and stop when disabled; see [The TASK oracle](#the-task-oracle). Since milestone 40 `--export` +also exports through a JDBC target into a sink cluster; see [The JDBC target](#the-jdbc-target-milestone-40). `SMOKE`, from milestone 1, only reads every table and checks that the queries succeed. `voltdb/run-sqlancer.sh` (milestone 4) starts a cluster, runs SQLancer against it and saves the results. A nightly lab job (milestone 7) runs it against master's kit; @@ -1232,6 +1233,44 @@ its lines (milestone 30's seven runs together) to 25.8% from the export run alon gap sessions (`E3ServerGapSession`, `E3ClientGapSession`, 237 lines) still never run: with k=2 every replica has every row, and a rejoined node never had to fill a gap. +### The JDBC target (milestone 40) + +Milestone 33's coverage run still found the JDBC export client (`JDBCExportClient`, 623 lines) never run. So +`--export` adds a third target for the streams, **JDBC** (`sqlancer_jdbc`, `type="jdbc"`), into VoltDB itself: the +script starts a sink, one node of the kit under test (k=0, 2 sites per host, on port slot 19, never killed), and the +target's `jdbcurl` is `jdbc:voltdb://localhost:`, with `ignoregenerations` and `skipinternals`, so +that each stream's rows go into a sink table of the stream's name and columns. The provider gets `--export-target +sqlancer,sqlancer_http,sqlancer_jdbc`, so db0 and db3 export to the file target, db1 to HTTP and db2 to JDBC. After +`@Quiesce`, once the sink's counts have not changed for 10 s, each `XS_DB_ST` table's rows and distinct `I` go into +the results' `export/jdbc.csv`, and the count at the end adds the distinct `I` to the file and HTTP targets' rows. + +Into VoltDB the target writes rows with `UPSERT`, and the tables it creates have no primary key, so VoltDB refuses +every row; its `CREATE TABLE` also gives a FLOAT column the type `DOUBLE PRECISION`, which VoltDB refuses (ENG-30681 +below). So while `--avoid-known-bugs` is true (the provider's default; the script reads `-- --avoid-known-bugs false`), +the script creates the sink's tables beforehand, with `I` as their primary key, and sets `createtable` to false. + +Milestone 40 also fixes four things that kept the HTTP and JDBC targets nearly idle in runs that kill nodes, or that +miscounted there: + +- With `--node-failures`, the connection reports "object name already exists" as a node failure, so STREAMS' `CREATE` + of an object made earlier (`XS_LB`, made by another database first) ended the check, and the database name's loopback + stream was never made: from then on every check of db1, db2 and db3 failed its first loopback insert and left its + stream out of step. In lab runs with kills, HTTP got 1 row. STREAMS now creates only what the catalog lacks, and + takes a stream's name only once all of its objects exist. +- A stream out of step (an insert a node failure interrupted) was skipped for the rest of the run. Its database name + now goes on with a stream of the next generation, `XS_DB2G1_ST` and so on, up to 8; the old one is kept, as dropping + it may lose rows still to export. The sink has a table for each generation. +- An insert into a stream that failed, or that a node failure interrupted, may still have committed and been exported. + STREAMS counts these, and those still running when SQLancer exits, as interrupted, and the count at the end allows + between the inserted rows and those plus the interrupted ones. +- The file target's rows were counted as distinct lines. After a failover the new partition leader exports some rows + again with its own site id, so the line differs: the rows are now counted by their distinct `I`, like the HTTP and + JDBC targets'. + +In a 5-minute trial on 3 nodes with k=2 and 2 sites per host, beside NoREC, STREAMS inserted 2,653 rows; all were +exported, 729 through HTTP and 656 through JDBC. In an 8-minute one with a node killed every 2 minutes, beside NoREC, +TLP WHERE, VIEWS and TTL, 3,221 rows, 883 through HTTP and 828 through JDBC (before these fixes, 1 and 1). + The bugs below were found in milestone 29. | Ticket | Issue | Workaround | @@ -1703,6 +1742,12 @@ The bugs below were found in milestone 29's lab run of the milestones before it. | --- | --- | --- | | ENG-30628 | A LEFT JOIN of a partitioned table P whose WHERE clause compares a scalar subquery with P's primary key (its partitioning column) fails to plan: "SQL error while compiling query: java.lang.IllegalStateException" (`SubPlanAssembler.buildIndexAccessPlanForTable`). The inner join, and the WHERE clause on P alone, plan. Also on 16.0.0. Found by TLP AGGREGATE in lab build #41 (the upgrade run, after the upgrade). | No scalar subqueries in a query with an outer join. | +The bug below was found in milestone 40. + +| Ticket | Issue | Workaround | +| --- | --- | --- | +| ENG-30681 | JDBC export to VoltDB with `createtable` (its default) delivers no rows: the tables it creates have no primary key, but it writes rows with `UPSERT` ("Unsupported UPSERT table without primary key"), and for a FLOAT column its `CREATE TABLE` uses `DOUBLE PRECISION` ("type not found or user lacks privilege: DOUBLE"). The export retries each block for good, and a graceful shutdown stops with the cluster paused. 16.0.0 too. Found by the JDBC target's first trial; `repros/ENG-30681.sh` exports a stream with a FLOAT column and one without from one 1-node cluster to another and finds neither row. Hang, Blocker for V16.1.0. | While `--avoid-known-bugs` is true, the script creates the sink's tables beforehand, with a primary key, and sets `createtable` to false | + The bug below was found in milestone 39. | Ticket | Issue | Workaround | diff --git a/src/sqlancer/voltdb/oracle/VoltDBStreamOracle.java b/src/sqlancer/voltdb/oracle/VoltDBStreamOracle.java index b899720ae..5e216514e 100644 --- a/src/sqlancer/voltdb/oracle/VoltDBStreamOracle.java +++ b/src/sqlancer/voltdb/oracle/VoltDBStreamOracle.java @@ -32,6 +32,12 @@ public class VoltDBStreamOracle implements TestOracle { private static final AtomicLong INSERTED = new AtomicLong(); + // inserts into a stream that a node failure interrupted, or that failed: each may have committed, and been + // exported, or not + private static final AtomicLong INTERRUPTED = new AtomicLong(); + // inserts into a stream not yet counted either way: at exit, SQLancer's threads may still be running one, which may + // commit and be exported after INSERTED is printed (an export one row over in a milestone 40 trial) + private static final AtomicLong IN_FLIGHT = new AtomicLong(); private static final AtomicLong CHECKED = new AtomicLong(); private static final AtomicLong LOOPBACK_CHECKED = new AtomicLong(); // how long a loopback check waits for the export to deliver the rows @@ -44,17 +50,30 @@ public class VoltDBStreamOracle implements TestOracle { private static final String VIEW_QUERY = "SELECT k, s, COUNT(*), SUM(v), MIN(f), MAX(v) FROM %s GROUP BY k, s"; static { - Runtime.getRuntime().addShutdownHook(new Thread(() -> System.out.println("STREAMS inserted rows: " + INSERTED - + "; views compared: " + CHECKED + "; loopback exports compared: " + LOOPBACK_CHECKED))); + Runtime.getRuntime().addShutdownHook(new Thread(() -> { + // in flight first: an insert that completes between the reads is then counted twice, never not at all + long inFlight = IN_FLIGHT.get(); + long inserted = INSERTED.get(); + System.out.println( + "STREAMS inserted rows: " + inserted + "; interrupted inserts: " + (INTERRUPTED.get() + inFlight) + + "; views compared: " + CHECKED + "; loopback exports compared: " + LOOPBACK_CHECKED); + })); } // the streams whose rows went into the stream but not into the shadow table, after which the two may differ; // static, as a database name, and so its stream, is used again by later databases of the run private static final java.util.Set OUT_OF_STEP = java.util.concurrent.ConcurrentHashMap.newKeySet(); + // an exported stream out of step is kept, and the database name's checks go on with a stream of a new generation, + // XS_DB0G1_ST and so on, up to MAX_GENERATION; so that, in a run that kills nodes, each export target still gets + // rows after its stream's first interrupted insert (milestone 40: with kills, the HTTP and JDBC targets got 1 row + // each) + static final int MAX_GENERATION = 8; + private static final java.util.Map GENERATION = new java.util.concurrent.ConcurrentHashMap<>(); private final VoltDBGlobalState state; private String prefix; private String lastQuery; + private String lastError; public VoltDBStreamOracle(VoltDBGlobalState state) { this.state = state; @@ -66,22 +85,39 @@ public void check() throws Exception { String loopback = state.getDbmsSpecificOptions().loopbackTarget; boolean looping = loopback != null && !loopback.isBlank(); boolean exporting = target != null && !target.isBlank() || looping; - if (prefix == null) { - prefix = "XS_" + state.getDatabaseName().toUpperCase(); - // kept from an earlier database of the same name in this run, or made now - create(target != null && !target.isBlank() ? " EXPORT TO TARGET " + target(target) : ""); - if (looping) { - ddl("CREATE TABLE XS_LB" + TAGGED_COLUMNS + "; PARTITION TABLE XS_LB ON COLUMN k"); - ddl("CREATE STREAM " + prefix + "_LS PARTITION ON COLUMN k EXPORT TO TARGET " + loopback - + TAGGED_COLUMNS); + String base = "XS_" + state.getDatabaseName().toUpperCase(); + if (exporting && OUT_OF_STEP.contains(generationPrefix(base))) { + // an exported stream is kept for the run, as dropping it may lose rows still to export: the next + // generation's stream takes over + int next = GENERATION.getOrDefault(base, 0) + 1; + if (next > MAX_GENERATION) { + throw new IgnoreMeException(); } + GENERATION.put(base, next); + prefix = null; } - if (OUT_OF_STEP.contains(prefix)) { - // an exported stream is kept for the run, as dropping it may lose rows still to export; one that exports - // nowhere starts afresh - if (exporting) { - throw new IgnoreMeException(); + if (prefix == null || !prefix.equals(generationPrefix(base))) { + // kept from an earlier database of the same name in this run, or made now; the prefix is taken only once + // all of it exists, so that DDL a node failure interrupted (IgnoreMeException) is done again by the next + // check (before milestone 40 the loopback stream could be left missing, and every later check of the + // name failed) + String next = generationPrefix(base); + prefix = next; + try { + create(target != null && !target.isBlank() ? " EXPORT TO TARGET " + target(target) : ""); + if (looping) { + ddlIfMissing("XS_LB", + "CREATE TABLE XS_LB" + TAGGED_COLUMNS + "; PARTITION TABLE XS_LB ON COLUMN k"); + ddlIfMissing(next + "_LS", "CREATE STREAM " + next + "_LS PARTITION ON COLUMN k EXPORT TO TARGET " + + loopback + TAGGED_COLUMNS); + } + } catch (IgnoreMeException e) { + prefix = null; + throw e; } + } + if (OUT_OF_STEP.contains(prefix)) { + // one that exports nowhere starts afresh ddl("DROP VIEW " + prefix + "_SV IF EXISTS"); ddl("DROP STREAM " + prefix + "_ST IF EXISTS"); ddl("DROP TABLE " + prefix + "_SH IF EXISTS"); @@ -101,16 +137,28 @@ public void check() throws Exception { // an insert a node failure interrupted (IgnoreMeException with --node-failures, --crashes and the like) may // or may not have committed, so the stream and its shadow can differ from then on (lab build #44) boolean inStream; + IN_FLIGHT.incrementAndGet(); try { inStream = insert("INSERT INTO " + prefix + "_ST VALUES " + values); } catch (IgnoreMeException e) { + INTERRUPTED.incrementAndGet(); + IN_FLIGHT.decrementAndGet(); OUT_OF_STEP.add(prefix); throw e; } + if (inStream) { + INSERTED.incrementAndGet(); + } else { + INTERRUPTED.incrementAndGet(); + } + IN_FLIGHT.decrementAndGet(); if (!inStream) { + // a stream has no constraints, so an insert into it fails only when something else does (a node + // failure the connection did not report as one, say): it may have committed, and been exported + System.err.println( + "STREAMS: an insert into " + prefix + "_ST failed, and may have committed: " + lastError); continue; } - INSERTED.incrementAndGet(); if (looping) { boolean inLoopback; try { @@ -149,6 +197,12 @@ public void check() throws Exception { } } + // the database name's current stream generation: XS_DB0, then XS_DB0G1 and so on + private static String generationPrefix(String base) { + int g = GENERATION.getOrDefault(base, 0); + return g == 0 ? base : base + "G" + g; + } + // --export-target names one target or several, comma-separated: a database's stream exports to one of them by // the database's number, so that each target gets streams of its own private String target(String targets) { @@ -187,10 +241,29 @@ private void checkLoopback() throws SQLException { private void create(String export) { String columns = COLUMNS; - ddl("CREATE STREAM " + prefix + "_ST PARTITION ON COLUMN k" + export + columns); - ddl("CREATE TABLE " + prefix + "_SH" + columns + "; PARTITION TABLE " + prefix + "_SH ON COLUMN k"); + ddlIfMissing(prefix + "_ST", "CREATE STREAM " + prefix + "_ST PARTITION ON COLUMN k" + export + columns); + ddlIfMissing(prefix + "_SH", + "CREATE TABLE " + prefix + "_SH" + columns + "; PARTITION TABLE " + prefix + "_SH ON COLUMN k"); // a view of a partitioned stream groups by the partitioning column - ddl("CREATE VIEW " + prefix + "_SV (k, s, n, sv, mn, mx) AS " + String.format(VIEW_QUERY, prefix + "_ST")); + ddlIfMissing(prefix + "_SV", + "CREATE VIEW " + prefix + "_SV (k, s, n, sv, mn, mx) AS " + String.format(VIEW_QUERY, prefix + "_ST")); + } + + // DDL that creates the object NAME, unless the catalog has it already: made for an earlier database of the same + // name, or by another thread (XS_LB). With --node-failures the connection reports "object name already exists" + // as a node failure (IgnoreMeException), so creating an existing object would end every check (before milestone + // 40 the loopback stream of db1 and later was never made in a run with kills, and their streams got no rows) + private void ddlIfMissing(String name, String sql) { + lastQuery = sql; + try (ResultSet rs = ((sqlancer.voltdb.VoltDBConnection) state.getConnection()).getMetaData().getTables(null, + null, name, null)) { + if (rs.next()) { + return; + } + } catch (SQLException e) { + throw new IgnoreMeException(); + } + ddl(sql); } // DDL that may already have been done for this database name earlier in the run @@ -211,6 +284,7 @@ private boolean insert(String sql) { st.execute(sql); return true; } catch (SQLException e) { + lastError = e.getMessage(); return false; } } diff --git a/voltdb/repros/ENG-30681.sh b/voltdb/repros/ENG-30681.sh new file mode 100755 index 000000000..1615ee491 --- /dev/null +++ b/voltdb/repros/ENG-30681.sh @@ -0,0 +1,55 @@ +#!/bin/bash +: <<'HEADER' +-- ticket: ENG-30681 +-- summary: JDBC export to VoltDB with createtable delivers no rows: its tables have no primary key but rows go by UPSERT, and a FLOAT column fails the CREATE TABLE (DOUBLE PRECISION) +HEADER +# The runner's env: VOLTDB_HOME, PORT_BASE, WORKDIR. Two one-node clusters: a sink, and a source whose JDBC export +# target writes into the sink (jdbc:voltdb, createtable at its default, true). The source exports a stream with a +# FLOAT column (SF) and one without (SN), a row each; after 60 s, exit 0 if the sink lacks either row (the bug: no table +# SF, and SN's row refused, "Unsupported UPSERT table without primary key"), 1 if it has both, 2 on a setup failure. +set -u +V=$VOLTDB_HOME; W=$WORKDIR/jdbcfloat; P=$PORT_BASE +rm -rf "$W"; mkdir -p "$W" +export VOLTDB_OPTS="${VOLTDB_OPTS:-} -XX:ErrorFile=$W/hs_err_pid%p.log" +port() { echo $((P + 10 * $1 + $2)); } +cat >"$W/sink.xml" < + +XML +cat >"$W/source.xml" < + + + + + + jdbc:voltdb://localhost:$(port 0 0) + u + true + true + + + +XML +start() { # start N NAME + "$V/bin/voltdb" init --force -D "$W/$2" -C "$W/$2.xml" ${VOLTDB_LICENSE:+--license "$VOLTDB_LICENSE"} >"$W/init-$2.log" 2>&1 || exit 2 + (nohup "$V/bin/voltdb" start -D "$W/$2" -H "localhost:$(port $1 2)" --client=$(port $1 0) --admin=$(port $1 1) \ + --internal=$(port $1 2) --zookeeper=$(port $1 3) --replication=$(port $1 4) --metrics=$(port $1 5) \ + >"$W/start-$2.log" 2>&1 & + echo $! >"$W/$2.pid") + for _ in $(seq 1 180); do grep -q "Server completed initialization" "$W/start-$2.log" 2>/dev/null && return; sleep 1; done + exit 2 +} +cleanup() { for n in sink source; do kill -9 "$(cat "$W/$n.pid" 2>/dev/null)" 2>/dev/null; done; } +trap cleanup EXIT +start 0 sink +start 1 source +sql() { "$V/bin/sqlcmd" --servers=localhost --port=$(port $1 0) --stop-on-error=false 2>&1; } +printf "CREATE STREAM sf PARTITION ON COLUMN k EXPORT TO TARGET j (k INTEGER NOT NULL, f FLOAT);\nCREATE STREAM sn PARTITION ON COLUMN k EXPORT TO TARGET j (k INTEGER NOT NULL, b BIGINT);\nINSERT INTO sf VALUES (1, 1.5);\nINSERT INTO sn VALUES (1, 2);\n" | + sql 1 >"$W/source.out" +sleep 60 +printf "SELECT COUNT(*) FROM SN;\nSELECT COUNT(*) FROM SF;\n" | sql 0 | tee "$W/sink.out" +grep -m1 -h -o 'DDL Error: "type not found[^"]*"' "$W"/source/voltdbroot/log/volt.log +grep -m1 -h -o 'Unsupported UPSERT table without primary key[^)]*' "$W"/source/voltdbroot/log/volt.log +[ "$(grep -cE '^ *1 *$' "$W/sink.out")" -eq 2 ] && exit 1 +exit 0 diff --git a/voltdb/run-sqlancer.sh b/voltdb/run-sqlancer.sh index 8d41ba44c..5a4094d4e 100755 --- a/voltdb/run-sqlancer.sh +++ b/voltdb/run-sqlancer.sh @@ -52,7 +52,9 @@ Usage: voltdb/run-sqlancer.sh --voltdb [options] [-- ] --crash-interval, --xdcr or --upgrade-from. --export add a file export target ("sqlancer", CSV into each node's voltdbroot/sqlancer_export) for the STREAMS oracle's streams, and check at the end, after @Quiesce, that it wrote every row they got; - and a loopback target ("sqlancer_lb", into the table XS_LB) whose rows STREAMS checks as it goes + and a loopback target ("sqlancer_lb", into the table XS_LB) whose rows STREAMS checks as it goes; + an HTTP target ("sqlancer_http") and a JDBC target ("sqlancer_jdbc", into a one-node sink + cluster of the same kit) whose rows are counted with the file target's --keep-cluster leave the cluster running and its data in place after the run --mirror-voltdb DIR also start one node of this other VoltDB kit (normally the last release) and run the provider with --mirror: every change is repeated on it, and the DIFF oracle @@ -185,7 +187,7 @@ if $security; then provider_args=(--security true ${provider_args[@]+"${provider_args[@]}"}) fi if $export; then - provider_args=(--export-target sqlancer,sqlancer_http --loopback-target sqlancer_lb --ttl-migrate-target sqlancer_lbt ${provider_args[@]+"${provider_args[@]}"}) + provider_args=(--export-target sqlancer,sqlancer_http,sqlancer_jdbc --loopback-target sqlancer_lb --ttl-migrate-target sqlancer_lbt ${provider_args[@]+"${provider_args[@]}"}) fi # the administrator's credentials for voltadmin and sqlancer, with --security admin_creds=() @@ -245,8 +247,9 @@ port_in_use() { (exec 3<>"/dev/tcp/127.0.0.1/$1") 2>/dev/null; } added=0 [ "$resize_interval" -gt 0 ] && added=$((kfactor + 1)) added_slot=$((nodes + 1)) -# the XDCR peer's nodes take the slots from 20 +# the XDCR peer's nodes take the slots from 20; with --export, the JDBC target's sink node takes slot 19 xdcr_slot=20 +sink_slot=19 for ((i = 0; i < added_slot + added; i++)); do [ "$i" -eq "$nodes" ] && [ -z "$mirror_home" ] && continue for j in 0 1 2 3 4 5; do @@ -254,6 +257,12 @@ for ((i = 0; i < added_slot + added; i++)); do port_in_use "$p" && die "port $p is in use; pick another --port-base" done done +if $export; then + [ $((added_slot + added)) -le "$sink_slot" ] || die "--export allows at most $((sink_slot - 1 - added)) nodes" + for j in 0 1 2 3 4 5; do + port_in_use "$(port $sink_slot $j)" && die "port $(port $sink_slot $j) is in use; pick another --port-base" + done +fi if $xdcr; then [ "$nodes" -le "$xdcr_slot" ] || die "--xdcr allows at most $xdcr_slot nodes" for ((i = xdcr_slot; i < xdcr_slot + nodes; i++)); do @@ -370,7 +379,7 @@ stop_cluster() { sleep 1 done pkill -f "$cluster/" 2>/dev/null - for f in "$cluster"/node*.pid "$cluster"/add*.pid "$cluster"/mirror.pid; do + for f in "$cluster"/node*.pid "$cluster"/add*.pid "$cluster"/mirror.pid "$cluster"/sink.pid; do [ -e "$f" ] && is_server "$(cat "$f")" && kill -9 "$(cat "$f")" 2>/dev/null done } @@ -455,6 +464,12 @@ if $security; then ' fi +# ENG-30681: into VoltDB the JDBC target writes rows with UPSERT, but the tables it creates have no primary key, so +# VoltDB refuses every row; and its CREATE TABLE gives a FLOAT column the type DOUBLE PRECISION, which VoltDB refuses +# too. While avoiding known bugs (the provider's default), the sink's tables are created beforehand, with I (unique in +# the run) as their primary key, and the target creates none; a row exported twice is upserted once +jdbc_createtable=false +case " ${provider_args[*]-} " in *" --avoid-known-bugs false "*) jdbc_createtable=true ;; esac # with --export, a file target for the STREAMS oracle's streams, one CSV line per row. The outdir is relative, so each # node writes into its own voltdbroot, as on separate hosts: in one shared directory two nodes exporting the same # stream in the same second name the same file, and the target refuses it and retries the block for good, logging a @@ -472,6 +487,14 @@ if $export; then http://localhost:'"$(port 0 7)"'/%t + + jdbc:voltdb://localhost:'"$(port $sink_slot 0)"' + sqlancer + sqlancer + true + true + '"$jdbc_createtable"' + XS_LB.insert @@ -614,6 +637,42 @@ if [ -n "$mirror_home" ]; then provider_args+=(--mirror "localhost:$(client_port $m)") fi +# --- the JDBC target's sink (--export) --------------------------------------------------------------------------- + +# one node of the kit under test, k=0, 2 sites per host, on port slot 19, never killed; the JDBC target (milestone 40) +# creates a table there for each stream it exports, named after the stream, and inserts each row into it +if $export; then + sed -e 's/sitesperhost="[0-9]*"/sitesperhost="2"/' -e "s/kfactor=\"$kfactor\"/kfactor=\"0\"/" \ + -e '//d' \ + -e '//,/<\/export>/d' "$cluster/deployment.xml" >"$cluster/deployment-sink.xml" + "$voltdb_home/bin/voltdb" init --force -D "$cluster/sink" -C "$cluster/deployment-sink.xml" \ + ${license_args[@]+"${license_args[@]}"} >"$cluster/init-sink.log" 2>&1 || + die "voltdb init failed for the JDBC sink; see $cluster/init-sink.log" + (nohup "$voltdb_home/bin/voltdb" start -D "$cluster/sink" -c 1 -H "localhost:$(internal_port $sink_slot)" \ + --client="$(client_port $sink_slot)" --admin="$(admin_port $sink_slot)" \ + --internal="$(internal_port $sink_slot)" --zookeeper="$(port $sink_slot 3)" \ + --replication="$(port $sink_slot 4)" --metrics="$(port $sink_slot 5)" >"$cluster/start-sink.log" 2>&1 & + echo $! >"$cluster/sink.pid") + for _ in $(seq 1 300); do + grep -q "Server completed initialization" "$cluster/sink/voltdbroot/log/volt.log" 2>/dev/null && break + kill -0 "$(cat "$cluster/sink.pid")" 2>/dev/null || break + sleep 1 + done + grep -q "Server completed initialization" "$cluster/sink/voltdbroot/log/volt.log" 2>/dev/null || + die "the JDBC sink did not start; see $cluster/start-sink.log" + if ! $jdbc_createtable; then + # the tables the target would create: the STREAMS oracle's stream columns, one table per database name and + # stream generation (XS_DB2_ST, then XS_DB2G1_ST up to G8, as streams fall out of step) + for ((d = 0; d < 2 * threads; d++)); do + for g in "" G1 G2 G3 G4 G5 G6 G7 G8; do + echo "CREATE TABLE XS_DB${d}${g}_ST (K INTEGER NOT NULL, V BIGINT, S VARCHAR(16), F FLOAT, I BIGINT NOT NULL, PRIMARY KEY (I));" + done + done | "$voltdb_home/bin/sqlcmd" --port="$(client_port $sink_slot)" ${admin_creds[@]+--user=sqlancer --password=sqlancer} \ + >>"$results/run.log" 2>&1 + fi + log "JDBC sink ready, client port $(client_port $sink_slot)$($jdbc_createtable || echo ", tables made beforehand (ENG-30681)")" +fi + # --- SQLancer ---------------------------------------------------------------------------------------------------- sqlancer_args=(--num-threads "$threads" --num-tries "$threads" --timeout-seconds "$duration" --num-queries "$queries" @@ -1075,11 +1134,40 @@ export_failed=false exported=0 duplicates=0 inserted=0 +stream_interrupted=0 if $export; then within 120 "$voltdb_home/bin/sqlcmd" --port="$(client_port 0)" ${admin_creds[@]+--user=sqlancer --password=sqlancer} \ <<<"exec @Quiesce;" >>"$results/run.log" 2>&1 inserted=$(grep -m1 "^STREAMS inserted rows:" "$results/sqlancer/out.log" | sed 's/^STREAMS inserted rows: \([0-9]*\).*/\1/') + # inserts a node failure interrupted: each may have committed and been exported, or not + stream_interrupted=$(grep -m1 "^STREAMS inserted rows:" "$results/sqlancer/out.log" | sed -n 's/.*; interrupted inserts: \([0-9]*\).*/\1/p') + stream_interrupted=${stream_interrupted:-0} inserted=${inserted:-0} + # the JDBC target's rows, in the sink's tables named after the streams (XS_DB2_ST and so on): once their counts + # are the same three times in a row (at most 40 tries), each table's rows and distinct I (unique in the run), into + # export/jdbc.csv as TABLE,ROWS,DISTINCT_I + jdbc_count() { + local t queries= + for t in $("$voltdb_home/bin/sqlcmd" --port="$(client_port $sink_slot)" ${admin_creds[@]+--user=sqlancer --password=sqlancer} \ + --output-format=csv --output-skip-metadata <<<"exec @SystemCatalog TABLES;" 2>/dev/null | + awk -F, '{ gsub(/"/, "", $3); if ($3 ~ /^XS_DB[0-9]+(G[0-9]+)?_ST$/) print $3 }'); do + queries+="SELECT '$t', COUNT(*), COUNT(DISTINCT i) FROM $t;"$'\n' + done + [ -n "$queries" ] || return 0 + "$voltdb_home/bin/sqlcmd" --port="$(client_port $sink_slot)" ${admin_creds[@]+--user=sqlancer --password=sqlancer} \ + --output-format=csv --output-skip-metadata <<<"$queries" 2>/dev/null | tr -d '"' | sort + } + last= same=0 + for _ in $(seq 1 40); do + now=$(jdbc_count) + [ "$now" = "$last" ] && same=$((same + 1)) || same=0 + last=$now + [ "$same" -ge 3 ] && break + sleep 1 + done + mkdir -p "$results/export" + printf '%s\n' "$last" | grep -E '^XS_DB[0-9]+(G[0-9]+)?_ST,[0-9]+,[0-9]+$' >"$results/export/jdbc.csv" + within 60 "$voltdb_home/bin/voltadmin" shutdown --force -H "localhost:$(admin_port $sink_slot)" ${admin_creds[@]+"${admin_creds[@]}"} >>"$results/run.log" 2>&1 fi # --- collect ----------------------------------------------------------------------------------------------------- @@ -1135,13 +1223,18 @@ if $xdcr; then fi # the JVM error reports of servers that crashed; each names its node's directory in its command line save_logs "$results/servers" "$cluster"/hs_err_pid*.log +if $export; then + save_logs "$results/servers/sink" "$cluster/start-sink.log" "$cluster/init-sink.log" "$cluster/sink/voltdbroot/log" +fi if [ -n "$mirror_home" ]; then save_logs "$results/servers/mirror" "$cluster/start-mirror.log" "$cluster/init-mirror.log" \ "$cluster/mirror/voltdbroot/log" fi cp "$cluster/deployment.xml" "$results/" -# every row the STREAMS oracle inserted must have been exported; export is at least once, so a row exported twice (an -# identical line, with the same transaction id and sequence number) counts once, and the duplicates are reported +# every row the STREAMS oracle inserted must have been exported; export is at least once, so a row exported twice counts +# once, and the duplicates are reported. A row is told by its I, unique in the run: a row a new partition leader exported +# again after a failover has the same transaction id and sequence number but another site id (milestone 40), so its +# line differs if $export; then for ((i = 0; i < nodes; i++)); do mkdir -p "$results/export/node$i" @@ -1149,15 +1242,19 @@ if $export; then done cp "$cluster/http-export.log" "$results/export/" 2>/dev/null total=$(cat "$cluster"/node*/voltdbroot/sqlancer_export/*.csv 2>/dev/null | wc -l | tr -d ' ') - exported=$(cat "$cluster"/node*/voltdbroot/sqlancer_export/*.csv 2>/dev/null | sort -u | wc -l | tr -d ' ') + # each line's last column is the row's I + exported=$(cat "$cluster"/node*/voltdbroot/sqlancer_export/*.csv 2>/dev/null | awk -F, '{ print $NF }' | sort -u | wc -l | tr -d ' ') # the HTTP target's rows: each request is one row, its columns as form fields; the row's I is unique in the run http_total=$(grep -c "&I=[0-9]*" "$cluster/http-export.log" 2>/dev/null) http_rows=$(grep -o "&I=[0-9]*" "$cluster/http-export.log" 2>/dev/null | sort -u | wc -l | tr -d ' ') - total=$((total + ${http_total:-0})) - exported=$((exported + ${http_rows:-0})) + jdbc_total=$(awk -F, '{ s += $2 } END { print s + 0 }' "$results/export/jdbc.csv" 2>/dev/null) + jdbc_rows=$(awk -F, '{ s += $3 } END { print s + 0 }' "$results/export/jdbc.csv" 2>/dev/null) + total=$((total + ${http_total:-0} + ${jdbc_total:-0})) + exported=$((exported + ${http_rows:-0} + ${jdbc_rows:-0})) duplicates=$((total - exported)) - [ "$exported" -eq "$inserted" ] || export_failed=true - log "Export: $exported rows exported (${http_rows:-0} through HTTP; $duplicates exported twice), $inserted inserted into the streams$($export_failed && echo ", MISMATCH")" + # every inserted row, and at most the interrupted ones besides + [ "$exported" -ge "$inserted" ] && [ "$exported" -le $((inserted + stream_interrupted)) ] || export_failed=true + log "Export: $exported rows exported (${http_rows:-0} through HTTP, ${jdbc_rows:-0} through JDBC; $duplicates exported twice), $inserted inserted into the streams ($stream_interrupted inserts interrupted)$($export_failed && echo ", MISMATCH")" fi # XDCR's conflict log: each database writes through one cluster only, so XDCR has nothing to resolve, and any # conflict it logged fails the run; but for XCONFLICT's tables (XCP_..., XCR_...), whose conflicts it makes on purpose @@ -1228,7 +1325,7 @@ result=PASS grep -m1 "^SNAPSHOT restores checked:" "$results/sqlancer/out.log" 2>/dev/null grep -m1 "^XCONFLICT checks:" "$results/sqlancer/out.log" 2>/dev/null grep -m1 "^TASK checks:" "$results/sqlancer/out.log" 2>/dev/null - $export && echo "export: $exported rows exported (${http_rows:-0} through HTTP, $duplicates twice), $inserted inserted$($export_failed && echo ", a MISMATCH (export/)")" + $export && echo "export: $exported rows exported (${http_rows:-0} through HTTP, ${jdbc_rows:-0} through JDBC, $duplicates twice), $inserted inserted$($export_failed && echo ", a MISMATCH (export/)")" echo "transient results skipped (ENG-30602): $(grep -c "^ENG-30602 transient:" "$results/sqlancer/out.log" 2>/dev/null || true)" [ "$kill_interval" -gt 0 ] && echo "node failures: $kills kills, $rejoins rejoins$($chaos_failed && echo ", a rejoin FAILED (chaos.log)")" [ "$crash_interval" -gt 0 ] && echo "crashes: $crashes crashes, $recoveries recoveries$($crash_failed && echo ", a recovery FAILED (crash.log)")"