long txn_id = XACT_ID.getAndIncrement();
MarkovEstimatorState state = t_estimator.startTransaction(txn_id, this.catalog_proc, txn_trace.getParams());
assertNotNull(state);
assertNotNull(state.getLastEstimate());
MarkovEstimate initialEst = state.getInitialEstimate();
assertNotNull(initialEst);
assertTrue(initialEst.toString(), initialEst.isInitialized());
// assertTrue(initialEst.toString(), initialEst.isSinglePartitionProbabilitySet());
assertTrue(initialEst.toString(), initialEst.isAbortProbabilitySet());
// assertTrue(initialEst.toString(), initialEst.getSinglePartitionProbability() < 1.0f);
assertTrue(initialEst.toString(), initialEst.isConfidenceCoefficientSet());
assertTrue(initialEst.toString(), initialEst.getConfidenceCoefficient() >= 0f);
assertTrue(initialEst.toString(), initialEst.getConfidenceCoefficient() <= 1f);
// Get the list of partitions that we're going to touch in the beginning
// We should never mark these as finished in subsequent estimates
PartitionSet touched = initialEst.getTouchedPartitions(thresholds);
assertFalse(touched.isEmpty());
assertFalse(touched.contains(HStoreConstants.NULL_PARTITION_ID));
System.err.println("TOUCHED: " + touched);
assertFalse(touched.toString(), touched.size() == 1);
// Execute a bunch of batches
// All should say that the txn is not finished with the partitions until we
// get to the one that contains the updateStock queries, which should be the last.
Statement lastBatchStmt = this.getStatement(this.catalog_proc, "updateStock");
for (int i = 0, cnt = txn_trace.getBatchCount(); i < cnt; i++) {
List<QueryTrace> queries = txn_trace.getBatchQueries(i);
assertFalse(queries.isEmpty());
boolean is_last = (i+1 == cnt);
Statement stmts[] = new Statement[queries.size()];
PartitionSet partitions[] = new PartitionSet[queries.size()];
boolean found = false;
int idx = 0;
for (QueryTrace q : queries) {
stmts[idx] = q.getCatalogItem(catalogContext.database);
assertNotNull(stmts[idx]);
partitions[idx] = new PartitionSet();
p_estimator.getAllPartitions(partitions[idx], q, state.getBasePartition());
assertFalse(partitions[idx].isEmpty());
assertFalse(partitions[idx].contains(HStoreConstants.NULL_PARTITION_ID));
found = found || stmts[idx].equals(lastBatchStmt);
idx++;
} // FOR
if (is_last) assertTrue(StringUtil.join("\n", queries), found);
MarkovEstimate est = t_estimator.executeQueries(state, stmts, partitions);
assertNotNull(est);
for (int partition : catalogContext.getAllPartitionIds()) {
String debug = String.format("Batch %02d / Partition %02d / isLast=%s\n%s",
est.getBatchId(), partition, is_last, est.toString());
assertTrue(debug, est.isDoneProbabilitySet(partition));
assertTrue(debug, est.isWriteProbabilitySet(partition));
// assertTrue(debug, est.isReadOnlyProbabilitySet(partition));
if (touched.contains(partition) && is_last == false) { // || partition == state.getBasePartition())) {
assertFalse(debug, est.isDonePartition(thresholds, partition));
assertTrue(debug, est.isWritePartition(thresholds, partition));
} else {
assertTrue(debug, est.isDonePartition(thresholds, partition));
}
} // FOR
} // FOR
}