Skip to content

Commit

Permalink
Merge branch 'main' into use-threadlocalrandom
Browse files Browse the repository at this point in the history
  • Loading branch information
bpkroth authored Dec 5, 2023
2 parents ddf67c0 + ba2ac51 commit 9c710a4
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 15 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
uses: actions/checkout@v4

- name: Set up JDK
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: ${{env.JAVA_VERSION}}
cache: 'maven'
Expand All @@ -64,7 +64,7 @@ jobs:
uses: actions/checkout@v4

- name: Set up JDK
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: ${{env.JAVA_VERSION}}
cache: 'maven'
Expand Down Expand Up @@ -105,7 +105,7 @@ jobs:
rm -rf benchbase-sqlite.tgz
- name: Set up JDK
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: ${{env.JAVA_VERSION}}
distribution: 'temurin'
Expand Down Expand Up @@ -175,7 +175,7 @@ jobs:
rm -rf benchbase-mariadb.tgz
- name: Set up JDK
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: ${{env.JAVA_VERSION}}
distribution: 'temurin'
Expand Down Expand Up @@ -243,7 +243,7 @@ jobs:
rm -rf benchbase-mysql.tgz
- name: Set up JDK
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: ${{env.JAVA_VERSION}}
distribution: 'temurin'
Expand Down Expand Up @@ -310,7 +310,7 @@ jobs:
rm -rf benchbase-postgres.tgz
- name: Set up JDK
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: ${{env.JAVA_VERSION}}
distribution: 'temurin'
Expand Down Expand Up @@ -370,7 +370,7 @@ jobs:
rm -rf benchbase-cockroachdb.tgz
- name: Set up JDK
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: ${{env.JAVA_VERSION}}
distribution: 'temurin'
Expand Down Expand Up @@ -427,7 +427,7 @@ jobs:
rm -rf benchbase-sqlserver.tgz
- name: Set up JDK
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: ${{env.JAVA_VERSION}}
distribution: 'temurin'
Expand Down
3 changes: 2 additions & 1 deletion CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@
We also acknowledge contributions from the following collaborators:

+ [Florian Funke](http://www3.in.tum.de/~funkef/)
+ [Michael Seibold](http://www3.in.tum.de/~seibold/)
+ [Michael Seibold](http://www3.in.tum.de/~seibold/)
+ [Oracle](https://github.com/oracle) (Copyright (c) 2023, Oracle and/or its affiliates.)
7 changes: 6 additions & 1 deletion src/main/java/com/oltpbenchmark/DBWorkload.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ public static void main(String[] args) throws Exception {
postExecutionWait = xmlConfig.getLong(key + "/postExecutionWait");
}

// After load
if (xmlConfig.containsKey("afterload")) {
bench.setAfterLoadScriptPath(xmlConfig.getString("afterload"));
}

TransactionType tmpType = bench.initTransactionType(txnName, txnId + txnIdOffset, preExecutionWait, postExecutionWait);

// Keep a reference for filtering
Expand Down Expand Up @@ -626,7 +631,7 @@ private static void runCreator(BenchmarkModule bench) throws SQLException, IOExc
bench.createDatabase();
}

private static void runLoader(BenchmarkModule bench) throws SQLException, InterruptedException {
private static void runLoader(BenchmarkModule bench) throws IOException, SQLException, InterruptedException {
LOG.debug(String.format("Loading %s Database", bench));
bench.loadDatabase();
}
Expand Down
26 changes: 25 additions & 1 deletion src/main/java/com/oltpbenchmark/api/BenchmarkModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ public final Connection makeConnection() throws SQLException {
}
}

private String afterLoadScriptPath = null;

public final void setAfterLoadScriptPath(String scriptPath) {
this.afterLoadScriptPath = scriptPath;
}

public String getAfterLoadScriptPath() {
return this.afterLoadScriptPath;
}

// --------------------------------------------------------------------------
// IMPLEMENTING CLASS INTERFACE
// --------------------------------------------------------------------------
Expand Down Expand Up @@ -248,11 +258,19 @@ public final void createDatabase(DatabaseType dbType, Connection conn) throws SQ
}
}

public final void runScript(String scriptPath) throws SQLException, IOException {
try (Connection conn = this.makeConnection()) {
DatabaseType dbType = this.workConf.getDatabaseType();
ScriptRunner runner = new ScriptRunner(conn, true, true);
LOG.debug("Executing script [{}] for database type [{}]", scriptPath, dbType);
runner.runScript(scriptPath);
}
}

/**
* Invoke this benchmark's database loader
*/
public final Loader<? extends BenchmarkModule> loadDatabase() throws SQLException, InterruptedException {
public final Loader<? extends BenchmarkModule> loadDatabase() throws IOException, SQLException, InterruptedException {
Loader<? extends BenchmarkModule> loader;

loader = this.makeLoaderImpl();
Expand All @@ -275,6 +293,12 @@ public final Loader<? extends BenchmarkModule> loadDatabase() throws SQLExceptio
}
}

if (this.afterLoadScriptPath != null) {
LOG.debug("Running script after load for {} benchmark...", this.workConf.getBenchmarkName().toUpperCase());
runScript(this.afterLoadScriptPath);
LOG.debug("Finished running script after load for {} benchmark...", this.workConf.getBenchmarkName().toUpperCase());
}

return loader;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public List<Object[]> run(Connection conn, int source_id, int session_low, int s
finalResults.add(arr);
}
}
stmt.close();

return (finalResults);
}

Expand Down
29 changes: 25 additions & 4 deletions src/test/java/com/oltpbenchmark/api/AbstractTestLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@

package com.oltpbenchmark.api;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import com.oltpbenchmark.catalog.Table;
import com.oltpbenchmark.util.Histogram;
import com.oltpbenchmark.util.SQLUtil;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;

import static org.junit.Assert.*;
import static org.junit.Assert.fail;

public abstract class AbstractTestLoader<T extends BenchmarkModule> extends AbstractTestCase<T> {

private static final Logger LOG = LoggerFactory.getLogger(AbstractTestLoader.class);
Expand All @@ -58,6 +58,27 @@ public void testLoad() throws Exception {

}

/**
* testLoad with after load script
*/
@Test
public void testLoadWithAfterLoad() throws Exception {
this.benchmark.setAfterLoadScriptPath("/after-load.sql");

this.benchmark.loadDatabase();

// A table called extra is added with after-load, with one entry zero
try (PreparedStatement stmt = conn.prepareStatement("SELECT * FROM extra"); ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
assertEquals("Table 'extra' from after-load.sql has value different than 0", rs.getInt(1), 0);
}
} catch (Exception e) {
fail("Table 'extra' from after-load.sql was not created");
}

validateLoad();
}

private void validateLoad() throws SQLException {
assertFalse("Failed to get table names for " + benchmark.getBenchmarkName().toUpperCase(), this.catalog.getTables().isEmpty());

Expand Down
8 changes: 8 additions & 0 deletions src/test/resources/after-load.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
DROP TABLE IF EXISTS extra CASCADE;

CREATE TABLE extra (
extra_pk int NOT NULL,
PRIMARY KEY (extra_pk)
);

INSERT INTO extra VALUES (0);

0 comments on commit 9c710a4

Please sign in to comment.