From 5d4bcb92a9a8505d57cace0bc718e6f064189a07 Mon Sep 17 00:00:00 2001 From: Rana Alotaibi Date: Mon, 11 Dec 2023 20:48:35 -0800 Subject: [PATCH 1/3] Introduce session setup --- config/sqlserver/sample_tpch_config.xml | 2 ++ .../session_setup_sqlserver_cmds_example.sql | 3 ++ .../java/com/oltpbenchmark/DBWorkload.java | 2 ++ .../oltpbenchmark/WorkloadConfiguration.java | 11 ++++++ .../java/com/oltpbenchmark/api/Worker.java | 35 +++++++++++++++++++ 5 files changed, 53 insertions(+) create mode 100644 data/session-setup-files/session_setup_sqlserver_cmds_example.sql diff --git a/config/sqlserver/sample_tpch_config.xml b/config/sqlserver/sample_tpch_config.xml index 153ba83de..6f49887c0 100644 --- a/config/sqlserver/sample_tpch_config.xml +++ b/config/sqlserver/sample_tpch_config.xml @@ -10,6 +10,8 @@ true TRANSACTION_SERIALIZABLE 1024 + + 0.1 diff --git a/data/session-setup-files/session_setup_sqlserver_cmds_example.sql b/data/session-setup-files/session_setup_sqlserver_cmds_example.sql new file mode 100644 index 000000000..bee4d4633 --- /dev/null +++ b/data/session-setup-files/session_setup_sqlserver_cmds_example.sql @@ -0,0 +1,3 @@ +-- SQL Server Database Console Command statements (DBCC) +DBCC DROPCLEANBUFFERS -- clear buffers (for cold runs) +DBCC FREEPROCCACHE -- clean plan cache \ No newline at end of file diff --git a/src/main/java/com/oltpbenchmark/DBWorkload.java b/src/main/java/com/oltpbenchmark/DBWorkload.java index f4108c27e..7009ec53b 100644 --- a/src/main/java/com/oltpbenchmark/DBWorkload.java +++ b/src/main/java/com/oltpbenchmark/DBWorkload.java @@ -122,6 +122,7 @@ public static void main(String[] args) throws Exception { wrkld.setPassword(xmlConfig.getString("password")); wrkld.setRandomSeed(xmlConfig.getInt("randomSeed", -1)); wrkld.setBatchSize(xmlConfig.getInt("batchsize", 128)); + wrkld.setSessionSetupFile(xmlConfig.getString("sessionsetupfile")); wrkld.setMaxRetries(xmlConfig.getInt("retries", 3)); wrkld.setNewConnectionPerTxn(xmlConfig.getBoolean("newConnectionPerTxn", false)); wrkld.setReconnectOnConnectionFailure( @@ -172,6 +173,7 @@ public static void main(String[] args) throws Exception { initDebug.put("URL", wrkld.getUrl()); initDebug.put("Isolation", wrkld.getIsolationString()); initDebug.put("Batch Size", wrkld.getBatchSize()); + initDebug.put("Session Setup File", wrkld.getSessionSetupFile()); initDebug.put("Scale Factor", wrkld.getScaleFactor()); initDebug.put("Terminals", wrkld.getTerminals()); initDebug.put("New Connection Per Txn", wrkld.getNewConnectionPerTxn()); diff --git a/src/main/java/com/oltpbenchmark/WorkloadConfiguration.java b/src/main/java/com/oltpbenchmark/WorkloadConfiguration.java index abf327004..f66b36a72 100644 --- a/src/main/java/com/oltpbenchmark/WorkloadConfiguration.java +++ b/src/main/java/com/oltpbenchmark/WorkloadConfiguration.java @@ -35,6 +35,7 @@ public class WorkloadConfiguration { private String password; private String driverClass; private int batchSize; + private String sessionSetupFile; private int maxRetries; private int randomSeed = -1; private double scaleFactor = 1.0; @@ -121,6 +122,14 @@ public void setBatchSize(int batchSize) { this.batchSize = batchSize; } + public String getSessionSetupFile(){ + return sessionSetupFile; + } + + public void setSessionSetupFile(String sessionSetupFile){ + this.sessionSetupFile = sessionSetupFile; + } + public int getMaxRetries() { return maxRetries; } @@ -389,6 +398,8 @@ public String toString() { + '\'' + ", batchSize=" + batchSize + + ", sessionSetupFile=" + + sessionSetupFile + ", maxRetries=" + maxRetries + ", scaleFactor=" diff --git a/src/main/java/com/oltpbenchmark/api/Worker.java b/src/main/java/com/oltpbenchmark/api/Worker.java index 3cac3882d..b6408d29a 100644 --- a/src/main/java/com/oltpbenchmark/api/Worker.java +++ b/src/main/java/com/oltpbenchmark/api/Worker.java @@ -26,6 +26,9 @@ import com.oltpbenchmark.types.TransactionStatus; import com.oltpbenchmark.util.Histogram; import com.oltpbenchmark.util.SQLUtil; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; import java.sql.Connection; import java.sql.SQLException; import java.sql.SQLRecoverableException; @@ -188,6 +191,13 @@ public final void run() { // In case of reuse reset the measurements latencies = new LatencyRecord(workloadState.getTestStartNs()); + // Invoke setup session + try { + this.setupSession(); + } catch (Throwable ex) { + throw new RuntimeException("Unexpected error when setting up the session " + this, ex); + } + // Invoke initialize callback try { this.initialize(); @@ -723,6 +733,31 @@ protected void initialize() { // The default is to do nothing } + /** + * Set up the session by running a set of statements before benchmark execution begins. + * The path of the file where a set of statements defined should be added + * in <sessionsetupfile> </sessionsetupfile> + */ + protected void setupSession() { + try { + String setupSessionFile = configuration.getSessionSetupFile(); + if (setupSessionFile == null || setupSessionFile.isEmpty()) { + return; + } + + String statements = new String(Files.readAllBytes(Paths.get(setupSessionFile))); + if (statements.isEmpty()) { + return; + } + + try (Statement stmt = conn.createStatement()) { + stmt.execute(statements); + } + } catch (SQLException | IOException ex) { + throw new RuntimeException("Failed setting up session", ex); + } + } + /** * Invoke a single transaction for the given TransactionType * From ed730c6397e04cfef17bd2b3922f8d0c4f95e189 Mon Sep 17 00:00:00 2001 From: Rana Alotaibi Date: Tue, 2 Jan 2024 16:19:07 -0800 Subject: [PATCH 2/3] Fix format --- src/main/java/com/oltpbenchmark/api/Worker.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/oltpbenchmark/api/Worker.java b/src/main/java/com/oltpbenchmark/api/Worker.java index b6408d29a..6a5d3b4cd 100644 --- a/src/main/java/com/oltpbenchmark/api/Worker.java +++ b/src/main/java/com/oltpbenchmark/api/Worker.java @@ -734,9 +734,9 @@ protected void initialize() { } /** - * Set up the session by running a set of statements before benchmark execution begins. - * The path of the file where a set of statements defined should be added - * in <sessionsetupfile> </sessionsetupfile> + * Set up the session by running a set of statements before benchmark execution begins. The path + * of the file where a set of statements defined should be added in <sessionsetupfile> + * </sessionsetupfile> */ protected void setupSession() { try { From 3086786214d42e57e21a7797eaaa1f9a0c96cf63 Mon Sep 17 00:00:00 2001 From: Rana Alotaibi Date: Tue, 2 Jan 2024 17:56:50 -0800 Subject: [PATCH 3/3] Move session setup file to the DB's config directory. --- config/sqlserver/sample_tpch_config.xml | 2 +- .../sqlserver}/session_setup_sqlserver_cmds_example.sql | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename {data/session-setup-files => config/sqlserver}/session_setup_sqlserver_cmds_example.sql (100%) diff --git a/config/sqlserver/sample_tpch_config.xml b/config/sqlserver/sample_tpch_config.xml index 6f49887c0..2cefff63b 100644 --- a/config/sqlserver/sample_tpch_config.xml +++ b/config/sqlserver/sample_tpch_config.xml @@ -11,7 +11,7 @@ TRANSACTION_SERIALIZABLE 1024 - + 0.1 diff --git a/data/session-setup-files/session_setup_sqlserver_cmds_example.sql b/config/sqlserver/session_setup_sqlserver_cmds_example.sql similarity index 100% rename from data/session-setup-files/session_setup_sqlserver_cmds_example.sql rename to config/sqlserver/session_setup_sqlserver_cmds_example.sql