use of org.voltdb.client.ClientResponse in project voltdb by VoltDB.
the class ClientThread method runOne.
void runOne() throws Exception {
// 1/10th of txns roll back
byte shouldRollback = (byte) (m_random.nextInt(10) == 0 ? 1 : 0);
try {
String procName = null;
int expectedTables = 5;
switch(m_type) {
case PARTITIONED_SP:
procName = "UpdatePartitionedSP";
break;
case PARTITIONED_MP:
procName = "UpdatePartitionedMP";
expectedTables = 6;
break;
case REPLICATED:
procName = "UpdateReplicatedMP";
expectedTables = 6;
break;
case HYBRID:
procName = "UpdateBothMP";
expectedTables = 6;
break;
case ADHOC_MP:
procName = "UpdateReplicatedMPInProcAdHoc";
expectedTables = 6;
break;
}
byte[] payload = m_processor.generateForStore().getStoreValue();
ClientResponse response;
try {
response = m_client.callProcedure(procName, m_cid, m_nextRid, payload, shouldRollback);
} catch (Exception e) {
if (shouldRollback == 0) {
log.warn("ClientThread threw after " + m_txnsRun.get() + " calls while calling procedure: " + procName + " with args: cid: " + m_cid + ", nextRid: " + m_nextRid + ", payload: " + payload + ", shouldRollback: " + shouldRollback);
}
throw e;
}
// fake a proc call exception if we think one should be thrown
if (response.getStatus() != ClientResponse.SUCCESS) {
throw new UserProcCallException(response);
}
VoltTable[] results = response.getResults();
m_txnsRun.incrementAndGet();
if (results.length != expectedTables) {
hardStop(String.format("Client cid %d procedure %s returned %d results instead of %d", m_cid, procName, results.length, expectedTables), response);
}
VoltTable data = results[3];
VoltTable view = results[4];
try {
UpdateBaseProc.validateCIDData(data, view, "ClientThread:" + m_cid);
} catch (VoltAbortException vae) {
log.error("validateCIDData failed on: " + procName + ", shouldRollback: " + shouldRollback + " data: " + data);
throw vae;
}
} finally {
// ensure rid is incremented (if not rolled back intentionally)
if (shouldRollback == 0) {
m_nextRid++;
}
}
}
use of org.voltdb.client.ClientResponse in project voltdb by VoltDB.
the class UpdateClassesBenchmark method doUpdateClassesWork.
static UACTime doUpdateClassesWork(Client client, String prevStmts, byte[] jar, String delPattern, String stmts) throws Exception {
uacBlockTime(client, 0, false);
long startTS = System.nanoTime();
long sumBlockTime = 0;
ClientResponse cr = null;
if (prevStmts != null && prevStmts.length() > 0) {
cr = client.callProcedure("@AdHoc", prevStmts);
assert (cr.getStatus() == ClientResponse.SUCCESS);
sumBlockTime += uacBlockTime(client, 1, true);
}
if (jar != null || delPattern != null) {
cr = client.callProcedure("@UpdateClasses", jar, delPattern);
assert (cr.getStatus() == ClientResponse.SUCCESS);
sumBlockTime += uacBlockTime(client, 1, true);
}
if (stmts != null && stmts.length() > 0) {
cr = client.callProcedure("@AdHoc", stmts);
assert (cr.getStatus() == ClientResponse.SUCCESS);
sumBlockTime += uacBlockTime(client, 1, true);
}
return new UACTime(System.nanoTime() - startTS, sumBlockTime);
}
use of org.voltdb.client.ClientResponse in project voltdb by VoltDB.
the class VoltClient4 method scan.
@Override
public Status scan(String keyspace, String lowerBound, int recordCount, Set<String> columns, Vector<HashMap<String, ByteIterator>> result) {
try {
byte[] ks = keyspace.getBytes(UTF8);
ClientResponse response = m_client.callProcedure("Scan", ks, lowerBound, lowerBound.getBytes(UTF8), recordCount);
if (response.getStatus() != ClientResponse.SUCCESS) {
return Status.ERROR;
}
int nFound = 0;
String partKey = lowerBound;
CyclicBarrier barrier = new CyclicBarrier(2);
result.ensureCapacity(recordCount);
ScanCallback callback = null;
boolean proceed = true;
while (proceed) {
if (response.getStatus() != ClientResponse.SUCCESS) {
return Status.ERROR;
}
VoltTable table = response.getResults()[0];
nFound += table.getRowCount();
proceed = nFound < recordCount && (partKey = nextPartitionKey(partKey)) != null;
if (proceed) {
barrier.reset();
callback = new ScanCallback(barrier);
m_client.callProcedure(callback, "Scan", ks, partKey, null, recordCount - nFound);
}
while (table.advanceRow()) {
result.add(unpackRowData(table, columns));
}
if (proceed) {
barrier.await();
response = callback.response;
}
}
return Status.OK;
} catch (Exception e) {
e.printStackTrace();
return Status.ERROR;
}
}
use of org.voltdb.client.ClientResponse in project voltdb by VoltDB.
the class TestAdhocCreateDropJavaProc method testBasic.
@Test
public void testBasic() throws Exception {
System.out.println("\n\n-----\n testBasic \n-----\n\n");
String pathToCatalog = Configuration.getPathToCatalogForTest("updateclasses.jar");
String pathToDeployment = Configuration.getPathToCatalogForTest("updateclasses.xml");
VoltProjectBuilder builder = new VoltProjectBuilder();
builder.addLiteralSchema("-- Don't care");
builder.setUseDDLSchema(true);
boolean success = builder.compile(pathToCatalog, 2, 1, 0);
assertTrue("Schema compilation failed", success);
MiscUtils.copyFile(builder.getPathToDeployment(), pathToDeployment);
try {
LocalCluster cluster = new LocalCluster("updateclasses.jar", 2, 1, 0, BackendTarget.NATIVE_EE_JNI);
cluster.compile(builder);
cluster.setHasLocalServer(false);
cluster.startUp();
m_client = ClientFactory.createClient();
m_client.createConnection(cluster.getListenerAddress(0));
ClientResponse resp;
// Can't create a procedure without a class
resp = m_client.callProcedure("@SystemCatalog", "CLASSES");
System.out.println("CLASSES: " + resp.getResults()[0]);
try {
resp = m_client.callProcedure("@AdHoc", "create procedure from class org.voltdb_testprocs.updateclasses.testImportProc");
fail("Shouldn't be able to create a procedure backed by no class");
} catch (ProcCallException pce) {
}
assertFalse(findProcedureInSystemCatalog("testImportProc"));
InMemoryJarfile jarfile = new InMemoryJarfile();
VoltCompiler comp = new VoltCompiler(false);
comp.addClassToJar(jarfile, org.voltdb_testprocs.updateclasses.testImportProc.class);
resp = m_client.callProcedure("@UpdateClasses", jarfile.getFullJarBytes(), null);
// call the procedure. Maybe this gets better in the future
try {
resp = m_client.callProcedure("@AdHoc", "create procedure from class org.voltdb_testprocs.updateclasses.testImportProc");
} catch (ProcCallException pce) {
fail("We allow procedures to be created with unsatisfied dependencies");
}
assertTrue(findProcedureInSystemCatalog("testImportProc"));
// Make sure we don't crash when we call it though
try {
resp = m_client.callProcedure("testImportProc");
fail("Should return an error and not crash calling procedure w/ bad dependencies");
} catch (ProcCallException pce) {
assertTrue(pce.getMessage().contains("ClassNotFoundException"));
}
// Okay, add the missing dependency
jarfile = new InMemoryJarfile();
comp = new VoltCompiler(false);
comp.addClassToJar(jarfile, org.voltdb_testprocs.updateclasses.NoMeaningClass.class);
resp = m_client.callProcedure("@UpdateClasses", jarfile.getFullJarBytes(), null);
// now we should be able to call it
try {
resp = m_client.callProcedure("testImportProc");
} catch (ProcCallException pce) {
fail("Should be able to call fully consistent procedure");
}
assertEquals(10L, resp.getResults()[0].asScalarLong());
// Now try to remove the procedure class
try {
resp = m_client.callProcedure("@UpdateClasses", null, "org.voltdb_testprocs.updateclasses.*");
fail("Shouldn't be able to rip a class out from under an active proc");
} catch (ProcCallException pce) {
assertTrue(pce.getMessage(), pce.getMessage().contains("Cannot load class for procedure: org.voltdb_testprocs.updateclasses.testImportProc"));
}
// Make sure we didn't purge anything (even the extra dependency)
resp = m_client.callProcedure("@SystemCatalog", "CLASSES");
assertEquals(2, resp.getResults()[0].getRowCount());
// Okay, drop the procedure first
try {
resp = m_client.callProcedure("@AdHoc", "drop procedure testImportProc");
} catch (ProcCallException pce) {
fail("Should be able to drop a stored procedure");
}
assertFalse(findProcedureInSystemCatalog("testImportProc"));
// Now try to remove the procedure class again
try {
resp = m_client.callProcedure("@UpdateClasses", null, "org.voltdb_testprocs.updateclasses.*");
} catch (ProcCallException pce) {
fail("Should be able to remove the classes for an inactive procedure");
}
resp = m_client.callProcedure("@SystemCatalog", "CLASSES");
// no classes in catalog
assertEquals(0, resp.getResults()[0].getRowCount());
m_client.close();
cluster.shutDown();
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.voltdb.client.ClientResponse in project voltdb by VoltDB.
the class TestAdhocCreateDropJavaProc method testCreateUsingExistingImport.
// This test should trigger the same failure seen in ENG-6611
@Test
public void testCreateUsingExistingImport() throws Exception {
System.out.println("\n\n-----\n testCreateUsingExistingImport \n-----\n\n");
String pathToCatalog = Configuration.getPathToCatalogForTest("updateclasses.jar");
String pathToDeployment = Configuration.getPathToCatalogForTest("updateclasses.xml");
VoltProjectBuilder builder = new VoltProjectBuilder();
// Start off with the dependency imported
builder.addLiteralSchema("import class org.voltdb_testprocs.updateclasses.NoMeaningClass;");
builder.setUseDDLSchema(true);
boolean success = builder.compile(pathToCatalog, 2, 1, 0);
assertTrue("Schema compilation failed", success);
MiscUtils.copyFile(builder.getPathToDeployment(), pathToDeployment);
try {
LocalCluster cluster = new LocalCluster("updateclasses.jar", 2, 1, 0, BackendTarget.NATIVE_EE_JNI);
cluster.compile(builder);
cluster.setHasLocalServer(false);
cluster.startUp();
m_client = ClientFactory.createClient();
m_client.createConnection(cluster.getListenerAddress(0));
ClientResponse resp;
resp = m_client.callProcedure("@SystemCatalog", "CLASSES");
System.out.println(resp.getResults()[0]);
// Now load the procedure requiring the already-resident dependency
InMemoryJarfile jarfile = new InMemoryJarfile();
VoltCompiler comp = new VoltCompiler(false);
comp.addClassToJar(jarfile, org.voltdb_testprocs.updateclasses.testImportProc.class);
try {
resp = m_client.callProcedure("@UpdateClasses", jarfile.getFullJarBytes(), null);
} catch (ProcCallException pce) {
pce.printStackTrace();
fail("Triggered ENG-6611!");
}
resp = m_client.callProcedure("@SystemCatalog", "CLASSES");
assertEquals(2, resp.getResults()[0].getRowCount());
// create the proc and make sure it runs
try {
resp = m_client.callProcedure("@AdHoc", "create procedure from class org.voltdb_testprocs.updateclasses.testImportProc");
} catch (ProcCallException pce) {
fail("Should be able to create testImportProc procedure");
}
assertTrue(findProcedureInSystemCatalog("testImportProc"));
try {
resp = m_client.callProcedure("testImportProc");
} catch (ProcCallException pce) {
pce.printStackTrace();
fail("Should be able to call fully consistent procedure");
}
assertEquals(10L, resp.getResults()[0].asScalarLong());
m_client.close();
cluster.shutDown();
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations