use of org.voltdb.VoltTableRow in project voltdb by VoltDB.
the class LogAnalyzer method analyzeOperation.
public void analyzeOperation(String name) {
int seconds = 10;
long minuteBeforeNow = System.currentTimeMillis() - seconds * 1000;
ClientResponse response = null;
try {
response = m_voltClient.callProcedure("FetchLogRowsProcedure", minuteBeforeNow, name);
} catch (ProcCallException | IOException e) {
System.out.println("Error executing analyzer stmt: " + e.getMessage());
e.printStackTrace();
return;
}
if (response.getStatus() != ClientResponse.SUCCESS) {
System.out.println("Procedure execution failed with status " + response.getStatus());
return;
}
VoltTable[] results = response.getResults();
if (results.length == 0 || results[0].getRowCount() == 0) {
System.out.println("No entries found for " + name + " in the last " + seconds + " seconds");
return;
}
int count = 0;
long totalTime = 0;
int min = 0;
int max = 0;
System.out.println("rowCount=" + results[0].getRowCount());
for (int i = 0; i < results[0].getRowCount(); i++) {
VoltTableRow row = results[0].fetchRow(i);
int time = getTimeFromLogMesg((String) row.get(0, VoltType.STRING));
if (time >= 0) {
min = Math.min(min, time);
max = Math.max(max, time);
totalTime += time;
count++;
}
}
if (count == 0) {
System.out.println("No good log entries found for " + name + " in the last " + seconds + " seconds");
} else {
System.out.println(String.format("Operation time for %s in the last %d seconds: min=%d, max=%d, avg=%f", name, seconds, min, max, totalTime * 1.0 / count));
}
}
use of org.voltdb.VoltTableRow in project voltdb by VoltDB.
the class paymentByCustomerNameC method run.
public VoltTable[] run(short w_id, byte d_id, double h_amount, short c_w_id, byte c_d_id, String c_last, TimestampType timestamp) throws VoltAbortException {
voltQueueSQL(getCustomersByLastName, c_last, c_d_id, c_w_id);
final VoltTable customers = voltExecuteSQL()[0];
final int namecnt = customers.getRowCount();
if (namecnt == 0) {
throw new VoltAbortException("paymentByCustomerNameC: no customers with last name: " + c_last + " in warehouse: " + c_w_id + " and in district " + c_d_id);
}
final int index = (namecnt - 1) / 2;
final VoltTableRow customer = customers.fetchRow(index);
final int c_id = (int) customer.getLong(C_ID_IDX);
return processPayment(w_id, d_id, c_w_id, c_d_id, c_id, h_amount, customer, timestamp);
}
use of org.voltdb.VoltTableRow in project voltdb by VoltDB.
the class neworder method run.
public VoltTable[] run(short w_id, byte d_id, int c_id, TimestampType timestamp, int[] item_id, short[] supware, int[] quantity) throws VoltAbortException {
assert item_id.length > 0;
assert item_id.length == supware.length;
assert item_id.length == quantity.length;
// CHEAT: Validate all items to see if we will need to abort.
// Also determine if this is an all local order or not
final VoltTableRow[] items = new VoltTableRow[item_id.length];
boolean isAllLocal = true;
for (int i = 0; i < item_id.length; ++i) {
isAllLocal = isAllLocal && supware[i] == w_id;
voltQueueSQL(getItemInfo, item_id[i]);
}
voltQueueSQL(getWarehouseTaxRate, w_id);
voltQueueSQL(getDistrict, d_id, w_id);
voltQueueSQL(getCustomer, w_id, d_id, c_id);
final VoltTable[] itemresults = voltExecuteSQL();
assert itemresults.length == item_id.length + 3;
for (int i = 0; i < item_id.length; ++i) {
if (itemresults[i].getRowCount() == 0) {
// TPCC defines 1% of neworder gives a wrong itemid, causing rollback.
throw new VoltAbortException(Constants.INVALID_ITEM_MESSAGE);
}
assert itemresults[i].getRowCount() == 1;
items[i] = itemresults[i].fetchRow(0);
}
//final VoltTable[] backgroundInfo = executeSQL();
VoltTable customer = itemresults[item_id.length + 2];
final double w_tax = itemresults[item_id.length].fetchRow(0).getDouble(0);
final int D_TAX_COL = 0, D_NEXT_O_ID = 1;
final int C_DISCOUNT = 0;
final VoltTableRow tempRow = itemresults[item_id.length + 1].fetchRow(0);
final double d_tax = tempRow.getDouble(D_TAX_COL);
final double c_discount = itemresults[item_id.length + 2].fetchRow(0).getDouble(C_DISCOUNT);
final long d_next_o_id = tempRow.getLong(D_NEXT_O_ID);
final long ol_cnt = item_id.length;
final long all_local = isAllLocal ? 1 : 0;
voltQueueSQL(incrementNextOrderId, d_next_o_id + 1, d_id, w_id);
voltQueueSQL(createOrder, d_next_o_id, d_id, w_id, c_id, timestamp, Constants.NULL_CARRIER_ID, ol_cnt, all_local);
voltQueueSQL(createNewOrder, d_next_o_id, d_id, w_id);
voltExecuteSQL();
// values the client is missing: i_name, s_quantity, brand_generic, i_price, ol_amount
final VoltTable item_data = item_data_template.clone(2048);
double total = 0;
for (int i = 0; i < item_id.length; ++i) {
final long ol_supply_w_id = supware[i];
final long ol_i_id = item_id[i];
// One getStockInfo SQL statement for each district
voltQueueSQL(getStockInfo[d_id - 1], ol_i_id, ol_supply_w_id);
}
final VoltTable[] stockresults = voltExecuteSQL();
assert stockresults.length == item_id.length;
for (int i = 0; i < item_id.length; ++i) {
final long ol_number = i + 1;
final long ol_supply_w_id = supware[i];
final long ol_i_id = item_id[i];
final long ol_quantity = quantity[i];
assert stockresults[i].getRowCount() == 1 : "Cannot find stock info for item; should not happen with valid database";
final VoltTableRow itemInfo = items[i];
final VoltTableRow stockInfo = stockresults[i].fetchRow(0);
final int I_PRICE = 0, I_NAME = 1, I_DATA = 2;
final byte[] i_name = itemInfo.getStringAsBytes(I_NAME);
final byte[] i_data = itemInfo.getStringAsBytes(I_DATA);
final double i_price = itemInfo.getDouble(I_PRICE);
final int S_QUANTITY = 0, S_DATA = 1, S_YTD = 2, S_ORDER_CNT = 3, S_REMOTE_CNT = 4, S_DIST_XX = 5;
long s_quantity = stockInfo.getLong(S_QUANTITY);
long s_ytd = stockInfo.getLong(S_YTD);
long s_order_cnt = stockInfo.getLong(S_ORDER_CNT);
long s_remote_cnt = stockInfo.getLong(S_REMOTE_CNT);
final byte[] s_data = stockInfo.getStringAsBytes(S_DATA);
// Fetches data from the s_dist_[d_id] column
final byte[] s_dist_xx = stockInfo.getStringAsBytes(S_DIST_XX);
// Update stock
s_ytd += ol_quantity;
if (s_quantity >= ol_quantity + 10) {
s_quantity = s_quantity - ol_quantity;
} else {
s_quantity = s_quantity + 91 - ol_quantity;
}
s_order_cnt++;
if (ol_supply_w_id != w_id)
s_remote_cnt++;
// TODO(evanj): Faster to do s_ytd and s_order_cnt increment in SQL?
// Saves fetching those columns the first time
voltQueueSQL(updateStock, s_quantity, s_ytd, s_order_cnt, s_remote_cnt, ol_i_id, ol_supply_w_id);
byte[] brand_generic;
if (indexOf(i_data, Constants.ORIGINAL_BYTES) != -1 && indexOf(s_data, Constants.ORIGINAL_BYTES) != -1) {
brand_generic = new byte[] { 'B' };
} else {
brand_generic = new byte[] { 'G' };
}
//Transaction profile states to use "ol_quantity * i_price"
final double ol_amount = ol_quantity * i_price;
total += ol_amount;
voltQueueSQL(createOrderLine, d_next_o_id, d_id, w_id, ol_number, ol_i_id, ol_supply_w_id, timestamp, ol_quantity, ol_amount, s_dist_xx);
// Add the info to be returned
item_data.addRow(i_name, s_quantity, brand_generic, i_price, ol_amount);
}
voltExecuteSQL();
// Adjust the total for the discount
total *= (1 - c_discount) * (1 + w_tax + d_tax);
// pack up values the client is missing (see TPC-C 2.4.3.5)
final VoltTable misc = misc_template.clone(256);
misc.addRow(w_tax, d_tax, d_next_o_id, total);
return new VoltTable[] { customer, misc, item_data };
}
use of org.voltdb.VoltTableRow in project voltdb by VoltDB.
the class paymentByCustomerNameW method run.
public VoltTable[] run(short w_id, byte d_id, double h_amount, short c_w_id, byte c_d_id, String c_last, TimestampType timestamp) throws VoltAbortException {
// retrieve c_id from replicated CUSTOMER_NAME table
voltQueueSQL(getCidByLastName, c_last, c_d_id, c_w_id);
final VoltTable result = voltExecuteSQL()[0];
final int namecnt = result.getRowCount();
if (namecnt == 0) {
throw new VoltAbortException("paymentByCustomerNameW: no customers with last name: " + c_last + " in warehouse: " + c_w_id + " and in district " + c_d_id);
}
final int index = (namecnt - 1) / 2;
final VoltTableRow customer = result.fetchRow(index);
final long c_id = customer.getLong(0);
return processPayment(w_id, d_id, h_amount, c_w_id, c_d_id, c_id, timestamp);
}
use of org.voltdb.VoltTableRow in project voltdb by VoltDB.
the class UpdateBaseProc method doWorkInProcAdHoc.
@SuppressWarnings("deprecation")
protected VoltTable[] doWorkInProcAdHoc(byte cid, long rid, byte[] value, byte shouldRollback) {
voltQueueSQLExperimental("SELECT * FROM replicated r INNER JOIN dimension d ON r.cid=d.cid WHERE r.cid = ? ORDER BY r.cid, r.rid desc;", cid);
voltQueueSQLExperimental("SELECT * FROM adhocr ORDER BY ts DESC, id LIMIT 1");
voltQueueSQLExperimental("SELECT * FROM replview WHERE cid = ? ORDER BY cid desc;", cid);
VoltTable[] results = voltExecuteSQL();
VoltTable data = results[0];
VoltTable adhoc = results[1];
VoltTable view = results[2];
final long txnid = getUniqueId();
final long ts = getTransactionTime().getTime();
long prevtxnid = 0;
long prevrid = 0;
long cnt = 0;
// read data modified by AdHocMayhemThread for later insertion
final long adhocInc = adhoc.getRowCount() > 0 ? adhoc.fetchRow(0).getLong("inc") : 0;
final long adhocJmp = adhoc.getRowCount() > 0 ? adhoc.fetchRow(0).getLong("jmp") : 0;
// compute the cheesy checksum of all of the table's contents based on
// this cid to subsequently store in the new row
final long cidallhash = MiscUtils.cheesyBufferCheckSum(data.getBuffer());
// get the most recent row's data
int rowCount = data.getRowCount();
if (rowCount != 0) {
VoltTableRow row = data.fetchRow(0);
cnt = row.getLong("cnt") + 1;
prevtxnid = row.getLong("txnid");
prevrid = row.getLong("rid");
}
validateCIDData(data, view, getClass().getName());
// check the rids monotonically increase
if (prevrid >= rid) {
throw new VoltAbortException(getClass().getName() + " previous rid " + prevrid + " >= than current rid " + rid + " for cid " + cid);
}
voltQueueSQLExperimental("INSERT INTO replicated (txnid, prevtxnid, ts, cid, cidallhash, rid, cnt, adhocinc, adhocjmp, value) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);", txnid, prevtxnid, ts, cid, cidallhash, rid, cnt, adhocInc, adhocJmp, value);
voltQueueSQLExperimental("INSERT INTO replicated_export VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);", txnid, prevtxnid, ts, cid, cidallhash, rid, cnt, adhocInc, adhocJmp, value);
voltQueueSQLExperimental("DELETE FROM replicated WHERE cid = ? and cnt < ?;", cid, cnt - 10);
voltQueueSQLExperimental("SELECT * FROM replicated r INNER JOIN dimension d ON r.cid=d.cid WHERE r.cid = ? ORDER BY r.cid, r.rid desc;", cid);
voltQueueSQLExperimental("SELECT * FROM replview WHERE cid = ? ORDER BY cid desc;", cid);
VoltTable[] retval = voltExecuteSQL();
// Verify that our update happened. The client is reporting data errors on this validation
// not seen by the server, hopefully this will bisect where they're occurring.
data = retval[3];
view = retval[4];
validateCIDData(data, view, getClass().getName());
VoltTableRow row = data.fetchRow(0);
if (row.getVarbinary("value").length == 0)
throw new VoltAbortException("Value column contained no data in UpdateBaseProc");
if (shouldRollback != 0) {
throw new VoltAbortException("EXPECTED ROLLBACK");
}
return retval;
}
Aggregations