Skip to content

Commit 5d4bcb9

Browse files
Rana AlotaibiRana Alotaibi
Rana Alotaibi
authored and
Rana Alotaibi
committed
Introduce session setup
1 parent 42655b8 commit 5d4bcb9

File tree

5 files changed

+53
-0
lines changed

5 files changed

+53
-0
lines changed

config/sqlserver/sample_tpch_config.xml

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
<reconnectOnConnectionFailure>true</reconnectOnConnectionFailure>
1111
<isolation>TRANSACTION_SERIALIZABLE</isolation>
1212
<batchsize>1024</batchsize>
13+
<!-- Session setup statements file -->
14+
<!-- <sessionsetupfile>data/session-setup-files/session_setup_sqlserver_cmds_example.sql</sessionsetupfile> -->
1315

1416
<scalefactor>0.1</scalefactor>
1517

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-- SQL Server Database Console Command statements (DBCC)
2+
DBCC DROPCLEANBUFFERS -- clear buffers (for cold runs)
3+
DBCC FREEPROCCACHE -- clean plan cache

src/main/java/com/oltpbenchmark/DBWorkload.java

+2
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ public static void main(String[] args) throws Exception {
122122
wrkld.setPassword(xmlConfig.getString("password"));
123123
wrkld.setRandomSeed(xmlConfig.getInt("randomSeed", -1));
124124
wrkld.setBatchSize(xmlConfig.getInt("batchsize", 128));
125+
wrkld.setSessionSetupFile(xmlConfig.getString("sessionsetupfile"));
125126
wrkld.setMaxRetries(xmlConfig.getInt("retries", 3));
126127
wrkld.setNewConnectionPerTxn(xmlConfig.getBoolean("newConnectionPerTxn", false));
127128
wrkld.setReconnectOnConnectionFailure(
@@ -172,6 +173,7 @@ public static void main(String[] args) throws Exception {
172173
initDebug.put("URL", wrkld.getUrl());
173174
initDebug.put("Isolation", wrkld.getIsolationString());
174175
initDebug.put("Batch Size", wrkld.getBatchSize());
176+
initDebug.put("Session Setup File", wrkld.getSessionSetupFile());
175177
initDebug.put("Scale Factor", wrkld.getScaleFactor());
176178
initDebug.put("Terminals", wrkld.getTerminals());
177179
initDebug.put("New Connection Per Txn", wrkld.getNewConnectionPerTxn());

src/main/java/com/oltpbenchmark/WorkloadConfiguration.java

+11
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class WorkloadConfiguration {
3535
private String password;
3636
private String driverClass;
3737
private int batchSize;
38+
private String sessionSetupFile;
3839
private int maxRetries;
3940
private int randomSeed = -1;
4041
private double scaleFactor = 1.0;
@@ -121,6 +122,14 @@ public void setBatchSize(int batchSize) {
121122
this.batchSize = batchSize;
122123
}
123124

125+
public String getSessionSetupFile(){
126+
return sessionSetupFile;
127+
}
128+
129+
public void setSessionSetupFile(String sessionSetupFile){
130+
this.sessionSetupFile = sessionSetupFile;
131+
}
132+
124133
public int getMaxRetries() {
125134
return maxRetries;
126135
}
@@ -389,6 +398,8 @@ public String toString() {
389398
+ '\''
390399
+ ", batchSize="
391400
+ batchSize
401+
+ ", sessionSetupFile="
402+
+ sessionSetupFile
392403
+ ", maxRetries="
393404
+ maxRetries
394405
+ ", scaleFactor="

src/main/java/com/oltpbenchmark/api/Worker.java

+35
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
import com.oltpbenchmark.types.TransactionStatus;
2727
import com.oltpbenchmark.util.Histogram;
2828
import com.oltpbenchmark.util.SQLUtil;
29+
import java.io.IOException;
30+
import java.nio.file.Files;
31+
import java.nio.file.Paths;
2932
import java.sql.Connection;
3033
import java.sql.SQLException;
3134
import java.sql.SQLRecoverableException;
@@ -188,6 +191,13 @@ public final void run() {
188191
// In case of reuse reset the measurements
189192
latencies = new LatencyRecord(workloadState.getTestStartNs());
190193

194+
// Invoke setup session
195+
try {
196+
this.setupSession();
197+
} catch (Throwable ex) {
198+
throw new RuntimeException("Unexpected error when setting up the session " + this, ex);
199+
}
200+
191201
// Invoke initialize callback
192202
try {
193203
this.initialize();
@@ -723,6 +733,31 @@ protected void initialize() {
723733
// The default is to do nothing
724734
}
725735

736+
/**
737+
* Set up the session by running a set of statements before benchmark execution begins.
738+
* The path of the file where a set of statements defined should be added
739+
* in &lt;sessionsetupfile&gt; &lt;/sessionsetupfile&gt;
740+
*/
741+
protected void setupSession() {
742+
try {
743+
String setupSessionFile = configuration.getSessionSetupFile();
744+
if (setupSessionFile == null || setupSessionFile.isEmpty()) {
745+
return;
746+
}
747+
748+
String statements = new String(Files.readAllBytes(Paths.get(setupSessionFile)));
749+
if (statements.isEmpty()) {
750+
return;
751+
}
752+
753+
try (Statement stmt = conn.createStatement()) {
754+
stmt.execute(statements);
755+
}
756+
} catch (SQLException | IOException ex) {
757+
throw new RuntimeException("Failed setting up session", ex);
758+
}
759+
}
760+
726761
/**
727762
* Invoke a single transaction for the given TransactionType
728763
*

0 commit comments

Comments
 (0)