Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce session setup #422

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/sqlserver/sample_tpch_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<reconnectOnConnectionFailure>true</reconnectOnConnectionFailure>
<isolation>TRANSACTION_SERIALIZABLE</isolation>
<batchsize>1024</batchsize>
<!-- Session setup statements file -->
<!-- <sessionsetupfile>config/sqlserver/session_setup_sqlserver_cmds_example.sql</sessionsetupfile> -->
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request that we have at least one example config where this option is not commented out so that it runs during the CI tests and/pr add an explicit unit test for it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ranaalotaibiMS bump :)


<scalefactor>0.1</scalefactor>

Expand Down
3 changes: 3 additions & 0 deletions config/sqlserver/session_setup_sqlserver_cmds_example.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- SQL Server Database Console Command statements (DBCC)
DBCC DROPCLEANBUFFERS -- clear buffers (for cold runs)
DBCC FREEPROCCACHE -- clean plan cache
bpkroth marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 2 additions & 0 deletions src/main/java/com/oltpbenchmark/DBWorkload.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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());
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/oltpbenchmark/WorkloadConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -389,6 +398,8 @@ public String toString() {
+ '\''
+ ", batchSize="
+ batchSize
+ ", sessionSetupFile="
+ sessionSetupFile
+ ", maxRetries="
+ maxRetries
+ ", scaleFactor="
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/com/oltpbenchmark/api/Worker.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 &lt;sessionsetupfile&gt;
* &lt;/sessionsetupfile&gt;
*/
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
*
Expand Down
Loading