Con = ClientConnectionPool.getWithRetry(servers, port);
// ---------------------------------------------------------------------------------------------------------------------------------------------------
// Pick the transaction rate limiter helping object to use based on user request (rate limiting or latency targeting)
IRateLimiter limiter = null;
limiter = new RateLimiter(rateLimit);
int cycle = 0;
// Run the benchmark loop for the requested duration
final long endTime = System.currentTimeMillis() + (1000l * duration);
while (endTime > System.currentTimeMillis())
{
// So, here's how we'll expose out-of-order replicated adhoc writes:
// 1) do an insert/update/delete cycle on a given primary key
// 2) some small fraction of the time, make one of these operations adhoc
// -- We do the adhoc synchronously on the master so that the ordering
// is deterministic
// 3) Add in replication and watch the DRagent go boom when the adhoc
// queries are performed asynchronously and out-of-order on the replica
// First, Insert
if (rand.nextInt(1000) < 5)
{
//System.out.println("Insert adhoc");
String query = "insert into votes (phone_number, state, contestant_number) values (" + cycle + ", 'MA', 999);";
ClientResponse response = Con.execute("@AdHoc", query);
InsertCallback blah = new InsertCallback(true, cycle);
blah.clientCallback(response);
}
else
{
//System.out.println("Insert regular");
Con.executeAsync(new InsertCallback(false, cycle),
"VOTES.insert", cycle, "MA", 999);
}
// Then, update
if (rand.nextInt(1000) < 5)
{
//System.out.println("Update adhoc");
ClientResponse response = Con.execute("@AdHoc", "update votes set state='RI', contestant_number=" + cycle + " where phone_number=" + cycle + ";");
UpdateCallback blah = new UpdateCallback(true, cycle);
blah.clientCallback(response);
}
else
{
//System.out.println("Update regular");
Con.executeAsync(new UpdateCallback(false, cycle),
"VOTES.update", cycle, "MA", cycle, cycle);
}
// Finally, delete
if (rand.nextInt(1000) < 5)
{
//System.out.println("Delete adhoc");
ClientResponse response = Con.execute("@AdHoc", "delete from votes where contestant_number=" + cycle + ";");
DeleteCallback blah = new DeleteCallback(true, cycle);
blah.clientCallback(response);
}
else
{
//System.out.println("Delete regular");
Con.executeAsync(new DeleteCallback(false, cycle),
"Delete", cycle);
}
cycle++;
// Use the limiter to throttle client activity
limiter.throttle();
}
// --------------------------------------------------------------------------------------------------------
Con.close();