use of org.voltdb.client.ProcedureCallback in project voltdb by VoltDB.
the class TableHelper method fillTableWithBigintPkey.
/**
* Load random data into a partitioned table in VoltDB that has a bigint pkey.
*
* If the VoltTable indicates which column is its pkey, then it will use it, but otherwise it will
* assume the first column is the bigint pkey. Note, this works with other integer keys, but
* your keyspace is pretty small.
*
* If mb == 0, then maxRows is used. If maxRows == 0, then mb is used.
*
* @param table Table with or without schema metadata.
* @param mb Target RSS (approximate)
* @param maxRows Target maximum rows
* @param client To load with.
* @param offset Generated pkey values start here.
* @param jump Generated pkey values increment by this value.
* @throws Exception
*/
public void fillTableWithBigintPkey(VoltTable table, int mb, long maxRows, final Client client, long offset, long jump) throws Exception {
// make sure some kind of limit is set
assert ((maxRows > 0) || (mb > 0));
assert (maxRows >= 0);
assert (mb >= 0);
final int mbTarget = mb > 0 ? mb : Integer.MAX_VALUE;
if (maxRows == 0) {
maxRows = Long.MAX_VALUE;
}
System.out.printf("Filling table %s with rows starting with pkey id %d (every %d rows) until either RSS=%dmb or rowcount=%d\n", table.m_extraMetadata.name, offset, jump, mbTarget, maxRows);
// find the primary key, assume first col if not found
int pkeyColIndex = getBigintPrimaryKeyIndexIfExists(table);
if (pkeyColIndex == -1) {
pkeyColIndex = 0;
assert (table.getColumnType(0).isBackendIntegerType());
}
final AtomicLong rss = new AtomicLong(0);
ProcedureCallback insertCallback = new ProcedureCallback() {
@Override
public void clientCallback(ClientResponse clientResponse) throws Exception {
if (clientResponse.getStatus() != ClientResponse.SUCCESS) {
System.out.println("Error in loader callback:");
System.out.println(((ClientResponseImpl) clientResponse).toJSONString());
assert (false);
}
}
};
// update the rss value asynchronously
final AtomicBoolean rssThreadShouldStop = new AtomicBoolean(false);
Thread rssThread = new Thread() {
@Override
public void run() {
long tempRss = rss.get();
long rssPrev = tempRss;
while (!rssThreadShouldStop.get()) {
tempRss = MiscUtils.getMBRss(client);
if (tempRss != rssPrev) {
rssPrev = tempRss;
rss.set(tempRss);
System.out.printf("RSS=%dmb\n", tempRss);
// bail when done
if (tempRss > mbTarget) {
return;
}
}
try {
Thread.sleep(2000);
} catch (Exception e) {
}
}
}
};
// load rows until RSS goal is met (status print every 100k)
long i = offset;
long rows = 0;
rssThread.start();
final String insertProcName = table.m_extraMetadata.name.toUpperCase() + ".insert";
RandomRowMaker filler = createRandomRowMaker(table, Integer.MAX_VALUE, false, false);
while (rss.get() < mbTarget) {
Object[] row = filler.randomRow();
row[pkeyColIndex] = i;
client.callProcedure(insertCallback, insertProcName, row);
rows++;
if ((rows % 100000) == 0) {
System.out.printf("Loading 100000 rows. %d inserts sent (%d max id).\n", rows, i);
}
// if row limit is set, break if it's hit
if (rows >= maxRows) {
break;
}
i += jump;
}
rssThreadShouldStop.set(true);
client.drain();
rssThread.join();
System.out.printf("Filled table %s with %d rows and now RSS=%dmb\n", table.m_extraMetadata.name, rows, rss.get());
}
use of org.voltdb.client.ProcedureCallback in project voltdb by VoltDB.
the class DeletesClient method performSnapshot.
public static void performSnapshot(Client client) {
checkSnapshotComplete(client);
if (m_snapshotInProgress) {
System.out.println("Snapshot still in progress, bailing");
return;
}
try {
VoltTable[] results = client.callProcedure("@SnapshotDelete", new String[] { m_snapshotDir }, new String[] { m_snapshotId }).getResults();
} catch (NoConnectionsException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (ProcCallException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// m_totalRows should be accurate at this point
m_snapshotSizes.add(m_totalRows);
System.out.println("Performing Snapshot with total rows: " + m_totalRows);
try {
if (m_blockingSnapshots) {
ClientResponse response = client.callProcedure("@SnapshotSave", m_snapshotDir, m_snapshotId, 1);
if (response.getStatus() != ClientResponse.SUCCESS) {
System.out.println("failed snapshot");
System.out.println(response.getStatusString());
}
} else {
client.callProcedure(new ProcedureCallback() {
@Override
public void clientCallback(ClientResponse response) {
if (response.getStatus() != ClientResponse.SUCCESS) {
System.out.println("failed snapshot");
System.out.println(response.getStatusString());
}
}
}, "@SnapshotSave", m_snapshotDir, m_snapshotId, 0);
}
} catch (NoConnectionsException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ProcCallException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of org.voltdb.client.ProcedureCallback in project voltdb by VoltDB.
the class TestFixedSQLSuite method subTestTicketEng2250_IsNull.
private void subTestTicketEng2250_IsNull() throws IOException, ProcCallException, InterruptedException {
System.out.println("STARTING testTicketEng2250_IsNull");
Client client = getClient();
ProcedureCallback callback = new ProcedureCallback() {
@Override
public void clientCallback(ClientResponse clientResponse) throws Exception {
if (clientResponse.getStatus() != ClientResponse.SUCCESS) {
throw new RuntimeException("Failed with response: " + clientResponse.getStatusString());
}
}
};
/*
CREATE TABLE P1 (
ID INTEGER DEFAULT '0' NOT NULL,
DESC VARCHAR(300),
NUM INTEGER,
RATIO FLOAT,
PRIMARY KEY (ID)
);
*/
System.out.println("Eng2250: null entries.");
for (int id = 0; id < 5; id++) {
client.callProcedure(callback, "P1.insert", id, null, 10, 1.1);
client.drain();
}
System.out.println("Eng2250: not null entries.");
for (int id = 5; id < 8; id++) {
client.callProcedure(callback, "P1.insert", id, "description", 10, 1.1);
client.drain();
}
VoltTable r1 = client.callProcedure("@AdHoc", "select count(*) from P1 where desc is null").getResults()[0];
//* enable for debugging */ System.out.println(r1);
assertEquals(5, r1.asScalarLong());
VoltTable r2 = client.callProcedure("@AdHoc", "select count(*) from P1 where not desc is null").getResults()[0];
//* enable for debugging */ System.out.println(r2);
assertEquals(3, r2.asScalarLong());
VoltTable r3 = client.callProcedure("@AdHoc", "select count(*) from P1 where NOT (id=2 and desc is null)").getResults()[0];
//* enable for debugging */ System.out.println(r3);
assertEquals(7, r3.asScalarLong());
VoltTable r4 = client.callProcedure("@AdHoc", "select count(*) from P1 where NOT (id=6 and desc is null)").getResults()[0];
//* enable for debugging */ System.out.println(r4);
assertEquals(8, r4.asScalarLong());
VoltTable r5 = client.callProcedure("@AdHoc", "select count(*) from P1 where id < 6 and NOT desc is null;").getResults()[0];
//* enable for debugging */ System.out.println(r5);
assertEquals(1, r5.asScalarLong());
truncateTable(client, "P1");
}
use of org.voltdb.client.ProcedureCallback in project voltdb by VoltDB.
the class TestFunctionsForVoltDBSuite method testExplicitErrorUDF.
public void testExplicitErrorUDF() throws Exception {
System.out.println("STARTING testExplicitErrorUDF");
Client client = getClient();
ProcedureCallback callback = new ProcedureCallback() {
@Override
public void clientCallback(ClientResponse clientResponse) throws Exception {
if (clientResponse.getStatus() != ClientResponse.SUCCESS) {
throw new RuntimeException("Failed with response: " + clientResponse.getStatusString());
}
}
};
/*
CREATE TABLE P1 (
ID INTEGER DEFAULT '0' NOT NULL,
DESC VARCHAR(300),
NUM INTEGER,
RATIO FLOAT,
PRIMARY KEY (ID)
);
*/
for (int id = 7; id < 15; id++) {
client.callProcedure(callback, "P1.insert", -id, "X" + String.valueOf(id), 10, 1.1);
client.drain();
}
ClientResponse cr = null;
// Exercise basic syntax without runtime invocation.
cr = client.callProcedure("@AdHoc", "select SQL_ERROR(123) from P1 where ID = 0");
assertEquals(cr.getStatus(), ClientResponse.SUCCESS);
cr = client.callProcedure("@AdHoc", "select SQL_ERROR('abc') from P1 where ID = 0");
assertEquals(cr.getStatus(), ClientResponse.SUCCESS);
cr = client.callProcedure("@AdHoc", "select SQL_ERROR(123, 'abc') from P1 where ID = 0");
assertEquals(cr.getStatus(), ClientResponse.SUCCESS);
// negative tests
verifyStmtFails(client, "select SQL_ERROR(123, 'abc') from P1", "abc");
verifyStmtFails(client, "select SQL_ERROR('abc') from P1", "abc");
verifyStmtFails(client, "select SQL_ERROR(123, 123) from P1", ".*SQL ERROR\n.*VARCHAR.*");
verifyStmtFails(client, "select SQL_ERROR(123.5) from P1", "Type DECIMAL can't be cast as BIGINT");
verifyStmtFails(client, "select SQL_ERROR(123.5E-2) from P1", "Type FLOAT can't be cast as BIGINT");
}
use of org.voltdb.client.ProcedureCallback in project voltdb by VoltDB.
the class SnapshotDaemon method processUserSnapshotRequestEvent.
/*
* Process the event generated when the node for a user snapshot request
* is created.
*/
private void processUserSnapshotRequestEvent(final WatchedEvent event) throws Exception {
if (event.getType() == EventType.NodeCreated) {
byte[] data = m_zk.getData(event.getPath(), false, null);
String jsonString = new String(data, "UTF-8");
final JSONObject jsObj = new JSONObject(jsonString);
final String requestId = jsObj.getString("requestId");
final boolean blocking = jsObj.getBoolean(SnapshotUtil.JSON_BLOCK);
/*
* Going to reuse the request object, remove the requestId
* field now that it is consumed
*/
jsObj.remove("requestId");
jsObj.put("perPartitionTxnIds", retrievePerPartitionTransactionIds());
final long handle = m_nextCallbackHandle++;
m_procedureCallbacks.put(handle, new ProcedureCallback() {
@Override
public void clientCallback(ClientResponse clientResponse) {
m_lastInitiationTs = null;
try {
/*
* If there is an error then we are done.
*/
if (clientResponse.getStatus() != ClientResponse.SUCCESS) {
ClientResponseImpl rimpl = (ClientResponseImpl) clientResponse;
saveResponseToZKAndReset(requestId, rimpl);
return;
}
/*
* Now analyze the response. If a snapshot was in progress
* we have to reattempt it later, and send a response to the client
* saying it was queued. Otherwise, forward the response
* failure/success to the client.
*/
if (isSnapshotInProgressResponse(clientResponse)) {
scheduleSnapshotForLater(jsObj.toString(4), requestId, true);
} else {
ClientResponseImpl rimpl = (ClientResponseImpl) clientResponse;
saveResponseToZKAndReset(requestId, rimpl);
return;
}
} catch (Exception e) {
SNAP_LOG.error("Error processing user snapshot request", e);
try {
userSnapshotRequestExistenceCheck(true);
} catch (Exception e2) {
VoltDB.crashLocalVoltDB("Error resetting watch for user snapshots", true, e2);
}
}
}
});
initiateSnapshotSave(handle, new Object[] { jsObj.toString(4) }, blocking);
return;
}
}
Aggregations