use of org.voltdb.VoltTable in project voltdb by VoltDB.
the class InsertImport2 method run.
public long run(long key, long value, byte rowid_group, byte type_null_tinyint, byte type_not_null_tinyint, short type_null_smallint, short type_not_null_smallint, int type_null_integer, int type_not_null_integer, long type_null_bigint, long type_not_null_bigint, TimestampType type_null_timestamp, TimestampType type_not_null_timestamp, double type_null_float, double type_not_null_float, BigDecimal type_null_decimal, BigDecimal type_not_null_decimal, String type_null_varchar25, String type_not_null_varchar25, String type_null_varchar128, String type_not_null_varchar128, String type_null_varchar1024, String type_not_null_varchar1024) {
// column positions, used in "get" calls below
final int TYPE_NULL_TINYINT = 3;
final int TYPE_NOT_NULL_TINYINT = 4;
final int TYPE_NULL_SMALLINT = 5;
final int TYPE_NOT_NULL_SMALLINT = 6;
final int TYPE_NULL_INTEGER = 7;
final int TYPE_NOT_NULL_INTEGER = 8;
final int TYPE_NULL_BIGINT = 9;
final int TYPE_NOT_NULL_BIGINT = 10;
final int TYPE_NULL_TIMESTAMP = 11;
final int TYPE_NOT_NULL_TIMESTAMP = 12;
final int TYPE_NULL_FLOAT = 13;
final int TYPE_NOT_NULL_FLOAT = 14;
final int TYPE_NULL_DECIMAL = 15;
final int TYPE_NOT_NULL_DECIMAL = 16;
final int TYPE_NULL_VARCHAR25 = 17;
final int TYPE_NOT_NULL_VARCHAR25 = 18;
final int TYPE_NULL_VARCHAR128 = 19;
final int TYPE_NOT_NULL_VARCHAR128 = 20;
final int TYPE_NULL_VARCHAR1024 = 21;
final int TYPE_NOT_NULL_VARCHAR1024 = 22;
// find mirror row that matches import
voltQueueSQL(selectMirrorRow, key, value);
VoltTable[] mirrorResults = voltExecuteSQL();
VoltTable rowData = mirrorResults[0];
long deletedCount = 0;
boolean rowCheckOk = true;
if (rowData.getRowCount() == 1) {
// we already checked key and value via SELECT; now work through the rest of the types
// not_null rows are simple compares. nullable types need to check for null as well
byte ntiVal = (byte) rowData.fetchRow(0).get(TYPE_NULL_TINYINT, VoltType.TINYINT);
if (ntiVal != type_null_tinyint) {
rowCheckOk = reportMismatch("type_null_tinyint", String.valueOf(type_null_tinyint), String.valueOf(ntiVal));
}
byte tiVal = (byte) rowData.fetchRow(0).get(TYPE_NOT_NULL_TINYINT, VoltType.TINYINT);
if (tiVal != type_not_null_tinyint) {
rowCheckOk = reportMismatch("type_not_null_tinyint", String.valueOf(type_not_null_tinyint), String.valueOf(tiVal));
}
short nsiVal = (short) rowData.fetchRow(0).get(TYPE_NULL_SMALLINT, VoltType.SMALLINT);
if (nsiVal != type_null_smallint) {
rowCheckOk = reportMismatch("type_null_smallint", String.valueOf(type_null_smallint), String.valueOf(nsiVal));
}
short siVal = (short) rowData.fetchRow(0).get(TYPE_NOT_NULL_SMALLINT, VoltType.SMALLINT);
if (siVal != type_not_null_smallint) {
rowCheckOk = reportMismatch("type_not_null_smallint", String.valueOf(type_not_null_smallint), String.valueOf(siVal));
}
int nintVal = (int) rowData.fetchRow(0).get(TYPE_NULL_INTEGER, VoltType.INTEGER);
if (nintVal != type_null_integer) {
rowCheckOk = reportMismatch("type_null_integer", String.valueOf(type_null_integer), String.valueOf(nintVal));
}
int intVal = (int) rowData.fetchRow(0).get(TYPE_NOT_NULL_INTEGER, VoltType.INTEGER);
if (intVal != type_not_null_integer) {
rowCheckOk = reportMismatch("type_not_null_integer", String.valueOf(type_not_null_integer), String.valueOf(intVal));
}
long nbigVal = (long) rowData.fetchRow(0).get(TYPE_NULL_BIGINT, VoltType.BIGINT);
if (nbigVal != type_null_bigint) {
rowCheckOk = reportMismatch("type_null_bigint", String.valueOf(type_null_bigint), String.valueOf(nbigVal));
}
long bigVal = (long) rowData.fetchRow(0).get(TYPE_NOT_NULL_BIGINT, VoltType.BIGINT);
if (bigVal != type_not_null_bigint) {
rowCheckOk = reportMismatch("type_not_null_bigint", String.valueOf(type_not_null_bigint), String.valueOf(bigVal));
}
TimestampType ntsVal = (TimestampType) rowData.fetchRow(0).get(TYPE_NULL_TIMESTAMP, VoltType.TIMESTAMP);
if (!(ntsVal == null && type_null_timestamp == null) && !ntsVal.equals(type_null_timestamp)) {
rowCheckOk = reportMismatch("type_null_timestamp", type_null_timestamp.toString(), ntsVal.toString());
}
TimestampType tsVal = (TimestampType) rowData.fetchRow(0).get(TYPE_NOT_NULL_TIMESTAMP, VoltType.TIMESTAMP);
if (!tsVal.equals(type_not_null_timestamp)) {
rowCheckOk = reportMismatch("type_not_null_timestamp", type_not_null_timestamp.toString(), tsVal.toString());
}
double nfloatVal = (double) rowData.fetchRow(0).get(TYPE_NULL_FLOAT, VoltType.FLOAT);
if (nfloatVal != type_null_float) {
rowCheckOk = reportMismatch("type_null_float", String.valueOf(type_null_float), String.valueOf(nfloatVal));
}
double floatVal = (double) rowData.fetchRow(0).get(TYPE_NOT_NULL_FLOAT, VoltType.FLOAT);
if (floatVal != type_not_null_float) {
rowCheckOk = reportMismatch("type_not_null_float", String.valueOf(type_not_null_float), String.valueOf(floatVal));
}
BigDecimal ndecimalVal = (BigDecimal) rowData.fetchRow(0).get(TYPE_NULL_DECIMAL, VoltType.DECIMAL);
if (!(ndecimalVal == null && type_null_decimal == null) && !ndecimalVal.equals(type_null_decimal)) {
rowCheckOk = reportMismatch("type_null_decimal", type_null_decimal.toString(), ndecimalVal.toString());
}
BigDecimal decimalVal = (BigDecimal) rowData.fetchRow(0).get(TYPE_NOT_NULL_DECIMAL, VoltType.DECIMAL);
if (!decimalVal.equals(type_not_null_decimal)) {
rowCheckOk = reportMismatch("type_not_null_decimal", type_not_null_decimal.toString(), decimalVal.toString());
}
String nstring25Val = (String) rowData.fetchRow(0).get(TYPE_NULL_VARCHAR25, VoltType.STRING);
if (!(nstring25Val == null && type_null_varchar25 == null) && !nstring25Val.equals(type_null_varchar25)) {
rowCheckOk = reportMismatch("type_null_varchar25", type_null_varchar25, nstring25Val);
}
String string25Val = (String) rowData.fetchRow(0).get(TYPE_NOT_NULL_VARCHAR25, VoltType.STRING);
if (!string25Val.equals(type_not_null_varchar25)) {
rowCheckOk = reportMismatch("type_not_null_varchar25", type_not_null_varchar25, string25Val);
}
String nstring128Val = (String) rowData.fetchRow(0).get(TYPE_NULL_VARCHAR128, VoltType.STRING);
if (!(nstring128Val == null && type_null_varchar128 == null) && !nstring128Val.equals(type_null_varchar128)) {
rowCheckOk = reportMismatch("type_null_varchar128", type_null_varchar128, nstring128Val);
}
String string128Val = (String) rowData.fetchRow(0).get(TYPE_NOT_NULL_VARCHAR128, VoltType.STRING);
if (!string128Val.equals(type_not_null_varchar128)) {
rowCheckOk = reportMismatch("type_not_null_varchar128", type_not_null_varchar128, string128Val);
}
String nstring1024Val = (String) rowData.fetchRow(0).get(TYPE_NULL_VARCHAR1024, VoltType.STRING);
if (!(nstring1024Val == null && type_null_varchar1024 == null) && !nstring1024Val.equals(type_null_varchar1024)) {
rowCheckOk = reportMismatch("type_null_varchar1024", type_null_varchar1024, nstring1024Val);
}
String string1024Val = (String) rowData.fetchRow(0).get(TYPE_NOT_NULL_VARCHAR1024, VoltType.STRING);
if (!string1024Val.equals(type_not_null_varchar1024)) {
rowCheckOk = reportMismatch("type_not_null_varchar1024", type_not_null_varchar1024, string1024Val);
}
if (rowCheckOk) {
// delete the row
voltQueueSQL(deleteMirrorRow, EXPECT_SCALAR_LONG, key, value);
deletedCount = voltExecuteSQL()[0].asScalarLong();
} else {
// there was a data mismatch; set VALUE_MISMATCH, which will be noticed by client
voltQueueSQL(updateMismatch, key, value, 1);
voltExecuteSQL();
return 0;
}
if (deletedCount != 1) {
System.out.println("Rows deleted: " + deletedCount + ", key: " + key + ", value: " + value);
}
} else {
// add to import table as indicator of dupe or mismatch
voltQueueSQL(importInsert, key, value, rowid_group, type_null_tinyint, type_not_null_tinyint, type_null_smallint, type_not_null_smallint, type_null_integer, type_not_null_integer, type_null_bigint, type_not_null_bigint, type_null_timestamp, type_not_null_timestamp, type_null_float, type_not_null_float, type_null_decimal, type_not_null_decimal, type_null_varchar25, type_not_null_varchar25, type_null_varchar128, type_not_null_varchar128, type_null_varchar1024, type_not_null_varchar1024);
voltExecuteSQL();
}
// update the counts tables so we can track progress and results
// since the SP can't return results to the client
voltQueueSQL(selectCounts);
VoltTable[] result = voltExecuteSQL();
VoltTable data = result[0];
long nrows = data.getRowCount();
if (nrows > 0) {
long ck = data.fetchRow(0).getLong(0);
voltQueueSQL(updateCounts, deletedCount, ck);
voltExecuteSQL(true);
} else {
voltQueueSQL(insertCounts, key, deletedCount);
voltExecuteSQL(true);
}
return 0;
}
use of org.voltdb.VoltTable in project voltdb by VoltDB.
the class CheckReplicaConsistency method checkForCorrectness.
/**
* Core benchmark code. Connect. Initialize. Run the loop. Cleanup. Print
* Results.
*
* @throws Exception
* if anything unexpected happens.
*/
public void checkForCorrectness(int ptnOrRep) throws Exception {
// compare state of all nodes
// we're employing "short circuit" read queries to get the data on the node
// exit with nonzero if there is an error
String z = config.servers;
String[] servers = z.split(",");
String[] tblSuffix_ = new String[] { "Ptn", "Rep" };
String sPtnOrRep = tblSuffix_[ptnOrRep];
// used for catalog check
int nTables = 0;
System.out.printf("Checking data across nodes, case: %s, servers: %s ...\n", sPtnOrRep, z);
ClientConfig clientConfig = new ClientConfig(config.user, config.password);
long[] counters = null;
long[] crcs = null;
int crcCount = -1;
for (int iServer = 0; iServer < servers.length; iServer++) {
String server = servers[iServer];
Client client = ClientFactory.createClient(clientConfig);
try {
client.createConnection(server);
} catch (Exception e) {
System.err.printf("Error connecting to node %d %s\n", iServer, server);
e.printStackTrace();
throw new RuntimeException();
}
ClientResponse resp = null;
if (iServer == 0) {
// get the partition count
resp = client.callProcedure("@Statistics", "PARTITIONCOUNT", 0);
if (resp.getStatus() != ClientResponse.SUCCESS) {
System.err.printf("Get partition count failed %s\n", resp.getStatusString());
throw new RuntimeException();
}
VoltTable[] tpc = resp.getResults();
nPartitions = 0;
while (tpc[0].advanceRow()) {
nPartitions = (int) tpc[0].getLong("PARTITION_COUNT");
}
System.out.printf("partition count: %d\n", nPartitions);
if (nPartitions < 2) {
System.err.printf("Less than 2 partitions\n", nPartitions);
throw new RuntimeException();
}
counters = new long[nPartitions];
crcs = new long[nPartitions];
}
if (nPartitions == 0) {
System.err.println("Zero partitions should not happen");
throw new RuntimeException();
}
// check the catalog by comparing the number of tables
resp = client.callProcedure("@Statistics", "TABLE", 0);
int nt = resp.getResults()[0].getRowCount();
System.out.printf("table count: %d\n", nt);
if (iServer == 0)
nTables = nt;
else {
if (nTables != nt) {
System.err.printf("TEST FAILED Catalog Table count mismatch %d != %d %s %s\n", nTables, nt, server, servers[0]);
System.exit(1);
//throw new RuntimeException();
} else {
System.out.printf("Catalog test passed\n");
}
}
for (int pid = 0; pid < nPartitions; pid++) {
// techniques ie. "short circuit" read.
try {
long counter = checkAndReturnCounter(server, client, pid, sPtnOrRep);
if (iServer == 0)
counters[pid] = counter;
else if (counters[pid] != counter) {
System.err.printf("TEST FAILED Node counter datacompare mismatch %d != %d %s %s\n", counter, counters[pid], server, servers[0]);
System.exit(1);
//throw new RuntimeException();
}
} catch (Exception e) {
System.err.printf("Exception received calling checkAndReturnCounter: server: %s pid: %d\n%s\n", server, pid, e.getMessage());
e.printStackTrace();
throw new RuntimeException();
}
// short circuit read techniques) and compare the crc's.
try {
long crc = returnCRC(server, client, pid, sPtnOrRep);
if (iServer == 0)
crcs[pid] = crc;
else if (crcs[pid] != crc) {
System.err.printf("TEST FAILED Node crc datacompare mismatch %d != %d %s %s\n", crc, crcs[pid], server, servers[0]);
System.exit(1);
//throw new RuntimeException();
}
} catch (Exception e) {
System.err.printf("Exception received calling returnCRC: server: %s pid: %d\n%s\n", server, pid, e.getMessage());
e.printStackTrace();
throw new RuntimeException();
}
}
client.drain();
client.close();
}
System.out.printf("case: %s All nodes of counter identical\n", sPtnOrRep);
}
use of org.voltdb.VoltTable in project voltdb by VoltDB.
the class getCRCFromPtn method run.
public long run(int id) {
CRC32 crc = new CRC32();
voltQueueSQL(Stmt, id);
VoltTable[] result = voltExecuteSQL(true);
while (result[0].advanceRow()) {
long counter = result[0].getLong("counter");
byte[] b = new byte[8];
for (int i = 0; i < 8; i++) {
b[7 - i] = (byte) (counter >>> (i * 8));
}
crc.update(b);
}
return crc.getValue();
}
use of org.voltdb.VoltTable in project voltdb by VoltDB.
the class getCRCFromRep method run.
public long run(int id) {
CRC32 crc = new CRC32();
voltQueueSQL(Stmt, id);
VoltTable[] result = voltExecuteSQL(true);
while (result[0].advanceRow()) {
long counter = result[0].getLong("counter");
byte[] b = new byte[8];
for (int i = 0; i < 8; i++) {
b[7 - i] = (byte) (counter >>> (i * 8));
}
crc.update(b);
}
return crc.getValue();
}
use of org.voltdb.VoltTable 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));
}
}
Aggregations