Skip to content
Open
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
32 changes: 14 additions & 18 deletions src/com/oltpbenchmark/api/Loader.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ public LoaderThread() {}
public final void run() {
try {
Connection conn = Loader.this.benchmark.makeConnection();
conn.setAutoCommit(false);

this.load(conn);
conn.commit();
conn.close();
} catch (SQLException ex) {
SQLException next_ex = ex.getNextException();
Expand Down Expand Up @@ -171,7 +168,7 @@ protected void transRollback(Connection conn) {
}
}

private void performInsertsWithRetries(Connection conn, PreparedStatement... stmts) throws Exception {
private void performInsertsWithRetries(PreparedStatement... stmts) throws Exception {
int attempts = workConf.getMaxLoaderRetries() + 1;
SQLException failure = null;
for (int i = 0; i < attempts; ++i) {
Expand All @@ -180,12 +177,11 @@ private void performInsertsWithRetries(Connection conn, PreparedStatement... stm
stmt.executeBatch();
stmt.clearBatch();
}
conn.commit();
return;
} catch (SQLException ex) {
LOG.warn("Fail to load batch with error: " + ex.getMessage());
LOG.error("Fail to load batch with error: " + ex.getMessage());
failure = ex;
transRollback(conn);
break;
}
}
if (failure != null) {
Expand Down Expand Up @@ -239,12 +235,12 @@ protected void loadItems(Connection conn) {
batchSize++;

if (batchSize == workConf.getBatchSize()) {
performInsertsWithRetries(conn, itemPrepStmt);
performInsertsWithRetries(itemPrepStmt);
batchSize = 0;
}
}
if (batchSize > 0)
performInsertsWithRetries(conn, itemPrepStmt);
performInsertsWithRetries(itemPrepStmt);

} catch (Exception ex) {
LOG.error("Failed to load data for TPC-C", ex);
Expand Down Expand Up @@ -282,7 +278,7 @@ protected void loadWarehouse(Connection conn, int w_id) {
whsePrepStmt.setString(++idx, warehouse.w_zip);
whsePrepStmt.execute();

performInsertsWithRetries(conn, whsePrepStmt);
performInsertsWithRetries(whsePrepStmt);
} catch (Exception ex) {
LOG.error("Failed to load data for TPC-C", ex);
transRollback(conn);
Expand Down Expand Up @@ -340,10 +336,10 @@ private void loadStock(Connection conn, int w_id) {
stckPrepStmt.setString(++idx, TPCCUtil.randomStr(24));
stckPrepStmt.addBatch();
if ((k % workConf.getBatchSize()) == 0) {
performInsertsWithRetries(conn, stckPrepStmt);
performInsertsWithRetries(stckPrepStmt);
}
} // end for [i]
performInsertsWithRetries(conn, stckPrepStmt);
performInsertsWithRetries(stckPrepStmt);
} catch (Exception ex) {
LOG.error("Failed to load data for TPC-C", ex);
transRollback(conn);
Expand Down Expand Up @@ -385,7 +381,7 @@ private void loadDistricts(Connection conn, int w_id) {
distPrepStmt.setString(++idx, district.d_zip);
distPrepStmt.addBatch();
} // end for [d]
performInsertsWithRetries(conn, distPrepStmt);
performInsertsWithRetries(distPrepStmt);
} catch (Exception e) {
LOG.error("Failed to load data for TPC-C", e);
transRollback(conn);
Expand Down Expand Up @@ -488,11 +484,11 @@ private void loadCustomers(Connection conn, int w_id) {
histPrepStmt.addBatch();

if ((k % workConf.getBatchSize()) == 0) {
performInsertsWithRetries(conn, custPrepStmt, histPrepStmt);
performInsertsWithRetries(custPrepStmt, histPrepStmt);
}
} // end for [c]
} // end for [d]
performInsertsWithRetries(conn, custPrepStmt, histPrepStmt);
performInsertsWithRetries(custPrepStmt, histPrepStmt);

} catch (Exception e) {
LOG.error("Failed to load data for TPC-C", e);
Expand Down Expand Up @@ -619,10 +615,10 @@ private void loadOrders(Connection conn, int w_id) {

if ((k % workConf.getBatchSize()) == 0) {
if (newOrderBatch > 0) {
performInsertsWithRetries(conn, ordrPrepStmt, nworPrepStmt, orlnPrepStmt);
performInsertsWithRetries(ordrPrepStmt, nworPrepStmt, orlnPrepStmt);
newOrderBatch = 0;
} else {
performInsertsWithRetries(conn, ordrPrepStmt, orlnPrepStmt);
performInsertsWithRetries(ordrPrepStmt, orlnPrepStmt);
}
}
} // end for [l]
Expand All @@ -631,7 +627,7 @@ private void loadOrders(Connection conn, int w_id) {

if (LOG.isDebugEnabled())
LOG.debug(" Writing final records " + k + " of " + t);
performInsertsWithRetries(conn, ordrPrepStmt, nworPrepStmt, orlnPrepStmt);
performInsertsWithRetries(ordrPrepStmt, nworPrepStmt, orlnPrepStmt);
} catch (Exception e) {
LOG.error("Failed to load data for TPC-C", e);
transRollback(conn);
Expand Down