Skip to content

Commit 34c1bcb

Browse files
Rana AlotaibiRana Alotaibi
Rana Alotaibi
authored and
Rana Alotaibi
committed
Introduce session setup
1 parent 65322e9 commit 34c1bcb

File tree

5 files changed

+48
-0
lines changed

5 files changed

+48
-0
lines changed

config/sqlserver/sample_tpch_config.xml

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
<password>P@ssw0rd</password>
1010
<isolation>TRANSACTION_SERIALIZABLE</isolation>
1111
<batchsize>1024</batchsize>
12+
<!-- Session setup statements file -->
13+
<!-- <sessionsetupfile>data/session-setup-files/session_setup_sqlserver_cmds_example.sql</sessionsetupfile> -->
1214

1315
<scalefactor>0.1</scalefactor>
1416

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
@@ -124,6 +124,7 @@ public static void main(String[] args) throws Exception {
124124
wrkld.setPassword(xmlConfig.getString("password"));
125125
wrkld.setRandomSeed(xmlConfig.getInt("randomSeed", -1));
126126
wrkld.setBatchSize(xmlConfig.getInt("batchsize", 128));
127+
wrkld.setSessionSetupFile(xmlConfig.getString("sessionsetupfile"));
127128
wrkld.setMaxRetries(xmlConfig.getInt("retries", 3));
128129
wrkld.setNewConnectionPerTxn(xmlConfig.getBoolean("newConnectionPerTxn", false));
129130

@@ -169,6 +170,7 @@ public static void main(String[] args) throws Exception {
169170
initDebug.put("URL", wrkld.getUrl());
170171
initDebug.put("Isolation", wrkld.getIsolationString());
171172
initDebug.put("Batch Size", wrkld.getBatchSize());
173+
initDebug.put("Session Setup File", wrkld.getSessionSetupFile());
172174
initDebug.put("Scale Factor", wrkld.getScaleFactor());
173175
initDebug.put("Terminals", wrkld.getTerminals());
174176
initDebug.put("New Connection Per Txn", wrkld.getNewConnectionPerTxn());

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

+6
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class WorkloadConfiguration {
3737
private String password;
3838
private String driverClass;
3939
private int batchSize;
40+
private String sessionSetupFile;
4041
private int maxRetries;
4142
private int randomSeed = -1;
4243
private double scaleFactor = 1.0;
@@ -116,6 +117,10 @@ public void setBatchSize(int batchSize) {
116117
this.batchSize = batchSize;
117118
}
118119

120+
public String getSessionSetupFile(){ return sessionSetupFile; }
121+
122+
public void setSessionSetupFile(String sessionSetupFile){ this.sessionSetupFile = sessionSetupFile; }
123+
119124
public int getMaxRetries() {
120125
return maxRetries;
121126
}
@@ -337,6 +342,7 @@ public String toString() {
337342
", password='" + password + '\'' +
338343
", driverClass='" + driverClass + '\'' +
339344
", batchSize=" + batchSize +
345+
", setupSessionFile=" + sessionSetupFile +
340346
", maxRetries=" + maxRetries +
341347
", scaleFactor=" + scaleFactor +
342348
", selectivity=" + selectivity +

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

+35
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
import org.slf4j.Logger;
2727
import org.slf4j.LoggerFactory;
2828

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.Statement;
@@ -191,6 +194,13 @@ public final void run() {
191194
// In case of reuse reset the measurements
192195
latencies = new LatencyRecord(workloadState.getTestStartNs());
193196

197+
// Invoke setup session
198+
try {
199+
this.setupSession();
200+
} catch (Throwable ex) {
201+
throw new RuntimeException("Unexpected error when setting up the session " + this, ex);
202+
}
203+
194204
// Invoke initialize callback
195205
try {
196206
this.initialize();
@@ -520,6 +530,31 @@ protected void initialize() {
520530
// The default is to do nothing
521531
}
522532

533+
/**
534+
* Set up the session by running a set of statements before benchmark execution begins.
535+
* The path of the file where a set of statements defined should be added
536+
* in &lt;sessionsetupfile&gt; &lt;/sessionsetupfile&gt;
537+
*/
538+
protected void setupSession() {
539+
try {
540+
String setupSessionFile = configuration.getSessionSetupFile();
541+
if (setupSessionFile == null || setupSessionFile.isEmpty()) {
542+
return;
543+
}
544+
545+
String statements = new String(Files.readAllBytes(Paths.get(setupSessionFile)));
546+
if (statements.isEmpty()) {
547+
return;
548+
}
549+
550+
try (Statement stmt = conn.createStatement()) {
551+
stmt.execute(statements);
552+
}
553+
} catch (SQLException | IOException ex) {
554+
throw new RuntimeException("Failed setting up session", ex);
555+
}
556+
}
557+
523558
/**
524559
* Invoke a single transaction for the given TransactionType
525560
*

0 commit comments

Comments
 (0)