Skip to content

Commit

Permalink
Add configuration to read external ddl script
Browse files Browse the repository at this point in the history
This commit adds a configuration option to the xml configuration files
that specifies a path to a ddl script. If the configuration option is
specified then that ddl script will be used instead of the default
script for the benchmark and database.

This could be useful for selecting between a row store and column store
layout or other alternative indexing options.

The xml tag is 'ddlpath'.

Resolves cmu-db#153
  • Loading branch information
jkosh44 committed Apr 25, 2022
1 parent 72f7d02 commit d858fd6
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/oltpbenchmark/DBWorkload.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ public static void main(String[] args) throws Exception {
wrkld.setIsolationMode(xmlConfig.getString("isolation" + pluginTest, isolationMode));
wrkld.setScaleFactor(xmlConfig.getDouble("scalefactor", 1.0));
wrkld.setDataDir(xmlConfig.getString("datadir", "."));
wrkld.setDdlPath(xmlConfig.getString("ddlpath", null));

double selectivity = -1;
try {
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/oltpbenchmark/WorkloadConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class WorkloadConfiguration {
private TransactionTypes transTypes = null;
private int isolationMode = Connection.TRANSACTION_SERIALIZABLE;
private String dataDir = null;
private String ddlPath = null;

public String getBenchmarkName() {
return benchmarkName;
Expand Down Expand Up @@ -210,6 +211,20 @@ public void setDataDir(String dir) {
this.dataDir = dir;
}

/**
* Return the path in which we can find the ddl script.
*/
public String getDdlPath() {
return this.ddlPath;
}

/**
* Set the path in which we can find the ddl script.
*/
public void setDdlPath(String ddlPath) {
this.ddlPath = ddlPath;
}

/**
* A utility method that init the phaseIterator and dialectMap
*/
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/com/oltpbenchmark/api/BenchmarkModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,15 +221,17 @@ public final void createDatabase() throws SQLException, IOException {
*/
public final void createDatabase(DatabaseType dbType, Connection conn) throws SQLException, IOException {

String ddlPath = this.getDatabaseDDLPath(dbType);
ScriptRunner runner = new ScriptRunner(conn, true, true);

if (LOG.isDebugEnabled()) {
if (workConf.getDdlPath() != null) {
String ddlPath = workConf.getDdlPath();
LOG.debug("Executing script [{}] for database type [{}]", ddlPath, dbType);
runner.runExternalScript(ddlPath);
} else {
String ddlPath = this.getDatabaseDDLPath(dbType);
LOG.debug("Executing script [{}] for database type [{}]", ddlPath, dbType);
runner.runScript(ddlPath);
}

runner.runScript(ddlPath);

}


Expand Down
30 changes: 22 additions & 8 deletions src/main/java/com/oltpbenchmark/util/ScriptRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,37 @@ public ScriptRunner(Connection connection, boolean autoCommit, boolean stopOnErr
}


public void runExternalScript(String path) throws IOException, SQLException {

LOG.debug("trying to find external file by path {}", path);

try (FileReader reader = new FileReader(path)) {

runScript(reader);
}
}

public void runScript(String path) throws IOException, SQLException {

LOG.debug("trying to find file by path {}", path);

try (InputStream in = this.getClass().getResourceAsStream(path);
Reader reader = new InputStreamReader(in)) {

boolean originalAutoCommit = connection.getAutoCommit();
runScript(reader);
}
}

try {
if (originalAutoCommit != this.autoCommit) {
connection.setAutoCommit(this.autoCommit);
}
runScript(connection, reader);
} finally {
connection.setAutoCommit(originalAutoCommit);
private void runScript(Reader reader) throws IOException, SQLException {
boolean originalAutoCommit = connection.getAutoCommit();

try {
if (originalAutoCommit != this.autoCommit) {
connection.setAutoCommit(this.autoCommit);
}
runScript(connection, reader);
} finally {
connection.setAutoCommit(originalAutoCommit);
}
}

Expand Down

0 comments on commit d858fd6

Please sign in to comment.