From 7a6feb6eec53a50a2aff1b2c55ce2b14b76bf9f9 Mon Sep 17 00:00:00 2001
From: psudheer21
Date: Tue, 10 Nov 2020 17:04:39 -0800
Subject: [PATCH] When loading partial data don't create SQL procedures. (#61)
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
---
src/com/oltpbenchmark/DBWorkload.java | 2 ++
.../oltpbenchmark/WorkloadConfiguration.java | 8 +++++
.../benchmarks/tpcc/TPCCBenchmark.java | 31 ++++++++++++++++--
.../benchmarks/tpcc/TPCCLoader.java | 32 -------------------
4 files changed, 39 insertions(+), 34 deletions(-)
diff --git a/src/com/oltpbenchmark/DBWorkload.java b/src/com/oltpbenchmark/DBWorkload.java
index b3f7414..eab7462 100644
--- a/src/com/oltpbenchmark/DBWorkload.java
+++ b/src/com/oltpbenchmark/DBWorkload.java
@@ -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")) {
@@ -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);
}
diff --git a/src/com/oltpbenchmark/WorkloadConfiguration.java b/src/com/oltpbenchmark/WorkloadConfiguration.java
index fc8a4a3..4908e9b 100644
--- a/src/com/oltpbenchmark/WorkloadConfiguration.java
+++ b/src/com/oltpbenchmark/WorkloadConfiguration.java
@@ -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;
@@ -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;
}
diff --git a/src/com/oltpbenchmark/benchmarks/tpcc/TPCCBenchmark.java b/src/com/oltpbenchmark/benchmarks/tpcc/TPCCBenchmark.java
index 5d572ae..75e1a08 100644
--- a/src/com/oltpbenchmark/benchmarks/tpcc/TPCCBenchmark.java
+++ b/src/com/oltpbenchmark/benchmarks/tpcc/TPCCBenchmark.java
@@ -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;
@@ -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 {
diff --git a/src/com/oltpbenchmark/benchmarks/tpcc/TPCCLoader.java b/src/com/oltpbenchmark/benchmarks/tpcc/TPCCLoader.java
index 33d4c54..d78db2d 100644
--- a/src/com/oltpbenchmark/benchmarks/tpcc/TPCCLoader.java
+++ b/src/com/oltpbenchmark/benchmarks/tpcc/TPCCLoader.java
@@ -132,9 +132,6 @@ public void load(Connection conn) throws SQLException {
workConf.getShouldEnableForeignKeys()) {
EnableForeignKeyConstraints(conn);
}
- if (workConf.getUseStoredProcedures()) {
- CreateSqlProcedures(conn);
- }
}
});
return (threads);
@@ -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;