Skip to content

Commit

Permalink
When loading partial data don't create SQL procedures. (#61)
Browse files Browse the repository at this point in the history
We load partial data through a client when we use multiple clients to
run the workload. Creation of SQL procedures when data load is happening
causes mismatch of the Catalog version.
Prevent the creation of the procedures in this case.

Reviewers:
Mihnea
  • Loading branch information
psudheer21 authored Nov 11, 2020
1 parent eddd12e commit 7a6feb6
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 34 deletions.
2 changes: 2 additions & 0 deletions src/com/oltpbenchmark/DBWorkload.java
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ public static void main(String[] args) throws Exception {
}
if (argsLine.hasOption("start-warehouse-id")) {
wrkld.setShouldEnableForeignKeys(false);
wrkld.setCreateSQLProcedures(false);
}

if (xmlConfig.containsKey("batchSize")) {
Expand Down Expand Up @@ -655,6 +656,7 @@ else if (serial)
for (BenchmarkModule benchmark : benchList) {
LOG.info("Creating new " + benchmark.getBenchmarkName().toUpperCase() + " database...");
runCreator(benchmark, verbose);
benchmark.createSqlProcedures();
LOG.info("Finished!");
LOG.info(SINGLE_LINE);
}
Expand Down
8 changes: 8 additions & 0 deletions src/com/oltpbenchmark/WorkloadConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public void setBenchmarkName(String benchmarkName) {
private boolean useThinkTime = true;
private boolean enableForeignKeysAfterLoad = true;
private boolean shouldEnableForeignKeys = true;
private boolean createSQLProcedures = true;
private int batchSize = 128;
private int hikariConnectionTimeout = 60000;
private boolean needsExecution = false;
Expand Down Expand Up @@ -366,6 +367,13 @@ public void setShouldEnableForeignKeys(boolean shouldEnableForeignKeys) {
this.shouldEnableForeignKeys = shouldEnableForeignKeys;
}

public boolean getCreateSQLProcedures() {
return createSQLProcedures;
}
public void setCreateSQLProcedures(boolean createSQLProcedures) {
this.createSQLProcedures = createSQLProcedures;
}

public int getBatchSize() {
return batchSize;
}
Expand Down
31 changes: 29 additions & 2 deletions src/com/oltpbenchmark/benchmarks/tpcc/TPCCBenchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.Statement;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
Expand Down Expand Up @@ -162,9 +164,34 @@ public void enableForeignKeys() throws Exception {
loader.EnableForeignKeyConstraints(makeConnection());
}

// This function creates SQL procedures that the execution would need. Currently we have
// procedures only to update the Stock table.
public void createSqlProcedures() throws Exception {
TPCCLoader loader = new TPCCLoader(this);
loader.CreateSqlProcedures(makeConnection());
try {
Connection conn = makeConnection();
Statement st = conn.createStatement();

StringBuilder argsSb = new StringBuilder();
StringBuilder updateStatements = new StringBuilder();

argsSb.append("wid int");
for (int i = 1; i <= 15; ++i) {
argsSb.append(String.format(", i%d int, q%d int, y%d int, r%d int", i, i, i, i));
updateStatements.append(String.format(
"UPDATE STOCK SET S_QUANTITY = q%d, S_YTD = y%d, S_ORDER_CNT = S_ORDER_CNT + 1, " +
"S_REMOTE_CNT = r%d WHERE S_W_ID = wid AND S_I_ID = i%d;",
i, i, i, i));
String updateStmt =
String.format("CREATE PROCEDURE updatestock%d (%s) AS '%s' LANGUAGE SQL;",
i, argsSb.toString(), updateStatements.toString());

st.execute(String.format("DROP PROCEDURE IF EXISTS updatestock%d", i));
st.execute(updateStmt);
}
} catch (SQLException se) {
LOG.error(se.getMessage());
throw se;
}
}

public void test() throws Exception {
Expand Down
32 changes: 0 additions & 32 deletions src/com/oltpbenchmark/benchmarks/tpcc/TPCCLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,6 @@ public void load(Connection conn) throws SQLException {
workConf.getShouldEnableForeignKeys()) {
EnableForeignKeyConstraints(conn);
}
if (workConf.getUseStoredProcedures()) {
CreateSqlProcedures(conn);
}
}
});
return (threads);
Expand Down Expand Up @@ -215,35 +212,6 @@ protected void EnableForeignKeyConstraints(Connection conn) {
}
}

// This function creates SQL procedures that the execution would need. Currently we have
// procedures only to update the Stock table.
protected void CreateSqlProcedures(Connection conn) throws SQLException {
try {
Statement st = conn.createStatement();

StringBuilder argsSb = new StringBuilder();
StringBuilder updateStatements = new StringBuilder();

argsSb.append("wid int");
for (int i = 1; i <= 15; ++i) {
argsSb.append(String.format(", i%d int, q%d int, y%d int, r%d int", i, i, i, i));
updateStatements.append(String.format(
"UPDATE STOCK SET S_QUANTITY = q%d, S_YTD = y%d, S_ORDER_CNT = S_ORDER_CNT + 1, " +
"S_REMOTE_CNT = r%d WHERE S_W_ID = wid AND S_I_ID = i%d;",
i, i, i, i));
String updateStmt =
String.format("CREATE PROCEDURE updatestock%d (%s) AS '%s' LANGUAGE SQL;",
i, argsSb.toString(), updateStatements.toString());

st.execute(String.format("DROP PROCEDURE IF EXISTS updatestock%d", i));
st.execute(updateStmt);
}
} catch (SQLException se) {
LOG.error(se.getMessage());
throw se;
}
}

protected int loadItems(Connection conn, int itemKount) {
int k = 0;
int randPct = 0;
Expand Down

0 comments on commit 7a6feb6

Please sign in to comment.