// probably doesn't hurt
// to do it right in case we need it later
// At this point we know what the transaction actually would do using
// the TransactionEstimator's
// internal Markov models.
MarkovEstimatorState s = this.t_estimator.processTransactionTrace(txn_trace);
assert (s != null);
Procedure catalog_proc = txn_trace.getCatalogItem(catalogContext.database);
if (debug.val) {
LOG.debug("Measuring MarkovEstimate Accuracy: " + txn_trace);
if (trace.val) {
LOG.trace("Estimated: " + ((MarkovEstimate)s.getInitialEstimate()).getMarkovPath());
LOG.trace("Actual: " + s.getActualPath());
}
}
double cost = 0.0d;
this.e_read_partitions.clear();
this.e_write_partitions.clear();
MarkovEstimate initialEst = s.getInitialEstimate();
assert(initialEst != null);
assert(initialEst.isInitialized());
for (Integer partition : initialEst.getTouchedPartitions(this.thresholds)) {
if (initialEst.isDonePartition(this.thresholds, partition.intValue()) == false) {
for (MarkovVertex v : initialEst.getMarkovPath()) {
if (v.getPartitions().contains(partition) == false)
continue;
if (((Statement) v.getCatalogItem()).getReadonly()) {
this.e_read_partitions.add(partition);
} else {
this.e_write_partitions.add(partition);
}
} // FOR
}
} // FOR
List<MarkovVertex> initialPath = initialEst.getMarkovPath();
List<MarkovVertex> actualPath = s.getActualPath();
this.a_read_partitions.clear();
this.a_write_partitions.clear();
MarkovUtil.getReadWritePartitions(actualPath, this.a_read_partitions, this.a_write_partitions);
// Try fast version
try {
if (this.force_full_comparison || !this.comparePathsFast(CollectionUtil.last(initialPath), actualPath)) {
// Otherwise we have to do the full path comparison to figure
// out just how wrong we are
cost = this.comparePathsFull(s);
this.full_path_counter.put(catalog_proc);
} else {
this.fast_path_counter.put(catalog_proc);
}
} catch (Throwable ex) {
System.err.println(txn_trace.debug(catalogContext.database));
System.err.println("COST = " + cost);
System.err.println("BASE PARTITION = " + s.getBasePartition());
System.err.println("PENALTIES = " + this.penalties);
System.err.println("ESTIMATED PARTITIONS: " + this.e_all_partitions);
System.err.println("ACTUAL PARTITIONS: " + this.a_all_partitions);
System.err.println("MARKOV GRAPH: " + MarkovUtil.exportGraphviz(s.getMarkovGraph(), true, null).writeToTempFile(catalog_proc));
System.err.println();
String e_path = "ESTIMATED PATH:\n" + StringUtil.join("\n", initialEst.getMarkovPath());
String a_path = "ACTUAL PATH:\n" + StringUtil.join("\n", s.getActualPath());
System.err.println(StringUtil.columns(e_path, a_path));
System.err.println("MARKOV ESTIMATE:\n" + s.getInitialEstimate());
throw new RuntimeException(ex);
}
this.t_estimator.destroyEstimatorState(s);