Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 47 additions & 2 deletions src/sqlancer/voltdb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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:<its client port>`, 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<n>_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 |
Expand Down Expand Up @@ -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 |
Expand Down
112 changes: 93 additions & 19 deletions src/sqlancer/voltdb/oracle/VoltDBStreamOracle.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
public class VoltDBStreamOracle implements TestOracle<VoltDBGlobalState> {

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
Expand All @@ -44,17 +50,30 @@ public class VoltDBStreamOracle implements TestOracle<VoltDBGlobalState> {
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<String> 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<String, Integer> 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;
Expand All @@ -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");
Expand All @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -211,6 +284,7 @@ private boolean insert(String sql) {
st.execute(sql);
return true;
} catch (SQLException e) {
lastError = e.getMessage();
return false;
}
}
Expand Down
Loading