Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
Binary file added lib/guava-31.1-jre.jar
Binary file not shown.
Binary file added lib/guava-retrying-2.0.0.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion src/client/jTPCC.java
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ else if(newOrderWeightValue == 0 && paymentWeightValue == 0 && orderStatusWeight
conn, dbType,
transactionsPerTerminal, terminalWarehouseFixed,
paymentWeightValue, orderStatusWeightValue,
deliveryWeightValue, stockLevelWeightValue, numWarehouses, limPerMin_Terminal, this);
deliveryWeightValue, stockLevelWeightValue, numWarehouses, limPerMin_Terminal, this, database, dbProps);

terminals[i] = terminal;
terminalNames[i] = terminalName;
Expand Down
7 changes: 6 additions & 1 deletion src/client/jTPCCConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,11 @@ public jTPCCConnection(Connection dbConn, int dbType)
" WHERE c_w_id = ? AND c_d_id = ? AND c_id = ?");
}

public Connection getDbConn()
{
return this.dbConn;
}

public jTPCCConnection(String connURL, Properties connProps, int dbType)
throws SQLException
{
Expand All @@ -316,6 +321,6 @@ public void commit()
public void rollback()
throws SQLException
{
dbConn.rollback();
dbConn.rollback();

Choose a reason for hiding this comment

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

格式调一下

}
}
20 changes: 0 additions & 20 deletions src/client/jTPCCTData.java
Original file line number Diff line number Diff line change
Expand Up @@ -568,10 +568,6 @@ else if (newOrder.ol_supply_w_id[ol_seq[y]] == newOrder.ol_supply_w_id[ol_seq[x]
}
catch (SQLException se)
{
log.error("Unexpected SQLException in NEW_ORDER");
for (SQLException x = se; x != null; x = x.getNextException())
log.error(x.getMessage());
se.printStackTrace();

try
{
Expand Down Expand Up @@ -935,10 +931,6 @@ private void executePayment(Logger log, jTPCCConnection db)
}
catch (SQLException se)
{
log.error("Unexpected SQLException in PAYMENT");
for (SQLException x = se; x != null; x = x.getNextException())
log.error(x.getMessage());
se.printStackTrace();

try
{
Expand Down Expand Up @@ -1232,10 +1224,6 @@ private void executeOrderStatus(Logger log, jTPCCConnection db)
}
catch (SQLException se)
{
log.error("Unexpected SQLException in ORDER_STATUS");
for (SQLException x = se; x != null; x = x.getNextException())
log.error(x.getMessage());
se.printStackTrace();

try
{
Expand Down Expand Up @@ -1388,10 +1376,6 @@ private void executeStockLevel(Logger log, jTPCCConnection db)
}
catch (SQLException se)
{
log.error("Unexpected SQLException in STOCK_LEVEL");
for (SQLException x = se; x != null; x = x.getNextException())
log.error(x.getMessage());
se.printStackTrace();

try
{
Expand Down Expand Up @@ -1731,10 +1715,6 @@ private void executeDeliveryBG(Logger log, jTPCCConnection db)
}
catch (SQLException se)
{
log.error("Unexpected SQLException in DELIVERY_BG");
for (SQLException x = se; x != null; x = x.getNextException())
log.error(x.getMessage());
se.printStackTrace();

try
{
Expand Down
102 changes: 79 additions & 23 deletions src/client/jTPCCTerminal.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,26 @@
* Copyright (C) 2016, Jan Wieck
*
*/
import org.apache.log4j.*;

import java.io.*;
import com.github.rholder.retry.RetryException;
import com.github.rholder.retry.Retryer;
import com.github.rholder.retry.RetryerBuilder;
import com.github.rholder.retry.StopStrategies;
import org.apache.log4j.Logger;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.sql.*;
import java.sql.Date;
import java.util.*;
import javax.swing.*;
import java.util.Properties;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;


public class jTPCCTerminal implements jTPCCConfig, Runnable
{
public class jTPCCTerminal implements jTPCCConfig, Runnable {
private static org.apache.log4j.Logger log = Logger.getLogger(jTPCCTerminal.class);

static Retryer<Boolean> connectRetryer = connectRetryer();

private String terminalName;
private Connection conn = null;
private Statement stmt = null;
Expand All @@ -45,12 +52,16 @@ public class jTPCCTerminal implements jTPCCConfig, Runnable
jTPCCConnection db = null;
int dbType = 0;

private String database = "";
private Properties dbProps = null;

public jTPCCTerminal
(String terminalName, int terminalWarehouseID, int terminalDistrictID,
Connection conn, int dbType,
int numTransactions, boolean terminalWarehouseFixed,
int paymentWeight, int orderStatusWeight,
int deliveryWeight, int stockLevelWeight, int numWarehouses, int limPerMin_Terminal, jTPCC parent) throws SQLException
int deliveryWeight, int stockLevelWeight, int numWarehouses, int limPerMin_Terminal, jTPCC parent,
String database, Properties dbProp) throws SQLException
{
this.terminalName = terminalName;
this.conn = conn;
Expand All @@ -76,6 +87,9 @@ public class jTPCCTerminal implements jTPCCConfig, Runnable
this.newOrderCounter = 0;
this.limPerMin_Terminal = limPerMin_Terminal;

this.database = database;
this.dbProps = dbProp;

this.db = new jTPCCConnection(conn, dbType);

terminalMessage("");
Expand Down Expand Up @@ -167,9 +181,12 @@ private void executeTransactions(int numTransactions)
}
catch (Exception e)
{
log.fatal(e.getMessage());
e.printStackTrace();
System.exit(4);
try {
Callable<Boolean> retryConnect = () -> retryConnect();
connectRetryer.call(retryConnect);
} catch (ExecutionException | RetryException ex) {
throw new RuntimeException(ex);
}
}
transactionTypeName = "Payment";
}
Expand All @@ -193,9 +210,12 @@ else if(transactionType <= paymentWeight + stockLevelWeight)
}
catch (Exception e)
{
log.fatal(e.getMessage());
e.printStackTrace();
System.exit(4);
try {
Callable<Boolean> retryConnect = () -> retryConnect();
connectRetryer.call(retryConnect);
} catch (ExecutionException | RetryException ex) {
throw new RuntimeException(ex);
}
}
transactionTypeName = "Stock-Level";
}
Expand All @@ -219,9 +239,12 @@ else if(transactionType <= paymentWeight + stockLevelWeight + orderStatusWeight)
}
catch (Exception e)
{
log.fatal(e.getMessage());
e.printStackTrace();
System.exit(4);
try {
Callable<Boolean> retryConnect = () -> retryConnect();
connectRetryer.call(retryConnect);
} catch (ExecutionException | RetryException ex) {
throw new RuntimeException(ex);
}
}
transactionTypeName = "Order-Status";
}
Expand Down Expand Up @@ -258,9 +281,12 @@ else if(transactionType <= paymentWeight + stockLevelWeight + orderStatusWeight
}
catch (Exception e)
{
log.fatal(e.getMessage());
e.printStackTrace();
System.exit(4);
try {
Callable<Boolean> retryConnect = () -> retryConnect();
connectRetryer.call(retryConnect);
} catch (ExecutionException | RetryException ex) {
throw new RuntimeException(ex);
}
}
transactionTypeName = "Delivery";
}
Expand All @@ -284,9 +310,12 @@ else if(transactionType <= paymentWeight + stockLevelWeight + orderStatusWeight
}
catch (Exception e)
{
log.fatal(e.getMessage());
e.printStackTrace();
System.exit(4);
try {
Callable<Boolean> retryConnect = () -> retryConnect();
connectRetryer.call(retryConnect);
} catch (ExecutionException | RetryException ex) {
throw new RuntimeException(ex);
}
}
transactionTypeName = "New-Order";
newOrderCounter++;
Expand Down Expand Up @@ -367,5 +396,32 @@ void transCommit() {
} // end transCommit()


boolean retryConnect() throws SQLException {
if (!db.getDbConn().isClosed()){
return true;
}
long startTime = System.currentTimeMillis();
Connection c = DriverManager.getConnection(this.database, this.dbProps);
c.setAutoCommit(false);
this.conn = c;
this.stmt = c.createStatement();
this.stmt.setMaxRows(200);
this.stmt.setFetchSize(100);

this.stmt1 = c.createStatement();
this.stmt1.setMaxRows(1);

this.db = new jTPCCConnection(c, dbType);
log.info("Reconnected to " + this.database + " in " + (System.currentTimeMillis() - startTime) + "ms");
return true;
}

public static Retryer<Boolean> connectRetryer() {
return RetryerBuilder.<Boolean>newBuilder()
.retryIfExceptionOfType(Exception.class)
.withStopStrategy(StopStrategies.stopAfterDelay(1000 * 120, java.util.concurrent.TimeUnit.MILLISECONDS))
.build();
}


}