Skip to content
Merged
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
12 changes: 12 additions & 0 deletions src/sqlancer/materialize/MaterializeBugs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package sqlancer.materialize;

// do not make the fields final to avoid warnings
public final class MaterializeBugs {

// Tables or columns may be missing when reading information_schema shortly after creation
public static boolean bugSchemaReadIncomplete = true;

private MaterializeBugs() {
}

}
27 changes: 27 additions & 0 deletions src/sqlancer/materialize/MaterializeGlobalState.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class MaterializeGlobalState extends SQLGlobalState<MaterializeOptions, M
// store and allow filtering by function volatility classifications
private final Map<String, Character> functionsAndTypes = new HashMap<>();
private List<Character> allowedFunctionTypes = Arrays.asList(IMMUTABLE, STABLE, VOLATILE);
private int lastKnownTableCount;
private int readSchemaCallCount;

@Override
public void setConnection(SQLConnection con) {
Expand Down Expand Up @@ -266,6 +268,31 @@ public String getRandomTableAccessMethod() {

@Override
public MaterializeSchema readSchema() throws SQLException {
if (MaterializeBugs.bugSchemaReadIncomplete) {
// Workaround for a suspected Materialize bug where tables or columns may be
// missing when reading the schema; retry until stable.
readSchemaCallCount++;
for (int tries = 0; tries < 30; tries++) {
MaterializeSchema schema = MaterializeSchema.fromConnection(getConnection(), getDatabaseName());
boolean hasTableWithEmptyColumns = schema.getDatabaseTables().stream()
.anyMatch(t -> t.getColumns().isEmpty());
boolean tableCountRegressed = schema.getDatabaseTables().size() < lastKnownTableCount;
boolean suspiciouslyEmpty = readSchemaCallCount > 1 && schema.getDatabaseTables().isEmpty();
if (!hasTableWithEmptyColumns && !tableCountRegressed && !suspiciouslyEmpty) {
lastKnownTableCount = schema.getDatabaseTables().size();
return schema;
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
break;
}
}
MaterializeSchema schema = MaterializeSchema.fromConnection(getConnection(), getDatabaseName());
lastKnownTableCount = schema.getDatabaseTables().size();
return schema;
}
return MaterializeSchema.fromConnection(getConnection(), getDatabaseName());
}

Expand Down
Loading