Skip to content

Commit 85e7332

Browse files
sonalsagarwalSonal Agarwal
andauthored
Support for multiple drivers in tpcc (#150)
Add support for multiple drivers, can be changed based on DB type. Co-authored-by: Sonal Agarwal <sagarwal@yugabyte.com>
1 parent 0ad0df7 commit 85e7332

File tree

14 files changed

+297
-173
lines changed

14 files changed

+297
-173
lines changed

config/workload_all.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0"?>
22
<parameters>
3-
<dbtype>postgres</dbtype>
3+
<dbtype>yugabyte</dbtype>
44
<driver>com.yugabyte.Driver</driver>
55
<port>5433</port>
66
<username>yugabyte</username>

config/workload_all_pg.xml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?xml version="1.0"?>
2+
<parameters>
3+
<dbtype>postgres</dbtype>
4+
<driver>org.postgresql.Driver</driver>
5+
<port>5432</port>
6+
<username>postgres</username>
7+
<DBName>postgres</DBName>
8+
<password>Password321</password>
9+
<isolation>TRANSACTION_REPEATABLE_READ</isolation>
10+
11+
<sslCert></sslCert>
12+
<sslKey></sslKey>
13+
<jdbcURL></jdbcURL>
14+
15+
<batchSize>128</batchSize>
16+
<useKeyingTime>true</useKeyingTime>
17+
<useThinkTime>true</useThinkTime>
18+
<enableForeignKeysAfterLoad>true</enableForeignKeysAfterLoad>
19+
<hikariConnectionTimeoutMs>180000</hikariConnectionTimeoutMs>
20+
<useStoredProcedures>true</useStoredProcedures>
21+
<displayEnhancedLatencyMetrics>false</displayEnhancedLatencyMetrics>
22+
<trackPerSQLStmtLatencies>false</trackPerSQLStmtLatencies>
23+
24+
<transactiontypes>
25+
<transaction>
26+
<name>NewOrder</name>
27+
<weight>45</weight>
28+
</transaction>
29+
<transaction>
30+
<name>Payment</name>
31+
<weight>43</weight>
32+
</transaction>
33+
<transaction>
34+
<name>OrderStatus</name>
35+
<weight>4</weight>
36+
</transaction>
37+
<transaction>
38+
<name>Delivery</name>
39+
<weight>4</weight>
40+
</transaction>
41+
<transaction>
42+
<name>StockLevel</name>
43+
<weight>4</weight>
44+
</transaction>
45+
</transactiontypes>
46+
47+
<runtime>1800</runtime>
48+
<rate>10000</rate>
49+
<!--
50+
Set the number of retries to 0 as retrying when the number of warehouses is
51+
high is pointless as it just leads to more failures.
52+
-->
53+
<maxRetriesPerTransaction>2</maxRetriesPerTransaction>
54+
<maxLoaderRetries>2</maxLoaderRetries>
55+
56+
</parameters>

ivy.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
<!-- JDBC Drivers -->
2323
<dependency org="com.yugabyte" name="jdbc-yugabytedb" rev="42.3.5-yb-3" force="true" conf="compile->compile(*),master(*);runtime->runtime(*)"/>
2424
<dependency org="org.hsqldb" name="hsqldb" rev="2.4.1" force="true" conf="compile->compile(*),master(*);runtime->runtime(*)"/>
25-
25+
<!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
26+
<dependency org="org.postgresql" name="postgresql" rev="42.4.5"/>
2627
<dependency org="com.zaxxer" name="HikariCP" rev="3.4.5" force="true" conf="compile->compile(*),master(*);runtime->runtime(*)"/>
2728

2829
<!-- Core Libraries -->

pom.xml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,17 @@
7777
<artifactId>httpmime</artifactId>
7878
<version>4.3.1</version>
7979
</dependency>
80-
<dependency>
80+
<dependency>
8181
<groupId>com.yugabyte</groupId>
8282
<artifactId>jdbc-yugabytedb</artifactId>
83-
<version>42.3.5-yb-3</version>
84-
</dependency>
83+
<version>42.3.5-yb-3</version>
84+
</dependency>
85+
<!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
86+
<dependency>
87+
<groupId>org.postgresql</groupId>
88+
<artifactId>postgresql</artifactId>
89+
<version>42.4.5</version>
90+
</dependency>
8591
<dependency>
8692
<groupId>org.hsqldb</groupId>
8793
<artifactId>hsqldb-j5</artifactId>

src/com/oltpbenchmark/ConfigFileOptions.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ public ConfigFileOptions(String filePath) throws ConfigurationException {
99
super(filePath);
1010
}
1111

12+
public String getDbType() {
13+
return xmlConfig.getString("dbtype");
14+
}
15+
1216
public String getDbDriver() {
1317
return xmlConfig.getString("driver");
1418
}

src/com/oltpbenchmark/DBWorkload.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public class DBWorkload {
5252
private static final Map<Integer, String> transactionTypes = new HashMap<>();
5353
private static JsonMetricsHelper jsonMetricsHelper = new JsonMetricsHelper();
5454

55+
public static String dbtype = "";
5556
/**
5657
* Returns true if asserts are enabled. This assumes that
5758
* we're always using the default system ClassLoader
@@ -159,6 +160,8 @@ public static void main(String[] args) throws Exception {
159160
wrkld.setNodes(nodes);
160161

161162
wrkld.setDBName(configOptions.getDbName());
163+
wrkld.setDBType(configOptions.getDbType());
164+
DBWorkload.dbtype = configOptions.getDbType();
162165
wrkld.setDBUsername(configOptions.getDbUsername());
163166
wrkld.setDBPassword(configOptions.getDbPassword());
164167

src/com/oltpbenchmark/WorkloadConfiguration.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public void setBenchmarkName(String benchmarkName) {
4141
}
4242

4343
private List<String> nodes;
44+
private String db_type;
4445
private String db_name;
4546
private String db_username;
4647
private String db_password;
@@ -117,6 +118,10 @@ public void setDBName(String dbname) {
117118
this.db_name = dbname;
118119
}
119120

121+
public void setDBType(String dbtype) {
122+
this.db_type = dbtype;
123+
}
124+
120125
public void setLoaderThreads(int loaderThreads) {
121126
this.loaderThreads = loaderThreads;
122127
}
@@ -140,6 +145,9 @@ public String getDBName() {
140145
return db_name;
141146
}
142147

148+
public String getDBType() {
149+
return db_type;
150+
}
143151
public void setDBUsername(String username) {
144152
this.db_username = username;
145153
}

src/com/oltpbenchmark/api/BenchmarkModule.java

Lines changed: 56 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,13 @@ public void createDataSource() {
9090
ThreadUtil.sleep(5000);
9191
}
9292
Properties props = new Properties();
93-
props.setProperty("dataSourceClassName", "com.yugabyte.ysql.YBClusterAwareDataSource");
94-
//props.setProperty("dataSource.serverNames", ip);
95-
props.setProperty("dataSource.serverName", ip);
93+
if(workConf.getDBType().equals("yugabyte")){
94+
props.setProperty("dataSourceClassName", "com.yugabyte.ysql.YBClusterAwareDataSource");
95+
} else {
96+
props.setProperty("dataSourceClassName", "org.postgresql.ds.PGSimpleDataSource");
97+
}
98+
//props.setProperty("dataSource.serverNames", ip);
99+
props.setProperty("dataSource.serverName", ip);
96100
props.setProperty("dataSource.portNumber", Integer.toString(workConf.getPort()));
97101
props.setProperty("dataSource.user", workConf.getDBUsername());
98102
props.setProperty("dataSource.password", workConf.getDBPassword());
@@ -119,30 +123,57 @@ public void createDataSource() {
119123
}
120124

121125
public final Connection makeConnection() throws SQLException {
122-
YBClusterAwareDataSource ds = new YBClusterAwareDataSource();
123-
ds.setProperty("user", workConf.getDBUsername());
124-
ds.setProperty("password", workConf.getDBPassword());
125-
ds.setProperty("reWriteBatchedInserts", "true");
126-
127-
if (workConf.getSslCert() != null && workConf.getSslCert().length() > 0) {
128-
assert(workConf.getSslKey().length() > 0) : "The SSL key is empty.";
129-
ds.setProperty("sslmode", "require");
130-
ds.setProperty("sslcert", workConf.getSslCert());
131-
ds.setProperty("sslkey", workConf.getSslKey());
126+
Connection conn = null;
127+
if(workConf.getDBType().equals("yugabyte")) {
128+
YBClusterAwareDataSource ds = new YBClusterAwareDataSource();
129+
ds.setProperty("user", workConf.getDBUsername());
130+
ds.setProperty("password", workConf.getDBPassword());
131+
ds.setProperty("reWriteBatchedInserts", "true");
132+
133+
if (workConf.getSslCert() != null && workConf.getSslCert().length() > 0) {
134+
assert (workConf.getSslKey().length() > 0) : "The SSL key is empty.";
135+
ds.setProperty("sslmode", "require");
136+
ds.setProperty("sslcert", workConf.getSslCert());
137+
ds.setProperty("sslkey", workConf.getSslKey());
138+
}
139+
int r = dataSourceCounter.getAndIncrement() % workConf.getNodes().size();
140+
String connectStr;
141+
if (workConf.getJdbcURL() != null && workConf.getJdbcURL().length() > 0) {
142+
connectStr = workConf.getJdbcURL();
143+
} else {
144+
connectStr = String.format("jdbc:yugabytedb://%s:%d/%s",
145+
workConf.getNodes().get(r),
146+
workConf.getPort(),
147+
workConf.getDBName());
148+
}
149+
ds.setUrl(connectStr);
150+
conn = ds.getConnection();
132151
}
152+
else {
153+
java.util.Properties props = new java.util.Properties();
154+
props.put("user", workConf.getDBUsername());
155+
props.put("password", workConf.getDBPassword());
156+
props.put("reWriteBatchedInserts", "true");
133157

134-
int r = dataSourceCounter.getAndIncrement() % workConf.getNodes().size();
135-
String connectStr;
136-
if (workConf.getJdbcURL() != null && workConf.getJdbcURL().length()>0) {
137-
connectStr=workConf.getJdbcURL();
138-
} else {
139-
connectStr = String.format("jdbc:yugabytedb://%s:%d/%s",
140-
workConf.getNodes().get(r),
141-
workConf.getPort(),
142-
workConf.getDBName());
158+
if (workConf.getSslCert() != null && workConf.getSslCert().length() > 0) {
159+
assert (workConf.getSslKey().length() > 0) : "The SSL key is empty.";
160+
props.put("sslmode", "require");
161+
props.put("sslcert", workConf.getSslCert());
162+
props.put("sslkey", workConf.getSslKey());
163+
}
164+
int r = dataSourceCounter.getAndIncrement() % workConf.getNodes().size();
165+
String connectStr;
166+
if (workConf.getJdbcURL() != null && workConf.getJdbcURL().length() > 0) {
167+
connectStr = workConf.getJdbcURL();
168+
} else {
169+
connectStr = String.format("jdbc:postgresql://%s:%d/%s",
170+
workConf.getNodes().get(r),
171+
workConf.getPort(),
172+
workConf.getDBName());
173+
}
174+
conn = DriverManager.getConnection(connectStr, props);
143175
}
144-
ds.setUrl(connectStr);
145-
return ds.getConnection();
176+
return conn;
146177
}
147178

148179
private static final AtomicInteger dataSourceCounter = new AtomicInteger(0);
@@ -199,7 +230,7 @@ public final void createDatabase() {
199230
try {
200231
Connection conn = makeConnection();
201232
SchemaManager schemaManager = SchemaManagerFactory.getSchemaManager(workConf, conn);
202-
schemaManager.create();
233+
schemaManager.create(workConf.getDBType());
203234
conn.close();
204235
} catch (SQLException ex) {
205236
throw new RuntimeException(String.format("Unexpected error when trying to create the %s database", this.benchmarkName), ex);

src/com/oltpbenchmark/api/Worker.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,8 @@ protected final ArrayList<Pair<TransactionExecutionState, TransactionStatus>> do
482482

483483
conn = dataSource.getConnection();
484484
try {
485-
conn.createStatement().execute("SET yb_enable_expression_pushdown to on");
485+
if(wrkld.getDBType().equals("yugabyte"))
486+
conn.createStatement().execute("SET yb_enable_expression_pushdown to on");
486487
if (next.getProcedureClass() != StockLevel.class) {
487488
// In accordance with 2.8.2.3 of the TPCC spec, StockLevel should execute each query in its own Snapshot
488489
// Isolation.

src/com/oltpbenchmark/schema/SchemaManager.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@ public SchemaManager(Connection db_connection) {
1515
this.db_connection = db_connection;
1616
}
1717

18-
public abstract void create() throws SQLException;
19-
18+
public abstract void create(String dbType) throws SQLException;
2019
public abstract void enableForeignKeyConstraints() throws SQLException;
2120

2221
public abstract void dropForeignKeyConstraints() throws SQLException;
2322

24-
protected abstract void createIndexes() throws SQLException;
23+
protected abstract void createIndexes(String dbType) throws SQLException;
2524

2625
public static Set<String> getTableNames() {
2726
return TPCCTableSchemas.tables.keySet();

0 commit comments

Comments
 (0)