use of org.voltdb.VoltTable in project voltdb by VoltDB.
the class AsyncBenchmark method runBenchmark.
/**
* Core benchmark code.
* Connect. Initialize. Run the loop. Cleanup. Print Results.
*
* @throws Exception if anything unexpected happens.
*/
public void runBenchmark() throws Exception {
log.info(HORIZONTAL_RULE);
log.info(" Setup & Initialization");
log.info(HORIZONTAL_RULE);
// connect to one or more servers, loop until success
connect();
VoltTable[] rowResults = null;
VoltTable[] replicatedResults = null;
boolean succeeded = false;
// If server fails during initialization, try again
while (!succeeded) {
Client initClient = clients.get(0);
try {
// initialize using synchronous call
initClient.callProcedure("Initialize");
ClientResponse rowResp = initClient.callProcedure("getLastRow");
rowResults = rowResp.getResults();
assert (rowResp.getStatus() == ClientResponse.SUCCESS);
ClientResponse replicatedRowResp = initClient.callProcedure("getLastReplicatedRow");
replicatedResults = replicatedRowResp.getResults();
assert (replicatedRowResp.getStatus() == ClientResponse.SUCCESS);
succeeded = true;
} catch (Exception e) {
log.error("Exception on init. Will sleep.", e);
sleepUntilConnected(initClient, System.currentTimeMillis() + config.duration * 1000);
}
}
// total of 127 cids
final int cidCount = 127;
final long windowPerCid = config.windowsize / cidCount;
// rids per cid
final Map<Integer, Long> rids = new HashMap<Integer, Long>();
// reset all cids to 0 and initialize inFlight queues
for (int i = -1; i < cidCount; i++) {
rids.put(i, 0l);
}
// populate the rids with values from previous run
while (rowResults[0].advanceRow()) {
long cid = rowResults[0].getLong("cid");
long last_rid = rowResults[0].getLong("last_rid");
rids.put((int) cid, last_rid + 1);
}
rids.put(-1, replicatedResults[0].asScalarLong() + 1);
log.info(HORIZONTAL_RULE);
log.info("Starting Benchmark");
log.info(HORIZONTAL_RULE);
java.util.Random r = new java.util.Random(2);
// print periodic statistics to the console
benchmarkStartTS = System.currentTimeMillis();
schedulePeriodicStats();
// Run the benchmark loop for the requested duration
// The throughput may be throttled depending on client configuration
final long benchmarkEndTime = System.currentTimeMillis() + (1000l * config.duration);
while (benchmarkEndTime > System.currentTimeMillis()) {
int cid;
if (r.nextDouble() < config.multisingleratio) {
// MP uses cid -1
cid = -1;
} else {
cid = (byte) r.nextInt(cidCount);
}
long rid = rids.get(cid);
// txns for the same cid go to the same client
Client client = null;
try {
if (cid == -1) {
client = clients.get(0);
// skip this work if the client is not connected
if (client.getConnectedHostList().size() == 0) {
continue;
}
// update the replicated table
try {
client.callProcedure(new updateReplicatedCallback(), "updateReplicated", rid);
} catch (NoConnectionsException e) {
log.error("ClientThread got NoConnectionsException on updateReplicated proc call.");
}
} else {
client = clients.get(cid % clients.size());
// skip this work if the client is not connected
if (client.getConnectedHostList().size() == 0) {
continue;
}
// asynchronously call the "doTxn" procedure
try {
client.callProcedure(new doTxnCallback(), "doTxn", cid, rid, rid > windowPerCid ? rid - windowPerCid : 0, processor.generateForStore().getStoreValue());
} catch (NoConnectionsException e) {
log.error("ClientThread got NoConnectionsException on doTxn proc call.");
}
}
} catch (Exception e) {
log.error("Benchark had a unexpected exception", e);
System.exit(-1);
}
rids.put(cid, rid + 1);
}
// cancel periodic stats printing
timer.cancel();
shutdown.set(true);
/* don't wait for a proper cleanup just go away the system may not be healthy -pr
// block until all outstanding txns return
for (Client client : clients) {
client.drain();
client.close();
}*/
log.info(HORIZONTAL_RULE);
log.info("Benchmark Complete");
}
use of org.voltdb.VoltTable in project voltdb by VoltDB.
the class Initialize method run.
public long run() {
voltQueueSQL(checkStmt, EXPECT_ZERO_OR_ONE_ROW);
VoltTable result = voltExecuteSQL()[0];
// if the data is initialized, return the current count
if (result.getRowCount() != 0) {
result.advanceRow();
return result.getLong("rid");
}
// initialize the data using the txnId
@SuppressWarnings("deprecation") long txnId = DeprecatedProcedureAPIAccess.getVoltPrivateRealTransactionId(this);
long uniqueId = getUniqueId();
voltQueueSQL(insertStmt, EXPECT_SCALAR_MATCH(1), txnId, uniqueId, -1, 0);
voltExecuteSQL(true);
// return the rid
return 0;
}
use of org.voltdb.VoltTable 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.VoltTable 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.VoltTable 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);
}
Aggregations