diff --git a/src/sqlancer/voltdb/README.md b/src/sqlancer/voltdb/README.md index e7ea0cfba..bb8ccad5e 100644 --- a/src/sqlancer/voltdb/README.md +++ b/src/sqlancer/voltdb/README.md @@ -25,7 +25,8 @@ change; see [The SCHEMA oracle](#the-schema-oracle). Since milestone 19 expressi functions and JSON functions, and the GEO oracle checks GEOGRAPHY_POINT and GEOGRAPHY; see [Date, JSON, FLOAT math and geography](#date-json-float-math-and-geography). Since milestone 20 the DIFF oracle compares this VoltDB with another version, normally the last release, on the same data; see -[The DIFF oracle](#the-diff-oracle). +[The DIFF oracle](#the-diff-oracle). Since milestone 21 the run script can also grow and shrink the cluster +elastically while SQLancer runs (`--resize-interval`); see [Elastic resizes](#elastic-resizes). `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; @@ -83,6 +84,7 @@ voltdb/run-sqlancer.sh --voltdb /opt/voltdb --nodes 3 --duration 3600 --seed 7 - | `--results DIR` | `./sqlancer-results` | Where the run's directory is created. | | `--use-reducer` | off | Reduce each failure before saving it (see [Reducing a failure](#reducing-a-failure)). | | `--kill-interval SECS` | 0 (never) | Every SECS seconds, kill a random node, node 0 included, with `kill -9`, restart it and wait until it has rejoined (see [Node failures](#node-failures)). Needs k-safety 1 or more. | +| `--resize-interval SECS` | 0 (never) | Every SECS seconds, add k+1 nodes with `voltdb start --add`, or remove them again with `voltadmin resize`, by turns (see [Elastic resizes](#elastic-resizes)). Does not mix with `--kill-interval`. | | `--keep-cluster` | off | Leave the cluster running, with its data, after the run. | | `-- ...` | | Everything after `--` goes to the provider, for example `-- --avoid-known-bugs false`. | @@ -98,6 +100,8 @@ that did not start). Each run writes `/sqlancer--seed/`: | `servers/node/` | Each node's `volt.log` and its `voltdb init` and `voltdb start` output. | | `sqlancer/` | SQLancer's output (`out.log`) and its `logs/voltdb/` directory (see [Reading the results](#reading-the-results)). | | `chaos.log` | With `--kill-interval`: each kill and rejoin, with its time. | +| `resize.log` | With `--resize-interval`: each grow and shrink, with its time, the planned removal and how long it took. | +| `servers/add-/` | With `--resize-interval`: the logs of node j added by grow n, like `servers/node/`. A join VoltDB refused is kept as `add--rejected`. | | `reproductions/` | The log of each database whose thread failed: the statements that set it up, then the failing queries. With `--use-reducer`, these are reduced, and `-reduce.log` shows the steps. | A run FAILs if any of these happens: @@ -105,6 +109,7 @@ A run FAILs if any of these happens: - A node is down at the end. - A server log has a FATAL line. - With `--kill-interval`, a killed node does not rejoin within 600 seconds. +- With `--resize-interval`, a grow or a shrink does not complete within 600 seconds. While `--avoid-known-bugs` is true (the default), a failed check whose queries no longer fail when its reproducer reruns them at once is not a failure. It is printed as `ENG-30602 transient: ...` in `sqlancer/out.log`, and the @@ -161,6 +166,46 @@ handle the errors a node failure causes: Without `--node-failures`, these errors fail the run as before. The OPS timeout makes each failure cost up to a minute of the threads that read the schema at the time, so a run with failures checks fewer queries. +## Elastic resizes + +With `--resize-interval SECS`, the script grows the cluster by k+1 nodes and shrinks it back by turns, a step every +SECS seconds, while SQLancer runs and the oracles keep checking query results: + +1. **Grow.** It starts k+1 new nodes with `voltdb start --add`, each with the whole host list, on the ports after the + original nodes' (slots `--nodes` to `--nodes`+k). VoltDB refuses a join while a catalog update is in progress + ("Can't do elastic join while catalog update is in progress"), which SQLancer's DDL makes common, and the joiner + then exits: the script kills the attempt's other nodes, keeps their logs as `add--rejected`, and tries + again, up to 10 times. A grow is done once every new node has started ("Server completed initialization") and the + cluster's topology has settled, about 40 seconds after the join: `voltadmin resize --test` then plans to remove + only the new nodes. +2. **Shrink.** `voltadmin resize` removes the partition group added last, which is the new nodes (the planner + removes the highest partitions). A shrink is done once their servers have exited. + +Host ids keep growing across grows, and VoltDB refuses to remove more than half the cluster, which is why the script +adds k+1 nodes: one partition group. When SQLancer stops the script lets the current step finish, and the summary +counts grows and shrinks. A step that does not finish within 600 seconds fails the run, and FATAL lines in an added +node's log fail it too (not in a rejected join's, where the FATAL is the refusal). + +With `--resize-interval`, the script passes the provider `--resizes true`: a shrink drops the calls in flight on the +hosts it removes, which the driver is connected to (`--servers`, `topologychangeaware`), so the provider expects the +same errors as for a killed node (see [Node failures](#node-failures)); the oracles' workarounds for ENG-30612, which +is about killed nodes, do not apply. It also passes `--ddl-hold /ddl.hold`: the script creates that file 3 +seconds before each shrink and deletes it once the shrink is done, and while it exists the connection holds every +DDL statement (CREATE, DROP, ALTER, PARTITION), for up to 15 minutes. Without it, a table that SQLancer drops while +the shrink streams its index snapshot hangs the shrink for good (ENG-30622). With `-- --avoid-known-bugs false` the +provider ignores the file. + +With `--resizes`, the provider also makes no ASSUMEUNIQUE constraint or index (a unique key on a partitioned table +that leaves out the partitioning column). VoltDB checks ASSUMEUNIQUE within a partition only, so two partitions can +hold rows with the same key, and a resize that moves one of them next to the other fails ("Found duplicates while +rebalancing data across partitions") and retries for good: lab build #40 hung a shrink this way for 10 minutes, until +SQLancer dropped the table. VoltDB documents this; it is not a bug. + +An elastic join, like a rejoin, makes system requests time out for a minute (ENG-30229): `@SystemInformation` and +`@SystemCatalog`, which the JDBC driver's `getMetaData()` and `DatabaseMetaData` calls send, fail with "OPS request hit +sixty second timeout" or "Too many pending stat requests". The connection retries them for up to 150 seconds, with or +without `--resizes`. + ## The nightly lab job `matrix-systemtest-apprunner-sqlancer` on jenkins-st runs this script against master's kit as part of the nightly @@ -171,18 +216,20 @@ system test (`matrix-systemtest/master`, on the nights the rotation in `internal The job fetches this repository at the commit in its `SQLANCER_REF` parameter. That commit is pinned in the Jenkinsfile, so a change here reaches the nightly run only when the Jenkinsfile is changed to name it. It then builds SQLancer with -the kit's runtime JDK and makes three runs, one after the other, every node on the agent: +the kit's runtime JDK and makes four runs, one after the other, every node on the agent: | Run (triagedb name) | Cluster | Oracles | Time | | --- | --- | --- | --- | -| `sqlancer-3n-k1-kill300` | 3 nodes, k=1, 8 sites per host; a node is killed and rejoined every 5 minutes | all sixteen (NoREC, TLP WHERE, DISTINCT, HAVING, AGGREGATE, PQS, PARAMS, VIEWS, LIMIT, SUBQUERY, WINDOW, SETOPS, DERIVED, PROCEDURE, SCHEMA, GEO) | 45 minutes | +| `sqlancer-3n-k1-kill300` | 3 nodes, k=1, 8 sites per host; a node is killed and rejoined every 5 minutes | all seventeen (NoREC, TLP WHERE, DISTINCT, HAVING, AGGREGATE, PQS, PARAMS, VIEWS, LIMIT, SUBQUERY, WINDOW, SETOPS, DERIVED, PROCEDURE, SCHEMA, GEO, DIFF) | 45 minutes | | `sqlancer-1n-k0` | 1 node, 8 sites per host | the same | 45 minutes | | `sqlancer-3n-k2-s2` | 3 nodes, k=2, 2 sites per host: every partition on every node, and 2 partitions in all | the same | 45 minutes | +| `sqlancer-3n-k1-resize120` | 3 nodes, k=1, 8 sites per host; every 2 minutes, 2 nodes are added, or removed again (see [Elastic resizes](#elastic-resizes)) | the same | 45 minutes | The shapes differ in what the planner and the execution engine do. With one node and 8 sites, a multi-partition query gathers 8 partitions' results in one process. With 3 nodes, k=1, the partitions' leaders are spread over the nodes and -each has one replica, and node failures move them. With k=2 and 2 sites per host, every node holds every partition, so -there are only 2 partitions and every write is replicated twice. The whole job takes about 2 hours 20 minutes. +each has one replica, and node failures move them; elastic resizes add a partition group and move data to it and +back. With k=2 and 2 sites per host, every node holds every partition, so +there are only 2 partitions and every write is replicated twice. The whole job takes about 3 hours 10 minutes. Every run uses `--use-reducer`. The first run's seed is the UTC time as `yyyymmddHHMM`, and each next run's is one more. @@ -197,8 +244,9 @@ To repeat a failure on your machine, take the seed and oracles from the bundle's them against the same build. The reproduction in `reproductions/` is usually quicker: run its statements on an empty server. -The job's parameters change a manual run: `CLUSTERS` (runs as `nodes:kfactor[:kill[:sites]]`, where kill is the -seconds between node failures and sites the sites per host, default `3:1:300 1:0 3:2:0:2`), `DURATION` (seconds +The job's parameters change a manual run: `CLUSTERS` (runs as `nodes:kfactor[:chaos[:sites]]`, where chaos is the +seconds between node failures, or `r` and the seconds between elastic resizes, and sites the sites per host, default +`3:1:300 1:0 3:2:0:2 3:1:r120`), `DURATION` (seconds per run, default 2700), `ORACLES`, `SEED`, `EXTRA_ARGS` (provider options) and `SQLANCER_REF`. A run of the job alone needs a kit: give `releasedir`, for example `releases/one-offs/16.1.0-SNAPSHOT-master/`. @@ -1024,6 +1072,13 @@ The bugs below were found in milestone 19. | ENG-30510 (comment) | The RIGHT JOIN bug through a FULL JOIN: a WHERE clause that rejects the right table's NULLs turns `a FULL JOIN b ON c >= b.k` into a RIGHT JOIN and then a LEFT JOIN that uses the ON condition as b's index range, dropping b's row. Found by TLP WHERE. Wrong result. | A FULL JOIN's ON condition reads the left table only. | | ENG-30611 | `DATEADD(YEAR, n, d)` on a DATE February 29 into a non-leap year: with a DATE literal the server aborts (uncaught `boost::gregorian::bad_day_of_month`), with a column it is "Invalid date 'February 29' as '2025' is not a leap year"; a TIMESTAMP and MONTH 12 give February 28. Found by PARAMS, crash found probing it. Critical. | DATEADD has no YEAR unit. | +The bugs below were found in milestone 21. + +| Ticket | Issue | Workaround | +| --- | --- | --- | +| ENG-30622 | An elastic remove hangs for good at "Building index for data migration" when a table is dropped while it streams its index snapshot: the hosts being removed log "No table streamer of Type TABLE_STREAM_ELASTIC_INDEX" and "Snapshot of table ... failed to complete", and `voltadmin resize --status` stays at "Planning data migration". Also on 16.0.0. Found by a local `--resize-interval` trial, where SQLancer's cleanup of an old database dropped its tables during a shrink; a script reproduces it in a few cycles. Critical. | DDL waits during each shrink (`--ddl-hold`). | +| ENG-30229 (existing) | System requests time out for 60 seconds during an elastic join, as during a rejoin, and the JDBC metadata calls with them. | The connection retries them for up to 150 seconds. | + The published `voltdbclient` jar does not register its JDBC driver with `java.sql.Driver`, so the provider loads `org.voltdb.jdbc.Driver` itself. diff --git a/src/sqlancer/voltdb/VoltDBConnection.java b/src/sqlancer/voltdb/VoltDBConnection.java index 476a2873b..ac2c89688 100644 --- a/src/sqlancer/voltdb/VoltDBConnection.java +++ b/src/sqlancer/voltdb/VoltDBConnection.java @@ -3,6 +3,8 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Proxy; +import java.nio.file.Files; +import java.nio.file.Path; import java.sql.CallableStatement; import java.sql.Connection; import java.sql.DatabaseMetaData; @@ -39,15 +41,32 @@ public class VoltDBConnection extends SQLConnection { private static final Pattern SELECT_PREAMBLE = Pattern.compile("^\\s*select\\s+.*", Pattern.CASE_INSENSITIVE | Pattern.DOTALL); + // ENG-30229: an OPS request (@SystemInformation, @SystemCatalog, @Statistics) sent while a host is joining or + // rejoining waits 60 s and fails ("OPS request hit sixty second timeout"), and while it waits every other one is + // refused ("Too many pending stat requests"). The driver's getMetaData() and DatabaseMetaData calls are such + // requests; they are retried for up to OPS_RETRY_MILLIS, which covers an elastic join (run-sqlancer.sh + // --resize-interval) or a rejoin. + private static final long OPS_RETRY_MILLIS = 150_000; + + // ENG-30622: a catalog update that drops a table while an elastic remove streams its index snapshot fails the + // snapshot ("No table streamer of Type TABLE_STREAM_ELASTIC_INDEX"), and the remove then waits forever at "Building + // index for data migration". run-sqlancer.sh creates the --ddl-hold file around each shrink; while it exists, DDL + // waits, for up to DDL_HOLD_MILLIS. + private static final Pattern DDL = Pattern.compile("^\\s*(create|drop|alter|partition)\\b.*", + Pattern.CASE_INSENSITIVE | Pattern.DOTALL); + private static final long DDL_HOLD_MILLIS = 900_000; + private final Connection connection; private final long retryMillis; private final boolean nodeFailures; private boolean closed; // the DIFF oracle's second cluster, running another VoltDB version (--mirror), or null; every statement that - // changes - // the database is repeated on it, and the database is marked diverged when the two disagree on whether it succeeded + // changes the database is repeated on it, and the database is marked diverged when the two disagree on whether it + // succeeded private VoltDBConnection mirror; private volatile boolean diverged; + // the --ddl-hold file, or null + private Path ddlHold; public VoltDBConnection(Connection connection, int retrySeconds, boolean nodeFailures) { super(connection); @@ -86,6 +105,22 @@ public void setMirror(VoltDBConnection mirror) { this.mirror = mirror; } + public void setDdlHold(Path ddlHold) { + this.ddlHold = ddlHold; + } + + // waits while the --ddl-hold file exists, if sql is DDL + private void holdDdl(Object... args) throws InterruptedException { + if (ddlHold == null || args == null || args.length != 1 || !(args[0] instanceof String) + || !DDL.matcher((String) args[0]).matches()) { + return; + } + long deadline = System.currentTimeMillis() + DDL_HOLD_MILLIS; + while (Files.exists(ddlHold) && System.currentTimeMillis() < deadline) { + Thread.sleep(200); + } + } + public VoltDBConnection getMirror() { return mirror; } @@ -119,28 +154,49 @@ private void mirrorWrite(Method method, Object[] args, boolean succeeded) { } } + private static boolean isOpsTimeout(Throwable t) { + String m = t instanceof SQLException ? t.getMessage() : null; + return m != null + && (m.contains("OPS request hit sixty second timeout") || m.contains("Too many pending stat requests")); + } + + private interface MetaDataCall { + T call() throws SQLException, InvocationTargetException, IllegalAccessException; + } + + private T opsRetrying(MetaDataCall call) throws Throwable { + long deadline = System.currentTimeMillis() + OPS_RETRY_MILLIS; + while (true) { + try { + return call.call(); + } catch (SQLException | InvocationTargetException e) { + Throwable cause = e instanceof InvocationTargetException ? e.getCause() : e; + if (isOpsTimeout(cause) && System.currentTimeMillis() < deadline) { + Thread.sleep(1000); + continue; + } + throw skippedIfNodeFailure(cause); + } + } + } + public DatabaseMetaData getMetaData() throws SQLException { DatabaseMetaData md; try { // the driver reads the cluster's system information here - md = connection.getMetaData(); - } catch (SQLException e) { - if (skippedIfNodeFailure(e) instanceof IgnoreMeException) { - throw new IgnoreMeException(); + md = opsRetrying(connection::getMetaData); + } catch (Throwable t) { + if (t instanceof SQLException) { + throw (SQLException) t; } - throw e; - } - if (!nodeFailures) { - return md; + if (t instanceof RuntimeException) { + throw (RuntimeException) t; + } + throw new SQLException(t); } return (DatabaseMetaData) Proxy.newProxyInstance(DatabaseMetaData.class.getClassLoader(), - new Class[] { DatabaseMetaData.class }, (proxy, method, args) -> { - try { - return method.invoke(md, args); - } catch (InvocationTargetException e) { - throw skippedIfNodeFailure(e.getCause()); - } - }); + new Class[] { DatabaseMetaData.class }, + (proxy, method, args) -> opsRetrying(() -> method.invoke(md, args))); } // an error a node failure caused, as IgnoreMeException while --node-failures is on, otherwise the error itself @@ -155,6 +211,9 @@ private Throwable skippedIfNodeFailure(Throwable t) { private T retrying(T statement, Class type) { return type .cast(Proxy.newProxyInstance(type.getClassLoader(), new Class[] { type }, (proxy, method, args) -> { + if (method.getName().startsWith("execute")) { + holdDdl(args); + } long deadline = System.currentTimeMillis() + retryMillis; while (true) { try { diff --git a/src/sqlancer/voltdb/VoltDBOptions.java b/src/sqlancer/voltdb/VoltDBOptions.java index b66c2b0db..bb1dbc517 100644 --- a/src/sqlancer/voltdb/VoltDBOptions.java +++ b/src/sqlancer/voltdb/VoltDBOptions.java @@ -41,6 +41,12 @@ public class VoltDBOptions implements DBMSSpecificOptions { @Parameter(names = "--node-failures", description = "Nodes are killed and rejoined during the run (run-sqlancer.sh --kill-interval): expect and retry the errors that causes", arity = 1) public boolean nodeFailures; + @Parameter(names = "--resizes", description = "The cluster grows and shrinks elastically during the run (run-sqlancer.sh --resize-interval): expect and retry the errors that hosts leaving the cluster cause, as for --node-failures", arity = 1) + public boolean resizes; + + @Parameter(names = "--ddl-hold", description = "A file that, while it exists, holds every DDL statement until it is gone (run-sqlancer.sh creates it during each shrink, ENG-30622); ignored with --avoid-known-bugs false") + public String ddlHold; + @Parameter(names = "--mirror", description = "Comma-separated host:port client addresses of a second cluster, normally running another VoltDB version: every statement that changes the database is repeated on it, and the DIFF oracle compares the two clusters' rows for the same query") public String mirror; diff --git a/src/sqlancer/voltdb/VoltDBProvider.java b/src/sqlancer/voltdb/VoltDBProvider.java index 30567163b..3796a254a 100644 --- a/src/sqlancer/voltdb/VoltDBProvider.java +++ b/src/sqlancer/voltdb/VoltDBProvider.java @@ -1,5 +1,6 @@ package sqlancer.voltdb; +import java.nio.file.Paths; import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.DriverManager; @@ -153,7 +154,14 @@ public SQLConnection createDatabase(VoltDBGlobalState globalState) throws Except String servers = globalState.getDbmsSpecificOptions().servers; String url = servers == null || servers.isBlank() ? String.format("jdbc:voltdb://%s:%d", host, port) : "jdbc:voltdb://" + servers.trim() + "?topologychangeaware=true"; - VoltDBConnection sqlCon = connect(globalState, url, globalState.getDbmsSpecificOptions().nodeFailures); + // a shrink (--resizes) removes hosts the driver is connected to (topologychangeaware), so the calls in flight + // on them fail as on a killed node; the oracles' --node-failures workarounds (ENG-30612) do not apply + VoltDBConnection sqlCon = connect(globalState, url, + globalState.getDbmsSpecificOptions().nodeFailures || globalState.getDbmsSpecificOptions().resizes); + String hold = globalState.getDbmsSpecificOptions().ddlHold; + if (hold != null && !hold.isBlank() && globalState.getDbmsSpecificOptions().avoidKnownBugs) { + sqlCon.setDdlHold(Paths.get(hold)); + } dropLeftovers(globalState, sqlCon, true); // DIFF (milestone 20): a second cluster, normally the last release, that every change is repeated on String mirror = globalState.getDbmsSpecificOptions().mirror; diff --git a/src/sqlancer/voltdb/gen/VoltDBIndexGenerator.java b/src/sqlancer/voltdb/gen/VoltDBIndexGenerator.java index beed70795..f4fc72d09 100644 --- a/src/sqlancer/voltdb/gen/VoltDBIndexGenerator.java +++ b/src/sqlancer/voltdb/gen/VoltDBIndexGenerator.java @@ -27,7 +27,12 @@ public static SQLQueryAdapter getQuery(VoltDBGlobalState globalState) { if (Randomly.getBooleanWithRatherLowProbability()) { boolean hasPartitionColumn = !table.isPartitioned() || columns.stream().anyMatch(c -> c.getName().equals(table.getPartitionColumn())); - sb.append(hasPartitionColumn ? "UNIQUE " : "ASSUMEUNIQUE "); + if (hasPartitionColumn) { + sb.append("UNIQUE "); + } else if (!globalState.getDbmsSpecificOptions().resizes) { + // no ASSUMEUNIQUE index while the cluster resizes (see VoltDBTableGenerator) + sb.append("ASSUMEUNIQUE "); + } } sb.append("INDEX ").append(globalState.getFreeIndexName()).append(" ON ").append(table.getName()).append(" (") .append(columns.stream().map(VoltDBColumn::getName).collect(Collectors.joining(", "))).append(')'); diff --git a/src/sqlancer/voltdb/gen/VoltDBTableGenerator.java b/src/sqlancer/voltdb/gen/VoltDBTableGenerator.java index 06430b57e..48bcdd16a 100644 --- a/src/sqlancer/voltdb/gen/VoltDBTableGenerator.java +++ b/src/sqlancer/voltdb/gen/VoltDBTableGenerator.java @@ -76,6 +76,13 @@ public static SQLQueryAdapter getQuery(VoltDBGlobalState globalState) { } List uniqueKey = Randomly.getBooleanWithRatherLowProbability() ? keyColumns(columns, partitionColumn, false) : null; + // ASSUMEUNIQUE holds only within a partition, so rows in two partitions can share its key; an elastic resize + // (--resizes) that moves one of them next to the other fails with "Found duplicates while rebalancing data + // across partitions" and retries for good, as VoltDB documents. The key is left out then. + if (uniqueKey != null && globalState.getDbmsSpecificOptions().resizes && partitionColumn != null + && !uniqueKey.contains(partitionColumn)) { + uniqueKey = null; + } StringBuilder sb = new StringBuilder("CREATE TABLE ").append(table).append(" ("); sb.append(columns.stream().map(c -> c.name + " " + c.type + (c.notNull ? " NOT NULL" : "")) diff --git a/voltdb/run-sqlancer.sh b/voltdb/run-sqlancer.sh index 3e8077946..e82799438 100755 --- a/voltdb/run-sqlancer.sh +++ b/voltdb/run-sqlancer.sh @@ -30,6 +30,9 @@ Usage: voltdb/run-sqlancer.sh --voltdb [options] [-- ] --use-reducer reduce each failure with SQLancer's statement reducer --kill-interval S every S seconds, kill a random node, node 0 included, with kill -9 and restart it, which rejoins it to the cluster (default 0: never). Needs --kfactor 1 or more. + --resize-interval S every S seconds, resize the cluster elastically, growing and shrinking by turns: add + k+1 nodes (voltdb start --add), then remove them (voltadmin resize) (default 0: never). + Not with --kill-interval. --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 @@ -68,6 +71,7 @@ results_root=$PWD/sqlancer-results use_reducer=false keep_cluster=false kill_interval=0 +resize_interval=0 mirror_home= mirror_license= mirror_java_home= @@ -91,6 +95,7 @@ while [ $# -gt 0 ]; do --use-reducer) use_reducer=true; shift ;; --keep-cluster) keep_cluster=true; shift ;; --kill-interval) kill_interval=$2; shift 2 ;; + --resize-interval) resize_interval=$2; shift 2 ;; --mirror-voltdb) mirror_home=$2; shift 2 ;; --mirror-license) mirror_license=$2; shift 2 ;; --mirror-java-home) mirror_java_home=$2; shift 2 ;; @@ -117,7 +122,7 @@ if [ -n "$mirror_home" ]; then mirror_license_args=(--license "$mirror_license") fi fi -for n in "$nodes" "$sites" "$duration" "$threads" "$queries" "$port_base" "$kill_interval"; do +for n in "$nodes" "$sites" "$duration" "$threads" "$queries" "$port_base" "$kill_interval" "$resize_interval"; do case $n in '' | *[!0-9]*) die "not a number: '$n'" ;; esac done [ "$nodes" -ge 1 ] || die "--nodes must be at least 1" @@ -126,6 +131,11 @@ if [ -z "$kfactor" ]; then fi [ "$kfactor" -lt "$nodes" ] || die "--kfactor must be less than --nodes" [ -n "$seed" ] || seed=$(date +%s) +[ "$kill_interval" -eq 0 ] || [ "$resize_interval" -eq 0 ] || die "--kill-interval and --resize-interval do not mix" +if [ "$resize_interval" -gt 0 ]; then + # a shrink drops the calls in flight on the hosts it removes, which the provider then expects (see VoltDBErrors) + provider_args=(--resizes true ${provider_args[@]+"${provider_args[@]}"}) +fi if [ "$kill_interval" -gt 0 ]; then [ "$kfactor" -ge 1 ] || die "--kill-interval needs --kfactor 1 or more" # the provider expects the errors a node failure causes (see VoltDBErrors) @@ -164,9 +174,12 @@ internal_port() { port "$1" 2; } port_in_use() { (exec 3<>"/dev/tcp/127.0.0.1/$1") 2>/dev/null; } -# the mirror, if any, takes the port slot after the last node's -for ((i = 0; i < nodes + 1; i++)); do - [ "$i" -eq "$nodes" ] && [ -z "$mirror_home" ] && break +# the mirror, if any, takes the port slot after the last node's; the k+1 nodes a resize adds take the slots after that +added=0 +[ "$resize_interval" -gt 0 ] && added=$((kfactor + 1)) +added_slot=$((nodes + 1)) +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 p=$(port $i $j) port_in_use "$p" && die "port $p is in use; pick another --port-base" @@ -178,6 +191,10 @@ results=$results_root/$run_id cluster=$results/cluster mkdir -p "$cluster" "$results/sqlancer" "$results/servers" "$results/reproductions" || die "cannot create $results" results=$(cd "$results" && pwd) +if [ "$resize_interval" -gt 0 ]; then + # DDL waits while this file exists, which shrink creates (the provider ignores it with --avoid-known-bugs false) + provider_args+=(--ddl-hold "$results/ddl.hold") +fi cluster=$results/cluster log() { echo "[$(date '+%H:%M:%S')] $*" | tee -a "$results/run.log"; } @@ -231,7 +248,7 @@ stop_cluster() { sleep 1 done pkill -f "$cluster/" 2>/dev/null - for f in "$cluster"/node*.pid "$cluster"/mirror.pid; do + for f in "$cluster"/node*.pid "$cluster"/add*.pid "$cluster"/mirror.pid; do [ -e "$f" ] && is_server "$(cat "$f")" && kill -9 "$(cat "$f")" 2>/dev/null done } @@ -277,6 +294,7 @@ sqlancer_dirty=$(git -C "$repo_dir" status --porcelain 2>/dev/null | grep -v '^? echo "queries per db: $queries" echo "use reducer: $use_reducer" echo "kill interval: $([ "$kill_interval" -gt 0 ] && echo "$kill_interval s" || echo never)" + echo "resize interval: $([ "$resize_interval" -gt 0 ] && echo "$resize_interval s, $added nodes added and removed by turns" || echo never)" echo "provider options: ${provider_args[*]:-}" } >"$results/manifest.txt" cat "$results/manifest.txt" @@ -442,6 +460,151 @@ if [ "$kill_interval" -gt 0 ]; then log "Killing and rejoining a random node every $kill_interval s (chaos.log)" fi +# Every resize_interval seconds, by turns: grow the cluster by k+1 nodes, then shrink it by the same nodes. A grow +# starts them with "voltdb start --add" in their own directories ($cluster/add-, kept for their logs) and waits +# until they have joined and until "voltadmin resize --test" would remove them: VoltDB publishes the new topology some +# seconds after the join (40 s in a trial), and a shrink planned before then would remove the original nodes, which it +# refuses as more than half the cluster. A shrink runs "voltadmin resize", which removes the partition group with +# the highest partition ids, those the last grow added, and waits until their servers exit. Each step has 600 s; one +# that fails or times out ends the loop and fails the run. Each event is a line of resize.log. The loop stops when +# $results/resize.stop exists, after its step, so the run ends at a settled size. +grows=0 +shrinks=0 +resize_hosts() { + "$voltdb_home/bin/voltadmin" resize --test -H "localhost:$(admin_port 0)" 2>&1 | tail -1 +} +# start_added N: starts the k+1 nodes of grow N, each initialized afresh in $cluster/add- +start_added() { + local n=$1 j slot dir + for ((j = 0; j < added; j++)); do + slot=$((added_slot + j)) + dir=$cluster/add$n-$j + "$voltdb_home/bin/voltdb" init --force -D "$dir" -C "$cluster/deployment.xml" \ + ${license_args[@]+"${license_args[@]}"} >"$dir.init.log" 2>&1 || return 1 + (nohup "$voltdb_home/bin/voltdb" start --add -D "$dir" -H "$(hosts internal)" \ + --client="$(client_port $slot)" --admin="$(admin_port $slot)" --internal="$(internal_port $slot)" \ + --zookeeper="$(port $slot 3)" --replication="$(port $slot 4)" --metrics="$(port $slot 5)" \ + >"$dir.start.log" 2>&1 & + echo $! >"$dir.pid") + done +} +# grow N: adds k+1 nodes and waits until the cluster would remove them again. VoltDB rejects a join while a catalog +# update is in progress, and SQLancer's DDL makes one likely: the joining nodes then exit with a FATAL line. Such an +# attempt is set aside (its directories renamed add--rejected, whose FATAL lines are not counted) and tried +# again 5 s later, up to 10 times. +grow() { + local n=$1 j attempt deadline=$((SECONDS + 600)) ready out rejected originals + for attempt in 1 2 3 4 5 6 7 8 9 10; do + start_added $n || return 1 + rejected=false + while [ $SECONDS -lt $deadline ]; do + ready=0 + for ((j = 0; j < added; j++)); do + grep -q "Server completed initialization" "$cluster/add$n-$j.start.log" 2>/dev/null && ready=$((ready + 1)) + grep -q "Can't do elastic join while catalog update is in progress" "$cluster/add$n-$j.start.log" 2>/dev/null && + rejected=true + done + [ "$ready" -eq "$added" ] || $rejected && break + # kill -0, not is_server: the PID is the launcher's until it execs the server's JVM + for ((j = 0; j < added; j++)); do + kill -0 "$(cat "$cluster/add$n-$j.pid")" 2>/dev/null && continue + # exited: a rejected join (its log may have been read just before the line was written), or a failure + sleep 1 + grep -q "Can't do elastic join while catalog update is in progress" "$cluster/add$n-$j.start.log" || return 1 + rejected=true + done + $rejected && break + sleep 1 + done + $rejected || break + echo "$(date '+%H:%M:%S') grow $n: join rejected while a catalog update was in progress (attempt $attempt), retrying" >>"$results/resize.log" + for ((j = 0; j < added; j++)); do + kill -9 "$(cat "$cluster/add$n-$j.pid")" 2>/dev/null + done + sleep 5 + for ((j = 0; j < added; j++)); do + for f in "" .init.log .start.log .pid; do + mv "$cluster/add$n-$j$f" "$cluster/add$n-$j-rejected$attempt$f" 2>/dev/null + done + done + [ $SECONDS -lt $deadline ] || return 1 + done + $rejected && return 1 + [ "$ready" -eq "$added" ] || return 1 + # the original nodes are hosts 0 to nodes-1: done once the planned removal names none of them (paste, not + # seq -s, as BSD seq ends the list with the separator, which makes an empty alternative) + originals=$(seq 0 $((nodes - 1)) | paste -sd '|' -) + while [ $SECONDS -lt $deadline ]; do + out=$(resize_hosts) + if echo "$out" | grep -q "Host Ids: \[" && ! echo "$out" | grep -qE "Host Ids: \[(.*[ ,\[])?($originals)[],]"; then + echo "$(date '+%H:%M:%S') grow $n: planned removal: ${out#INFO: }" >>"$results/resize.log" + return 0 + fi + sleep 5 + done + return 1 +} +# ENG-30622: a table dropped while an elastic remove streams its index snapshot hangs the remove for good, so DDL is +# held (the provider's --ddl-hold) from a few seconds before the shrink, letting a catalog update in flight finish, +# until it is done +shrink() { + local rc=0 + touch "$results/ddl.hold" + sleep 3 + shrink_steps "$1" || rc=1 + rm -f "$results/ddl.hold" + return $rc +} +shrink_steps() { + local n=$1 j alive deadline=$((SECONDS + 600)) out + out=$("$voltdb_home/bin/voltadmin" resize -H "localhost:$(admin_port 0)" 2>&1 | tail -1) + echo "$(date '+%H:%M:%S') shrink $n: $out" >>"$results/resize.log" + echo "$out" | grep -q "^INFO" || return 1 + while [ $SECONDS -lt $deadline ]; do + alive=0 + for ((j = 0; j < added; j++)); do + is_server "$(cat "$cluster/add$n-$j.pid")" && alive=$((alive + 1)) + done + [ "$alive" -eq 0 ] && return 0 + sleep 1 + done + return 1 +} +resize_loop() { + local n=0 t0 + while true; do + for _ in $(seq 1 "$resize_interval"); do + [ -e "$results/resize.stop" ] && return 0 + sleep 1 + done + n=$((n + 1)) + t0=$SECONDS + echo "$(date '+%H:%M:%S') grow $n: adding $added node(s)" >>"$results/resize.log" + if ! grow $n; then + echo "$(date '+%H:%M:%S') grow $n: FAILED after $((SECONDS - t0)) s" >>"$results/resize.log" + return 1 + fi + echo "$(date '+%H:%M:%S') grow $n: done, $((SECONDS - t0)) s" >>"$results/resize.log" + for _ in $(seq 1 "$resize_interval"); do + [ -e "$results/resize.stop" ] && return 0 + sleep 1 + done + t0=$SECONDS + if ! shrink $n; then + echo "$(date '+%H:%M:%S') shrink $n: FAILED after $((SECONDS - t0)) s" >>"$results/resize.log" + return 1 + fi + echo "$(date '+%H:%M:%S') shrink $n: done, $((SECONDS - t0)) s" >>"$results/resize.log" + done +} +resize_pid= +if [ "$resize_interval" -gt 0 ]; then + : >"$results/resize.log" + resize_loop & + resize_pid=$! + log "Growing and shrinking the cluster by $added node(s) by turns, every $resize_interval s (resize.log)" +fi + log "Running SQLancer for $duration s: oracles $oracles, seed $seed, $threads threads" # in the background, so that an interrupt runs the trap at once instead of after SQLancer finishes (cd "$results/sqlancer" && exec "$java" -jar "$jar" "${sqlancer_args[@]}" voltdb --oracle "$oracles" \ @@ -462,6 +625,14 @@ if [ -n "$chaos_pid" ]; then rejoins=$(grep -c " rejoin [0-9]*: node[0-9]*, " "$results/chaos.log") log "Node failures: $kills kills, $rejoins rejoins$($chaos_failed && echo ", the last one FAILED")" fi +resize_failed=false +if [ -n "$resize_pid" ]; then + touch "$results/resize.stop" + wait "$resize_pid" || resize_failed=true + grows=$(grep -c " grow [0-9]*: done" "$results/resize.log") + shrinks=$(grep -c " shrink [0-9]*: done" "$results/resize.log") + log "Resizes: $grows grows, $shrinks shrinks$($resize_failed && echo ", the last step FAILED")" +fi # --- collect ----------------------------------------------------------------------------------------------------- @@ -475,6 +646,13 @@ for ((i = 0; i < nodes; i++)); do cp "$cluster/start$i.log" "$cluster/init$i.log" "$cluster"/restart$i-*.log "$results/servers/node$i/" 2>/dev/null cp -R "$cluster/node$i/voltdbroot/log/." "$results/servers/node$i/" 2>/dev/null done +for d in "$cluster"/add*-*; do + [ -d "$d" ] || continue + a=$(basename "$d") + mkdir -p "$results/servers/$a" + cp "$d.init.log" "$d.start.log" "$results/servers/$a/" 2>/dev/null + cp -R "$d/voltdbroot/log/." "$results/servers/$a/" 2>/dev/null +done if [ -n "$mirror_home" ]; then mkdir -p "$results/servers/mirror" cp "$cluster/start-mirror.log" "$cluster/init-mirror.log" "$results/servers/mirror/" 2>/dev/null @@ -503,12 +681,17 @@ for ((i = 0; i < nodes; i++)); do END { print c + 0 }' "$results/servers/node$i/volt.log" 2>/dev/null) fatal=$((fatal + ${n:-0})) done +for f in "$results"/servers/add*-*/volt.log; do + [ -e "$f" ] || continue + case $f in *-rejected*) continue ;; esac + fatal=$((fatal + $(grep -c " FATAL " "$f"))) +done # --- summary ----------------------------------------------------------------------------------------------------- result=PASS [ "$sqlancer_exit" -eq 0 ] && [ ${#failures[@]} -eq 0 ] && [ ${#down[@]} -eq 0 ] && [ "$fatal" -eq 0 ] && - ! $chaos_failed || result=FAIL + ! $chaos_failed && ! $resize_failed || result=FAIL { echo "RESULT: $result" echo "run: $run_id" @@ -520,6 +703,7 @@ result=PASS # ENG-30602: failures that did not recur when rerun at once (VoltDBTransientCheck), counted, not failed 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)")" + [ "$resize_interval" -gt 0 ] && echo "resizes: $grows grows, $shrinks shrinks$($resize_failed && echo ", a step FAILED (resize.log)")" for f in ${failures[@]+"${failures[@]}"}; do echo echo "== reproductions/$(basename "$f")"