Skip to content

Commit

Permalink
Switch txns to return instead of unnecessarily aborting in SEATS (cmu…
Browse files Browse the repository at this point in the history
  • Loading branch information
timveil authored Mar 8, 2022
1 parent ca5d7e2 commit c9f2bd6
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 104 deletions.
4 changes: 1 addition & 3 deletions src/main/java/com/oltpbenchmark/DBWorkload.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ public static void main(String[] args) throws Exception {
// create the command line parser
CommandLineParser parser = new DefaultParser();

// Get the directory of the jar output
String jarDirPath = new File(DBWorkload.class.getProtectionDomain().getCodeSource().getLocation().toURI()).getParent();
XMLConfiguration pluginConfig = buildConfiguration(jarDirPath + "/config/plugin.xml");
XMLConfiguration pluginConfig = buildConfiguration("config/plugin.xml");

Options options = buildOptions(pluginConfig);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ private boolean executeUpdateReservation(Connection conn, UpdateReservation proc
// Nothing
}
if (r == null) {
LOG.warn(String.format("Failed to find Reservation to update [cache=%d]", cache.size()));
LOG.debug(String.format("Failed to find Reservation to update [cache=%d]", cache.size()));
return (false);
}
if (LOG.isTraceEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ public void run(Connection conn, String f_id, String c_id, String c_id_str, Stri
ff_al_id = results.getLong(2);
}
} else {
throw new UserAbortException(String.format("No Customer record was found [c_id_str=%s, ff_c_id_str=%s, ff_al_id=%s]",
c_id_str, ff_c_id_str, ff_al_id));
LOG.debug("No Customer record was found [c_id_str={}, ff_c_id_str={}, ff_al_id={}]", c_id_str, ff_c_id_str, ff_al_id);
return;
}
}
}
Expand All @@ -131,7 +131,8 @@ public void run(Connection conn, String f_id, String c_id, String c_id_str, Stri
stmt.setString(2, f_id);
try (ResultSet results = stmt.executeQuery()) {
if (!results.next()) {
throw new UserAbortException(String.format("No Customer information record found for id '%s'", c_id));
LOG.debug("No Customer information record found for id '{}'", c_id);
return;
}
c_iattr00 = results.getLong(4) + 1;
seats_left = results.getLong(8);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,83 +36,83 @@ public class NewReservation extends Procedure {

public final SQLStmt GetFlight = new SQLStmt(
"SELECT F_AL_ID, F_SEATS_LEFT, " +
SEATSConstants.TABLENAME_AIRLINE + ".* " +
" FROM " + SEATSConstants.TABLENAME_FLIGHT + ", " +
SEATSConstants.TABLENAME_AIRLINE +
" WHERE F_ID = ? AND F_AL_ID = AL_ID");
SEATSConstants.TABLENAME_AIRLINE + ".* " +
" FROM " + SEATSConstants.TABLENAME_FLIGHT + ", " +
SEATSConstants.TABLENAME_AIRLINE +
" WHERE F_ID = ? AND F_AL_ID = AL_ID");

public final SQLStmt GetCustomer = new SQLStmt(
"SELECT C_BASE_AP_ID, C_BALANCE, C_SATTR00 " +
" FROM " + SEATSConstants.TABLENAME_CUSTOMER +
" WHERE C_ID = ? ");
" FROM " + SEATSConstants.TABLENAME_CUSTOMER +
" WHERE C_ID = ? ");

public final SQLStmt CheckSeat = new SQLStmt(
"SELECT R_ID " +
" FROM " + SEATSConstants.TABLENAME_RESERVATION +
" WHERE R_F_ID = ? and R_SEAT = ?");
" FROM " + SEATSConstants.TABLENAME_RESERVATION +
" WHERE R_F_ID = ? and R_SEAT = ?");

public final SQLStmt CheckCustomer = new SQLStmt(
"SELECT R_ID " +
" FROM " + SEATSConstants.TABLENAME_RESERVATION +
" WHERE R_F_ID = ? AND R_C_ID = ?");
" FROM " + SEATSConstants.TABLENAME_RESERVATION +
" WHERE R_F_ID = ? AND R_C_ID = ?");

public final SQLStmt UpdateFlight = new SQLStmt(
"UPDATE " + SEATSConstants.TABLENAME_FLIGHT +
" SET F_SEATS_LEFT = F_SEATS_LEFT - 1 " +
" WHERE F_ID = ? ");
" SET F_SEATS_LEFT = F_SEATS_LEFT - 1 " +
" WHERE F_ID = ? ");

