*
* XXX. What about prepared transactions???
*/
+ elog(LOG, "[snaparray] snapshot compaction is needed");
new_running_xids = palloc(sizeof(TransactionId) * MaxBackends);
num_new_running_xids =
GetTopXids(new_xmax, MaxBackends, new_running_xids);
Assert(xids_added > certainly_removed_xids);
num_new_running_xids = last_summary_size + xids_added
- certainly_removed_xids;
- new_running_xids = palloc(sizeof(TransactionId)
- * num_new_running_xids);
/*
* Filter out the removed XIDs from the running XIDs, and add any
* XIDs between the old and new xmax that aren't listed as removed.
+ * We can skip this if it's already clear that the new snapshot
+ * will have no running XIDs.
*/
- result =
- SnapArrayComputeRunningXids(xmax, new_xmax,
- num_running_xids, running_xids,
- num_removed_xids, removed_xids,
- num_new_running_xids,
- new_running_xids);
- if (result > num_new_running_xids)
- elog(PANIC, "snapshot size calculation is bogus");
- num_new_running_xids = result;
+ if (num_new_running_xids > 0)
+ {
+ new_running_xids = palloc(sizeof(TransactionId)
+ * num_new_running_xids);
+ result =
+ SnapArrayComputeRunningXids(xmax, new_xmax,
+ num_running_xids, running_xids,
+ num_removed_xids, removed_xids,
+ num_new_running_xids,
+ new_running_xids);
+ if (result > num_new_running_xids)
+ elog(PANIC, "snapshot size calculation is bogus");
+ num_new_running_xids = result;
+ }
+ else
+ {
+ /* Placate the compiler. */
+ new_running_xids = NULL;
+ }
/*
* If the highest removed subxid has aged out of the snapshot,
* We've decided not to insert a new snapshot summary, so just
* append our completed XIDs.
*/
+ {
+ uint32 k;
+ StringInfoData buf;
+ initStringInfo(&buf);
+ appendStringInfo(&buf,
+ "appending %u xids: [%u",
+ (unsigned) 1 + nchildren, (unsigned) xid);
+ for (k = 0; k < nchildren; ++k)
+ appendStringInfo(&buf, " %lu", (unsigned long) children[k]);
+ appendStringInfo(&buf, "] at write_pointer = %llu",
+ (unsigned long long) write_pointer);
+ elog(LOG, "[snaparray] %s", buf.data);
+ }
/* Advance write pointer. */
SnapArrayAdvanceWritePointer(1 + nchildren);
TransactionId xmax_threshold;
uint64 write_pointer;
+ {
+ uint32 k;
+ StringInfoData buf;
+ initStringInfo(&buf);
+ appendStringInfo(&buf,
+ "xmax: %lu, latest_removed_subxid: %lu, %u xids: [",
+ (unsigned long) xmax, (unsigned long) latest_removed_subxid,
+ (unsigned) nxids);
+ for (k = 0; k < nxids; ++k)
+ appendStringInfo(&buf, k ? " %lu" : "%lu",
+ (unsigned long) running_xids[k]);
+ appendStringInfo(&buf, "]");
+ elog(LOG, "[snaparray] %s", buf.data);
+ }
+
/*
* When this function is invoked from elsewhere within snaparray.c,
* the caller should arrange to compact the snapshot if required. We