*/
private DonePartitionsNotification computeDonePartitions(final LocalTransaction ts,
final Estimate estimate,
final FastIntHistogram fragmentsPerPartition,
final boolean finalTask) {
final PartitionSet touchedPartitions = ts.getPredictTouchedPartitions();
final PartitionSet donePartitions = ts.getDonePartitions();
// Compute the partitions that the txn will be finished with after this batch
PartitionSet estDonePartitions = null;
// If the finalTask flag is set to true, then the new done partitions
// is every partition that this txn has locked
if (finalTask) {
estDonePartitions = new PartitionSet(touchedPartitions);
}
// Otherwise, we'll rely on the transaction's current estimate to figure it out.
else {
if (estimate == null || estimate.isValid() == false) {
if (debug.val && estimate != null)
LOG.debug(String.format("%s - Unable to compute new done partitions because there " +
"is no valid estimate for the txn",
ts, estimate.getClass().getSimpleName()));
return (null);
}
estDonePartitions = estimate.getDonePartitions(this.thresholds);
if (estDonePartitions == null || estDonePartitions.isEmpty()) {
if (debug.val)
LOG.debug(String.format("%s - There are no new done partitions identified by %s",
ts, estimate.getClass().getSimpleName()));
return (null);
}
}
assert(estDonePartitions != null) : "Null done partitions for " + ts;
assert(estDonePartitions.isEmpty() == false) : "Empty done partitions for " + ts;
if (debug.val)
LOG.debug(String.format("%s - New estimated done partitions %s%s",
ts, estDonePartitions,
(trace.val ? "\n"+estimate : "")));
// Note that we can actually be done with ourself, if this txn is only going to execute queries
// at remote partitions. But we can't actually execute anything because this partition's only
// execution thread is going to be blocked. So we always do this so that we're not sending a
// useless message
estDonePartitions.remove(this.partitionId);
// Make sure that we only tell partitions that we actually touched, otherwise they will
// be stuck waiting for a finish request that will never come!
DonePartitionsNotification notify = new DonePartitionsNotification();
LocalPrepareCallback callback = null;
for (int partition : estDonePartitions.values()) {
// Only mark the txn done at this partition if the Estimate says we were done
// with it after executing this batch and it's a partition that we've locked.
if (donePartitions.contains(partition) || touchedPartitions.contains(partition) == false)
continue;