public final SQLStmt UpdateCustomer = new SQLStmt(
"UPDATE " + SEATSConstants.TABLENAME_CUSTOMER +
" SET C_IATTR10 = C_IATTR10 + 1, " +
" C_IATTR11 = C_IATTR11 + 1, " +
" C_IATTR12 = ?, " +
" C_IATTR13 = ?, " +
" C_IATTR14 = ?, " +
" C_IATTR15 = ? " +
" WHERE C_ID = ? ");
" SET C_IATTR10 = C_IATTR10 + 1, " +
" C_IATTR11 = C_IATTR11 + 1, " +
" C_IATTR12 = ?, " +
" C_IATTR13 = ?, " +
" C_IATTR14 = ?, " +
" C_IATTR15 = ? " +
" WHERE C_ID = ? ");

public final SQLStmt UpdateFrequentFlyer = new SQLStmt(
"UPDATE " + SEATSConstants.TABLENAME_FREQUENT_FLYER +
" SET FF_IATTR10 = FF_IATTR10 + 1, " +
" FF_IATTR11 = ?, " +
" FF_IATTR12 = ?, " +
" FF_IATTR13 = ?, " +
" FF_IATTR14 = ? " +
" WHERE FF_C_ID = ? " +
" AND FF_AL_ID = ?");
" SET FF_IATTR10 = FF_IATTR10 + 1, " +
" FF_IATTR11 = ?, " +
" FF_IATTR12 = ?, " +
" FF_IATTR13 = ?, " +
" FF_IATTR14 = ? " +
" WHERE FF_C_ID = ? " +
" AND FF_AL_ID = ?");

public final SQLStmt InsertReservation = new SQLStmt(
"INSERT INTO " + SEATSConstants.TABLENAME_RESERVATION + " (" +
" R_ID, " +
" R_C_ID, " +
" R_F_ID, " +
" R_SEAT, " +
" R_PRICE, " +
" R_IATTR00, " +
" R_IATTR01, " +
" R_IATTR02, " +
" R_IATTR03, " +
" R_IATTR04, " +
" R_IATTR05, " +
" R_IATTR06, " +
" R_IATTR07, " +
" R_IATTR08 " +
") VALUES (" +
" ?, " + // R_ID
" ?, " + // R_C_ID
" ?, " + // R_F_ID
" ?, " + // R_SEAT
" ?, " + // R_PRICE
" ?, " + // R_ATTR00
" ?, " + // R_ATTR01
" ?, " + // R_ATTR02
" ?, " + // R_ATTR03
" ?, " + // R_ATTR04
" ?, " + // R_ATTR05
" ?, " + // R_ATTR06
" ?, " + // R_ATTR07
" ? " + // R_ATTR08
")");
" R_ID, " +
" R_C_ID, " +
" R_F_ID, " +
" R_SEAT, " +
" R_PRICE, " +
" R_IATTR00, " +
" R_IATTR01, " +
" R_IATTR02, " +
" R_IATTR03, " +
" R_IATTR04, " +
" R_IATTR05, " +
" R_IATTR06, " +
" R_IATTR07, " +
" R_IATTR08 " +
") VALUES (" +
" ?, " + // R_ID
" ?, " + // R_C_ID
" ?, " + // R_F_ID
" ?, " + // R_SEAT
" ?, " + // R_PRICE
" ?, " + // R_ATTR00
" ?, " + // R_ATTR01
" ?, " + // R_ATTR02
" ?, " + // R_ATTR03
" ?, " + // R_ATTR04
" ?, " + // R_ATTR05
" ?, " + // R_ATTR06
" ?, " + // R_ATTR07
" ? " + // R_ATTR08
")");

