Debugging code - rip me out.
authorRobert Haas <rhaas@postgresql.org>
Thu, 25 Aug 2011 13:34:06 +0000 (09:34 -0400)
committerRobert Haas <rhaas@postgresql.org>
Fri, 14 Oct 2011 18:38:13 +0000 (14:38 -0400)
src/backend/storage/ipc/snaparray.c

index a0f3538152e40a06e2aefdca543c5861bc63b373..8b040253ce486b6f39a48ef1a5f31bbe53259f15 100644 (file)
@@ -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