From 2f48e5487cf235087d67c58074aa4797f09f69c1 Mon Sep 17 00:00:00 2001 From: Robert Haas Date: Thu, 25 Aug 2011 09:34:06 -0400 Subject: [PATCH] Debugging code - rip me out. --- src/backend/storage/ipc/snaparray.c | 61 +++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 11 deletions(-) diff --git a/src/backend/storage/ipc/snaparray.c b/src/backend/storage/ipc/snaparray.c index a0f3538152..8b040253ce 100644 --- a/src/backend/storage/ipc/snaparray.c +++ b/src/backend/storage/ipc/snaparray.c @@ -427,6 +427,7 @@ SnapArrayRemoveRunningXids(TransactionId xid, int nchildren, * * 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); @@ -449,22 +450,32 @@ SnapArrayRemoveRunningXids(TransactionId xid, int nchildren, 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, @@ -491,6 +502,19 @@ SnapArrayRemoveRunningXids(TransactionId xid, int nchildren, * 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); @@ -803,6 +827,21 @@ SnapArrayWriteSnapshotSummary(TransactionId xmax, 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 -- 2.39.5