public void run(Connection conn, long r_id, String c_id, String f_id, long seatnum, double price, long[] attrs) throws SQLException {
boolean found;
Expand All @@ -125,16 +125,16 @@ public void run(Connection conn, long r_id, String c_id, String f_id, long seatn
try (ResultSet results = stmt.executeQuery()) {
found = results.next();
if (!found) {
throw new UserAbortException(ErrorType.INVALID_FLIGHT_ID +
String.format(" Invalid flight #%s", f_id));
LOG.debug("Error Type [{}]: Invalid flight {}", ErrorType.INVALID_FLIGHT_ID, f_id);
return;
}
airline_id = results.getLong(1);
seats_left = results.getLong(2);
}
}
if (seats_left <= 0) {
throw new UserAbortException(ErrorType.NO_MORE_SEATS +
String.format(" No more seats available for flight #%s", f_id));
LOG.debug("Error Type [{}]: No more seats available for flight {}", ErrorType.NO_MORE_SEATS, f_id);
return;
}
// Check if Seat is Available
try (PreparedStatement stmt = this.getPreparedStatement(conn, CheckSeat, f_id, seatnum)) {
Expand All @@ -143,8 +143,8 @@ public void run(Connection conn, long r_id, String c_id, String f_id, long seatn
}
}
if (found) {
throw new UserAbortException(ErrorType.SEAT_ALREADY_RESERVED +
String.format(" Seat %d is already reserved on flight #%s", seatnum, f_id));
LOG.debug("Error Type [{}]: Seat {} is already reserved on flight {}", ErrorType.SEAT_ALREADY_RESERVED, seatnum, f_id);
return;
}
// Check if the Customer already has a seat on this flight
try (PreparedStatement stmt = this.getPreparedStatement(conn, CheckCustomer, f_id, c_id)) {
Expand All @@ -153,8 +153,8 @@ public void run(Connection conn, long r_id, String c_id, String f_id, long seatn
}
}
if (found) {
throw new UserAbortException(ErrorType.CUSTOMER_ALREADY_HAS_SEAT +
String.format(" Customer %s already owns on a reservations on flight #%s", c_id, f_id));
LOG.debug("Error Type [{}]: Customer {} already owns on a reservations on flight {}", ErrorType.CUSTOMER_ALREADY_HAS_SEAT, c_id, f_id);
return;
}
// Get Customer Information
try (PreparedStatement preparedStatement = this.getPreparedStatement(conn, GetCustomer, c_id)) {
Expand All @@ -163,8 +163,8 @@ public void run(Connection conn, long r_id, String c_id, String f_id, long seatn
}
}
if (!found) {
throw new UserAbortException(ErrorType.INVALID_CUSTOMER_ID +
String.format(" Invalid customer id: %s / %s", c_id, new CustomerId(c_id)));
LOG.debug("Error Type [{}]: Invalid customer id: {} / {}", ErrorType.INVALID_CUSTOMER_ID, c_id, new CustomerId(c_id));
return;
}

int updated;
Expand All @@ -181,27 +181,21 @@ public void run(Connection conn, long r_id, String c_id, String f_id, long seatn
updated = preparedStatement.executeUpdate();
}
if (updated != 1) {
String msg = String.format("Failed to add reservation for flight #%s - Inserted %d records for InsertReservation", f_id, updated);
LOG.warn(msg);
throw new UserAbortException(ErrorType.VALIDITY_ERROR + " " + msg);
throw new UserAbortException(String.format("Error Type [%s]: Failed to add reservation for flight #%s - Inserted %d records for InsertReservation", ErrorType.VALIDITY_ERROR, f_id, updated));
}

try (PreparedStatement preparedStatement = this.getPreparedStatement(conn, UpdateFlight, f_id)) {
updated = preparedStatement.executeUpdate();
}
if (updated != 1) {
String msg = String.format("Failed to add reservation for flight #%s - Updated %d records for UpdateFlight", f_id, updated);
LOG.warn(msg);
throw new UserAbortException(ErrorType.VALIDITY_ERROR + " " + msg);
throw new UserAbortException(String.format("Error Type [%s]: Failed to add reservation for flight #%s - Updated %d records for UpdateFlight", ErrorType.VALIDITY_ERROR, f_id, updated));
}

try (PreparedStatement preparedStatement = this.getPreparedStatement(conn, UpdateCustomer, attrs[0], attrs[1], attrs[2], attrs[3], c_id)) {
updated = preparedStatement.executeUpdate();
}
if (updated != 1) {
String msg = String.format("Failed to add reservation for flight #%s - Updated %d records for UpdateCustomer", f_id, updated);
LOG.warn(msg);
throw new UserAbortException(ErrorType.VALIDITY_ERROR + " " + msg);
throw new UserAbortException(String.format("Error Type [%s]: Failed to add reservation for flight #%s - Updated %d records for UpdateCustomer", ErrorType.VALIDITY_ERROR, f_id, updated));
}

// We don't care if we updated FrequentFlyer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ public void run(Connection conn, String c_id, String c_id_str, Long update_ff, l
if (rs.next()) {
c_id = rs.getString(1);
} else {
throw new UserAbortException(String.format("No Customer information record found for string '%s'", c_id_str));
LOG.debug("No Customer information record found for string '{}'", c_id_str);
return;
}
}
}
Expand All @@ -92,7 +93,8 @@ public void run(Connection conn, String c_id, String c_id_str, Long update_ff, l
try (PreparedStatement preparedStatement = this.getPreparedStatement(conn, GetCustomer, c_id)) {
try (ResultSet rs = preparedStatement.executeQuery()) {
if (!rs.next()) {
throw new UserAbortException(String.format("No Customer information record found for id '%s'", c_id));
LOG.debug("No Customer information record found for id '{}'", c_id);
return;
}

base_airport = rs.getLong(3);
Expand Down Expand Up @@ -129,9 +131,7 @@ public void run(Connection conn, String c_id, String c_id_str, Long update_ff, l
updated = preparedStatement.executeUpdate();
}
if (updated != 1) {
String msg = String.format("Failed to update customer #%s - Updated %d records", c_id, updated);
LOG.warn(msg);
throw new UserAbortException(ErrorType.VALIDITY_ERROR + " " + msg);
throw new UserAbortException(String.format("Error Type [%s]: Failed to update customer #%s - Updated %d records", ErrorType.VALIDITY_ERROR, c_id, updated));
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,17 @@ public class UpdateReservation extends Procedure {

public final SQLStmt CheckSeat = new SQLStmt(
"SELECT R_ID " +
" FROM " + SEATSConstants.TABLENAME_RESERVATION +
" WHERE R_F_ID = ? and R_SEAT = ?");
" FROM " + SEATSConstants.TABLENAME_RESERVATION +
" WHERE R_F_ID = ? and R_SEAT = ?");

public final SQLStmt CheckCustomer = new SQLStmt(
"SELECT R_ID " +
" FROM " + SEATSConstants.TABLENAME_RESERVATION +
" WHERE R_F_ID = ? AND R_C_ID = ?");
" FROM " + SEATSConstants.TABLENAME_RESERVATION +
" WHERE R_F_ID = ? AND R_C_ID = ?");

private static final String BASE_SQL = "UPDATE " + SEATSConstants.TABLENAME_RESERVATION +
" SET R_SEAT = ?, %s = ? " +
" WHERE R_ID = ? AND R_C_ID = ? AND R_F_ID = ?";
" SET R_SEAT = ?, %s = ? " +
" WHERE R_ID = ? AND R_C_ID = ? AND R_F_ID = ?";

public final SQLStmt ReserveSeat0 = new SQLStmt(String.format(BASE_SQL, "R_IATTR00"));
public final SQLStmt ReserveSeat1 = new SQLStmt(String.format(BASE_SQL, "R_IATTR01"));
Expand All @@ -94,8 +94,8 @@ public void run(Connection conn, long r_id, String f_id, String c_id, long seatn
}

if (found) {
throw new UserAbortException(ErrorType.SEAT_ALREADY_RESERVED +
String.format(" Seat %d is already reserved on flight #%s", seatnum, f_id));
LOG.debug("Error Type [{}]: Seat {} is already reserved on flight {}", ErrorType.SEAT_ALREADY_RESERVED, seatnum, f_id);
return;
}

// Check if the Customer already has a seat on this flight
Expand All @@ -106,8 +106,8 @@ public void run(Connection conn, long r_id, String f_id, String c_id, long seatn
}

if (!found) {
throw new UserAbortException(ErrorType.CUSTOMER_ALREADY_HAS_SEAT +
String.format(" Customer %s does not have an existing reservation on flight #%s", c_id, f_id));
LOG.debug("Error Type [{}]: Customer {} does not have an existing reservation on flight {}", ErrorType.CUSTOMER_ALREADY_HAS_SEAT, c_id, f_id);
return;
}

// Update the seat reservation for the customer
Expand All @@ -117,13 +117,11 @@ public void run(Connection conn, long r_id, String f_id, String c_id, long seatn
}

if (updated != 1) {
String msg = String.format("Failed to update reservation on flight %s for customer #%s - Updated %d records", f_id, c_id, updated);
LOG.warn(msg);
throw new UserAbortException(ErrorType.VALIDITY_ERROR + " " + msg);
throw new UserAbortException(String.format("Error Type [%s]: Failed to update reservation on flight %s for customer #%s - Updated %d records", ErrorType.VALIDITY_ERROR, f_id, c_id, updated));
}


LOG.debug(String.format("Updated reservation on flight %s for customer %s", f_id, c_id));
LOG.debug(String.format("Updated reservation on flight %s for customer %s", f_id, c_id));

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

package com.oltpbenchmark.benchmarks.seats.util;

import java.util.regex.Pattern;

/**
* Internal Error Codes
*
Expand All @@ -35,7 +33,6 @@ public enum ErrorType {
UNKNOWN;

private final String errorCode;
private final static Pattern p = Pattern.compile("^(USER ABORT:[\\s]+)?E([\\d]{4})");

ErrorType() {
this.errorCode = String.format("E%04d", this.ordinal());
Expand Down

0 comments on commit c9f2bd6

Please sign in to comment.