use of org.voltdb.client.NoConnectionsException in project voltdb by VoltDB.
the class TestLiveProcedurePartitioningChanges method testSlamming.
public void testSlamming() throws IOException, ProcCallException, InterruptedException {
String simpleSchema = "create table dummy (" + "sval1 varchar(100) not null, " + "sval2 varchar(100) default 'foo', " + "sval3 varchar(100) default 'bar', " + "PRIMARY KEY(sval1));\n" + "PARTITION TABLE dummy ON COLUMN sval1;";
DeploymentBuilder deploymentBuilder = new DeploymentBuilder(3, 1, 0);
deploymentBuilder.setUseDDLSchema(true);
deploymentBuilder.setEnableCommandLogging(false);
deploymentBuilder.writeXML(Configuration.getPathToCatalogForTest("slamcatalog.xml"));
VoltDB.Configuration config = new VoltDB.Configuration();
config.m_pathToDeployment = Configuration.getPathToCatalogForTest("slamcatalog.xml");
server = new ServerThread(config);
server.start();
server.waitForInitialization();
Client client = getRandomClient();
ClientResponse response;
response = client.callProcedure("@AdHoc", simpleSchema);
assert (response.getStatus() == ClientResponse.SUCCESS);
final AtomicBoolean shouldContinue = new AtomicBoolean(true);
// create a thread to call the proc over and over with different pkeys
Thread clientThread = new Thread() {
@Override
public void run() {
for (long i = 0; shouldContinue.get(); i++) {
try {
client.callProcedure(PROC_NAME, String.valueOf(i));
} catch (NoConnectionsException e) {
fail();
} catch (IOException e) {
fail();
} catch (ProcCallException e) {
String msg = e.getMessage();
e.printStackTrace();
assertTrue(msg.contains("is not present") || msg.contains("was not found"));
}
}
}
};
clientThread.start();
// mess up the presence and partitioning of the procedure
for (int i = 0; i < 50; i++) {
addProcedure();
partitionProcedure();
unpartitionProcedure();
deleteProcedure();
}
shouldContinue.set(false);
clientThread.join();
client.close();
server.shutdown();
}
use of org.voltdb.client.NoConnectionsException 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 {
benchmarkThread = Thread.currentThread();
log.info(HORIZONTAL_RULE);
log.info(" Setup & Initialization");
log.info(HORIZONTAL_RULE);
// connect to one or more servers, loop until success
// first server in the list is a blessed node, we only connect to it
// second server in the list is the rejoinable node, we never connect
// to it in this part of the test
connect(config.servers.split(",")[0]);
// get the partition count
ClientResponse resp = client.callProcedure("@Statistics", "PARTITIONCOUNT", 0);
if (resp.getStatus() != ClientResponse.SUCCESS) {
log.error(_F("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");
}
log.info(_F("partition count: %d\n", nPartitions));
if (nPartitions < 2) {
log.error(_F("Less than 2 partitions\n", nPartitions));
System.exit(1);
}
client.callProcedure("Initialize", nPartitions);
log.info(HORIZONTAL_RULE);
log.info("Starting Benchmark");
log.info(HORIZONTAL_RULE);
// 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
log.info("\nRunning benchmark...");
final long benchmarkEndTime = System.currentTimeMillis() + (1000l * config.duration);
//String qOps[] = {"*","/"};
String[] qOps = { "+", "+" };
int lastCatalog = 0;
while (runBenchmark && (benchmarkEndTime > System.currentTimeMillis())) {
// 50/50 multiply or divide operation
int r = rand.nextInt(2);
//choose a counter
int p = rand.nextInt(nPartitions);
// values 2-3
int c = rand.nextInt(1) + 2;
Tests tc;
if (testCase == null) {
tc = Tests.values()[rand.nextInt(Tests.values().length)];
//System.err.printf("selected test: %s\n", tc);
} else
tc = testCase;
totalAsync.getAndIncrement();
try {
switch(tc) {
case ADHOCSINGLEPARTPTN:
// single part adhoc query ENG-3886 also see ENG-4076
//System.err.printf("adhoc singlepart...\n");
client.callProcedure(new SequenceCallback(), "@AdHoc", "UPDATE COUNTERS_PTN set COUNTER=COUNTER" + qOps[r] + Integer.toString(c) + " WHERE id=" + Integer.toString(p) + ";");
totalAdHoc.getAndIncrement();
break;
case ADHOCMULTIPARTPTN:
// multipart adhoc query ENG-3887
//System.err.printf("adhoc multipart...\n");
client.callProcedure(new SequenceCallback(), "@AdHoc", "UPDATE COUNTERS_PTN set COUNTER=COUNTER" + qOps[r] + Integer.toString(c) + ";");
totalAdHoc.getAndIncrement();
break;
case ADHOCSINGLEPARTREP:
// multipart adhoc query ENG-3887
//System.err.printf("adhoc multipart...\n");
client.callProcedure(new SequenceCallback(), "@AdHoc", "UPDATE COUNTERS_REP set COUNTER=COUNTER" + qOps[r] + Integer.toString(c) + " WHERE id=" + Integer.toString(p) + ";");
totalAdHoc.getAndIncrement();
break;
case ADHOCMULTIPARTREP:
// multipart adhoc query ENG-3887
//System.err.printf("adhoc multipart...\n");
client.callProcedure(new SequenceCallback(), "@AdHoc", "UPDATE COUNTERS_REP set COUNTER=COUNTER" + qOps[r] + Integer.toString(c) + ";");
totalAdHoc.getAndIncrement();
break;
case UPDATEAPPLICATIONCATALOG:
// UpdateApplicationCatalog
// we want the update application catalog command to be issued during the rejoin
// but the client is async relative to killing and rejoining.
// also, the rejoin time will vary a lot depending on the nodes and sitesperhost.
// so long run times will be required to possibly hit the right timing.
// bottom line-this is not going to be a meaningful test when run for short durations.
ClientResponse response = null;
// Find out which catalog we are on
try {
response = client.callProcedure("@AdHoc", "Select count(*) from replicated;");
if (response.getStatus() == ClientResponse.SUCCESS) {
lastCatalog = 1;
} else {
lastCatalog = 0;
}
} catch (ProcCallException e) {
// expect a planner exception on catalog 0
//e.printStackTrace();
lastCatalog = 0;
} catch (Exception e) {
logStackTrace(e);
throw new RuntimeException();
}
// running ALL, we don't wait, otherwise go slow.
if (testCase != null) {
// really slow
Thread.sleep(rand.nextInt(20000) + 1);
}
// now, flip to the other catalog
// this runs as a synchronous tx (for now)
log.info(_F("updateapplicationcatalog %d...\n", lastCatalog));
// create catalog
String catPath = ".";
File[] catalog_files = { new File(catPath + "/LiveRejoinConsistency.jar"), new File(catPath + "/LiveRejoinConsistency2.jar") };
File file2 = new File(catPath + "/deployment.xml");
// Flip the catalog
lastCatalog = (lastCatalog + 1) % 2;
response = client.updateApplicationCatalog(catalog_files[lastCatalog], file2);
if (response.getStatus() != ClientResponse.SUCCESS) {
log.error(_F("UAC operation failed with %s\n", response.getStatusString()));
throw new RuntimeException();
} else {
successfulAsync.getAndIncrement();
// check if we're on the right catalog
try {
response = client.callProcedure("@AdHoc", "Select count(*) from replicated;");
switch(lastCatalog) {
case 0:
if (response.getStatus() == ClientResponse.SUCCESS) {
log.error("unexpected result for catalog 0\n");
throw new RuntimeException();
}
break;
case 1:
if (response.getStatus() != ClientResponse.SUCCESS) {
log.error("unexpected result for catalog 1\n");
throw new RuntimeException();
}
break;
default:
throw new RuntimeException("Invalid catalog switch value");
}
} catch (ProcCallException e) {
if (lastCatalog != 0) {
logStackTrace(e);
log.error(_F("unexpected result for catalog 1 in proccallexception %d\n%s\n", lastCatalog, e.getMessage()));
throw new RuntimeException();
}
}
}
break;
case WRSINGLEPARTSTOREDPROCPTN:
// single-part stored procedure
client.callProcedure(new SequenceCallback(), "getNextFromPtn", p, nPartitions);
break;
case WRMULTIPARTSTOREDPROCPTN:
// multi-part stored procedure
// Updates a partitioned table
client.callProcedure(new SequenceCallback(), "MPUpdatePtn");
case WRMULTIPARTSTOREDPROCREP:
// multi-part stored procedure
// Updates a replicated table
client.callProcedure(new SequenceCallback(), "MPUpdateRep");
break;
// this case is failing ENG-4097
case LOADSINGLEPARTITIONTABLEPTN:
case LOADMULTIPARTITIONTABLEREP:
// LoadSinglePartitionTable LoadMultiPartitionTable ENG-3885 part 1 of 2
// voltLoadTable is not client exposed
// voltLoadTable is used for the initial load on DR
// Get all the rows from the counter table and insert them into the
// like_counter table, then compare both copies of the target table after rejoin
response = null;
try {
response = client.callProcedure("getRowFromPtn", p);
if (response.getStatus() != ClientResponse.SUCCESS) {
log.error(_F("FATAL Unexpectd result getting source row %s\n", response.getStatusString()));
throw new RuntimeException();
}
} catch (ProcCallException e) {
//e.printStackTrace();
log.error(_F("unexpected exception getting source row\n %s\n", e.getMessage()));
}
VoltTable[] vt = response.getResults();
if (vt.length == 0) {
log.error(_F("FATAL VoltTable[] object has no elememts\n"));
throw new RuntimeException();
}
if (vt[0].getRowCount() != 1) {
log.error(_F("FATAL VoltTable object has wrong number of rows %d\n", vt[0].getRowCount()));
throw new RuntimeException();
}
VoltTable vt0 = vt[0];
// insert row into target table
try {
switch(tc) {
case LOADSINGLEPARTITIONTABLEPTN:
client.callProcedure(new SequenceCallback(), "@LoadSinglepartitionTable", "LIKE_COUNTERS_PTN", upsertMode, vt0);
break;
case LOADMULTIPARTITIONTABLEREP:
client.callProcedure(new SequenceCallback(), "@LoadMultipartitionTable", "LIKE_COUNTERS_REP", upsertMode, vt0);
break;
}
} catch (VoltAbortException e) {
log.error(_F("FATAL Load single/multi table failed with an exception\n%s\n", e.getMessage()));
throw new RuntimeException();
}
break;
default:
throw new RuntimeException("Invalid query selector switch value: '" + tc + "'");
}
} catch (NoConnectionsException e) {
logStackTrace(e);
throw new RuntimeException(e);
} catch (InterruptedException e) {
logStackTrace(e);
log.warn(_F("Caught InterrruptedException: %s\ntoString: %s\n", e.getMessage(), e.toString()));
//throw new RuntimeException(e);
} catch (IOException e) {
logStackTrace(e);
log.warn(_F("Caught IOException: %s\ntoString: %s\n", e.getMessage(), e.toString()));
//throw new RuntimeException(e);
} catch (Exception e) {
logStackTrace(e);
log.error(_F("Caught Exception: %s\ntoString: %s\n", e.getMessage(), e.toString()));
throw new RuntimeException(e);
}
Thread.yield();
}
// while
// cancel periodic stats printing
timer.cancel();
try {
// block until all outstanding txns return
log.info("draining connection...");
client.drain();
} catch (Exception e) {
}
// print a report
try {
printResults();
} catch (Exception e) {
}
// close down the client connections
try {
client.close();
} catch (Exception e) {
}
}
use of org.voltdb.client.NoConnectionsException in project voltdb by VoltDB.
the class VoltDBOsmSink method process.
public void process(WayContainer wayContainer) {
Way way;
List<Long> nodeIds;
way = wayContainer.getEntity();
nodeIds = new ArrayList<Long>(way.getWayNodes().size());
for (WayNode wayNode : way.getWayNodes()) {
nodeIds.add(wayNode.getNodeId());
}
// Keep invalid ways out of the database if desired by the user
if (way.getWayNodes().size() > 1 || keepInvalidWays) {
for (Tag tag : way.getTags()) {
try {
client.callProcedure(new InsertCallback(), INS_WAY_TAGS_PROC, way.getId(), tag.getKey(), tag.getValue());
} catch (NoConnectionsException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
// Add these to the ways_nodes_table;
int sequence = 0;
for (Long nodeId : nodeIds) {
try {
client.callProcedure(new InsertCallback(), INS_WAYS_NODES_PROC, way.getId(), nodeId, sequence);
} catch (NoConnectionsException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
sequence++;
}
StringBuffer sb = new StringBuffer();
// if the first node id == the last nodeId, we know that this is a
// closed loop.
long n0 = nodeIds.get(0);
long nn = nodeIds.get(nodeIds.size() - 1);
if (n0 == nn) {
if (enableBboxBuilder) {
Polygon pg = wayGeometryBuilder.createPolygon(way);
pg.outerWKT(sb);
}
} else {
// it's a lineString, but we don't support it yet.
if (enableLinestringBuilder) {
LineString lineString = wayGeometryBuilder.createWayLinestring(way);
lineString.outerWKT(sb);
} else {
return;
}
}
String bbox = sb.toString();
try {
client.callProcedure(new InsertCallback(), INS_WAYS_PROC, way.getId(), way.getVersion(), way.getUser().getId(), way.getTimestamp(), way.getChangesetId(), bbox);
} catch (NoConnectionsException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
use of org.voltdb.client.NoConnectionsException in project voltdb by VoltDB.
the class TestCatchExceptionsInProcedure method spChecker.
private void spChecker(Client client, String proc, int hasPreviousBatch, int tryCatchContains1BatchFirst, int tryCatchContains1BatchSecond, int hasFollowingBatch, int followingBatchHasException, double[] expected) throws NoConnectionsException, IOException, ProcCallException {
VoltTable vt;
String sql;
try {
// use the default value for partition column to route this procedure
if (tryCatchContains1BatchSecond == -1) {
vt = client.callProcedure(proc, 0, hasPreviousBatch, tryCatchContains1BatchFirst, hasFollowingBatch, followingBatchHasException).getResults()[0];
} else {
vt = client.callProcedure(proc, 0, hasPreviousBatch, tryCatchContains1BatchFirst, tryCatchContains1BatchSecond, hasFollowingBatch, followingBatchHasException).getResults()[0];
}
if (isTrue(followingBatchHasException)) {
assertTrue(isTrue(hasFollowingBatch));
fail("Expected failure but succeeded.");
}
// validate returned value from the procedure calls
validateRowOfLongs(vt, new long[] { -1 });
} catch (Exception e) {
assertTrue(e.getMessage().contains("CONSTRAINT VIOLATION"));
// violated at row (3, 3.2)
assertTrue(e.getMessage().contains("3.2"));
assertTrue(isTrue(hasFollowingBatch) && isTrue(followingBatchHasException));
}
sql = "select ratio from P1 order by 1; ";
validateTableColumnOfScalarFloat(client, sql, expected);
client.callProcedure("@AdHoc", "truncate table P1");
}
use of org.voltdb.client.NoConnectionsException in project voltdb by VoltDB.
the class TestIndexesSuite method subTestKeyCastingOverflow.
private void subTestKeyCastingOverflow() throws NoConnectionsException, IOException, ProcCallException {
Client client = getClient();
ClientResponseImpl cr = (ClientResponseImpl) client.callProcedure("@AdHoc", "select * from P1 where ID = ?;", 0);
assertEquals(cr.getStatus(), ClientResponse.SUCCESS);
try {
cr = (ClientResponseImpl) client.callProcedure("@AdHoc", "select * from P1 where ID = ?;", 6000000000L);
fail();
} catch (Exception ex) {
assertTrue(ex.getMessage().contains("tryToMakeCompatible: The provided value: (6000000000) of type:" + " java.lang.Long is not a match or is out of range for the target parameter type: int"));
}
}
Aggregations