use of org.voltdb.VoltTable 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;
}
use of org.voltdb.VoltTable in project voltdb by VoltDB.
the class UpdateClassesBenchmark method runBenchmark.
/**
* Core benchmark code.
* Connect. Initialize. Run the loop. Cleanup. Print Results.
*
* @throws Exception if anything unexpected happens.
*/
public void runBenchmark() throws Exception {
// connect to one or more servers, loop until success
connect(config.servers);
FileWriter fw = null;
if ((config.statsfile != null) && (config.statsfile.length() != 0)) {
fw = new FileWriter(config.statsfile);
}
System.out.print(HORIZONTAL_RULE);
System.out.println("\nRunning Benchmark for " + config.name);
System.out.println(HORIZONTAL_RULE);
VoltTable vt = null;
String dirPath = config.dir;
String jarPath = dirPath + "/jars/";
byte[] jarBytes = readFileIntoByteArray(jarPath + "uac_base.jar");
// setup the base case: 500 tables with 1000 procedures
String stmts = new String(readFileIntoByteArray(jarPath + "stmts_base.txt"));
UACTime uacTime = doUpdateClassesWork(client, null, jarBytes, null, stmts);
System.out.println(String.format("Created %d procedure using %f ms", config.procedurecount, toMillis(uacTime.totalTime)));
ProcBenchmark bench = fromString(config.name);
// Benchmark start time
BenchmarkResult res = null;
// TODO: refactor some of these codes when we have DEL/UPD benchmarks
if (bench == ProcBenchmark.ADD) {
res = runAdd(client, config, jarPath);
} else if (bench == ProcBenchmark.ADD_BATCH) {
res = runAddBatch(client, config, jarPath);
} else if (bench == ProcBenchmark.DELETE) {
res = runDel(client, config, jarPath);
} else if (bench == ProcBenchmark.DELETE_BATCH) {
res = runDelBatch(client, config, jarPath);
} else if (bench == ProcBenchmark.UPDATE) {
res = runUpd(client, config, jarPath);
}
double avg = toMillis(res.sum / config.invocations);
System.out.printf("\n(Benchmark %s ran %d times in average %f ms, max %f ms, " + "mp block average %f ms)\n", config.name, config.invocations, avg, toMillis(res.max), toMillis(res.bsum / config.invocations));
//retrieve stats
ClientStats stats = fullStatsContext.fetch().getStats();
// write stats to file
//client.writeSummaryCSV(stats, config.statsfile);
// name, duration,invocations/tps,avg block time,latmax,lat95,lat99
fw.append(String.format("%s,-1,%f,0,0,%f,%f,0,0,0,0,0,0\n", config.name, avg, toMillis(res.bsum / config.invocations), toMillis(res.max)));
fw.flush();
fw.close();
// block until all outstanding txns return
client.drain();
// close down the client connections
client.close();
}
use of org.voltdb.VoltTable in project voltdb by VoltDB.
the class UpdateBaseProc method doWork.
protected VoltTable[] doWork(SQLStmt getCIDData, SQLStmt cleanUp, SQLStmt insert, SQLStmt export, SQLStmt getAdHocData, SQLStmt getViewData, byte cid, long rid, byte[] value, byte shouldRollback, boolean usestreamviews) {
voltQueueSQL(getCIDData, cid);
voltQueueSQL(getAdHocData);
voltQueueSQL(d_getCount, cid);
voltQueueSQL(getViewData, cid);
VoltTable[] results = voltExecuteSQL();
VoltTable data = results[0];
VoltTable adhoc = results[1];
VoltTable dim = results[2];
VoltTable view = results[3];
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);
}
voltQueueSQL(insert, txnid, prevtxnid, ts, cid, cidallhash, rid, cnt, adhocInc, adhocJmp, value);
voltQueueSQL(export, txnid, prevtxnid, ts, cid, cidallhash, rid, cnt, adhocInc, adhocJmp, value);
voltQueueSQL(cleanUp, cid, cnt - 10);
voltQueueSQL(getCIDData, cid);
voltQueueSQL(getViewData, cid);
assert dim.getRowCount() == 1;
VoltTable[] retval = voltExecuteSQL();
// Is this comment below now obsolete and can be removed?
// 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];
VoltTableRow row = data.fetchRow(0);
if (row.getVarbinary("value").length == 0)
throw new VoltAbortException("Value column contained no data in UpdateBaseProc");
validateCIDData(data, view, getClass().getName());
if (usestreamviews) {
// insert to export table done, check corresponding materialized view
validateView(cid, cnt, "insert");
// update export materialized view & validate
// arbitrary. could use random but really doesn't matter
int someData = 5;
voltQueueSQL(p_updateExViewData, someData, someData + 1, someData + 2, someData + 3, cid);
voltQueueSQL(p_updateExViewShadowData, someData, someData + 1, someData + 2, someData + 3, cid);
voltExecuteSQL();
validateView(cid, cnt, "update");
// delete from export materialized view & validate
voltQueueSQL(p_deleteExViewData, cid);
voltQueueSQL(p_deleteExViewShadowData, cid);
voltExecuteSQL();
validateView(cid, cnt, "delete");
}
if (shouldRollback != 0) {
throw new VoltAbortException("EXPECTED ROLLBACK");
}
return retval;
}
use of org.voltdb.VoltTable in project voltdb by VoltDB.
the class SwapTablesBase method run.
public VoltTable[] run(long p, byte shouldRollback, String storedProcName) {
// and used before the SWAP TABLES (as ad hoc DML) feature is complete
if (USE_FAKE_SWAP) {
return runFakeSwap(p, shouldRollback, storedProcName);
}
// Execute the SWAP TABLES query, with SELECT COUNT(*) queries before and after
voltQueueSQL(count_tru);
voltQueueSQL(count_swap);
voltQueueSQL(scancount_tru);
voltQueueSQL(scancount_swap);
// voltQueueSQL(swap);
voltQueueSQL(count_tru);
voltQueueSQL(count_swap);
voltQueueSQL(scancount_tru);
voltQueueSQL(scancount_swap);
VoltTable[] results = voltExecuteSQL(true);
// Check that the total (opt) counts of the two tables have been swapped
VoltTable data = results[0];
VoltTableRow row = data.fetchRow(0);
long truCountBefore = row.getLong(0);
data = results[1];
row = data.fetchRow(0);
long swapCountBefore = row.getLong(0);
data = results[5];
row = data.fetchRow(0);
long truCountAfter = row.getLong(0);
data = results[6];
row = data.fetchRow(0);
long swapCountAfter = row.getLong(0);
if (truCountBefore != swapCountAfter || swapCountBefore != truCountAfter) {
throw new VoltAbortException("after swap (opt) counts (" + truCountAfter + "," + swapCountAfter + ") do not match reverse of those before (" + truCountBefore + "," + swapCountBefore + ")");
}
// Check that the partial (scan) counts of the two tables have been swapped
data = results[2];
row = data.fetchRow(0);
long truScanCountBefore = row.getLong(0);
data = results[3];
row = data.fetchRow(0);
long swapScanCountBefore = row.getLong(0);
data = results[7];
row = data.fetchRow(0);
long truScanCountAfter = row.getLong(0);
data = results[8];
row = data.fetchRow(0);
long swapScanCountAfter = row.getLong(0);
if (truScanCountBefore != swapScanCountAfter || swapScanCountBefore != truScanCountAfter) {
throw new VoltAbortException("after swap (scan) counts (" + truScanCountAfter + "," + swapScanCountAfter + ") do not match reverse of those before (" + truScanCountBefore + "," + swapScanCountBefore + ")");
}
if (shouldRollback != 0) {
throw new VoltAbortException("EXPECTED SWAP ROLLBACK");
}
return results;
}
use of org.voltdb.VoltTable in project voltdb by VoltDB.
the class SwapTablesBase method runFakeSwap.
// TODO: this is a temporary method, so that the test code can be tested
// and used before the SWAP TABLES (as ad hoc DML) feature is complete.
private VoltTable[] runFakeSwap(long p, byte shouldRollback, String storedProcName) {
// Execute the SWAP TABLES query, with SELECT COUNT(*) queries before and after
voltQueueSQL(count_tru);
voltQueueSQL(count_swap);
voltQueueSQL(scancount_tru);
voltQueueSQL(scancount_swap);
// "Fake" swap, using a temp table:
voltQueueSQL(swap6);
voltQueueSQL(swap0);
voltQueueSQL(swap6);
voltQueueSQL(swap1);
voltQueueSQL(swap2);
voltQueueSQL(swap3);
voltQueueSQL(swap4);
voltQueueSQL(swap5);
voltQueueSQL(swap6);
voltQueueSQL(swap0);
voltQueueSQL(swap6);
voltQueueSQL(count_tru);
voltQueueSQL(count_swap);
voltQueueSQL(scancount_tru);
voltQueueSQL(scancount_swap);
VoltTable[] results = voltExecuteSQL(true);
// Check that the total (opt) counts of the two tables have been swapped
VoltTable data = results[0];
VoltTableRow row = data.fetchRow(0);
long truCountBefore = row.getLong(0);
data = results[1];
row = data.fetchRow(0);
long swapCountBefore = row.getLong(0);
data = results[15];
row = data.fetchRow(0);
long truCountAfter = row.getLong(0);
data = results[16];
row = data.fetchRow(0);
long swapCountAfter = row.getLong(0);
if (truCountBefore != swapCountAfter || swapCountBefore != truCountAfter) {
throw new VoltAbortException("after swap (opt) counts (" + truCountAfter + "," + swapCountAfter + ") do not match reverse of those before (" + truCountBefore + "," + swapCountBefore + ")");
}
// Check that the partial (scan) counts of the two tables have been swapped
data = results[2];
row = data.fetchRow(0);
long truScanCountBefore = row.getLong(0);
data = results[3];
row = data.fetchRow(0);
long swapScanCountBefore = row.getLong(0);
data = results[17];
row = data.fetchRow(0);
long truScanCountAfter = row.getLong(0);
data = results[18];
row = data.fetchRow(0);
long swapScanCountAfter = row.getLong(0);
if (truScanCountBefore != swapScanCountAfter || swapScanCountBefore != truScanCountAfter) {
throw new VoltAbortException("after swap (scan) counts (" + truScanCountAfter + "," + swapScanCountAfter + ") do not match reverse of those before (" + truScanCountBefore + "," + swapScanCountBefore + ")");
}
// TODO: temporary debug print:
data = results[4];
row = data.fetchRow(0);
long countTemp0 = row.getLong(0);
data = results[6];
row = data.fetchRow(0);
long countTemp1 = row.getLong(0);
data = results[12];
row = data.fetchRow(0);
long countTemp2 = row.getLong(0);
data = results[14];
row = data.fetchRow(0);
long countTemp3 = row.getLong(0);
System.out.println("In " + storedProcName + ": shouldRollback: " + shouldRollback + "\n truCountBefore: " + truCountBefore + " swapCountBefore: " + swapCountBefore + "; truCountAfter: " + truCountAfter + " swapCountAfter: " + swapCountAfter + "\n truScanCountBefore: " + truScanCountBefore + " swapScanCountBefore: " + swapScanCountBefore + "; truScanCountAfter: " + truScanCountAfter + " swapScanCountAfter: " + swapScanCountAfter + "\n countTemp0: " + countTemp0 + " countTemp1: " + countTemp1 + "; countTemp2: " + countTemp2 + " countTemp3: " + countTemp3);
if (shouldRollback != 0) {
throw new VoltAbortException("EXPECTED SWAP ROLLBACK");
}
return results;
}
Aggregations