Apply 0007-Need-to-pin-and-take-cleanup-lock-on-every-b-tree-le.patch with some docs...
authorSimon Riggs <simon@2ndQuadrant.com>
Mon, 5 Oct 2009 13:28:34 +0000 (14:28 +0100)
committerSimon Riggs <simon@2ndQuadrant.com>
Mon, 5 Oct 2009 13:28:34 +0000 (14:28 +0100)
All code changes approved, especially the neat tweak to improve performance in btree vacuum.

src/backend/access/nbtree/nbtxlog.c
src/backend/access/transam/clog.c
src/backend/access/transam/xlog.c
src/include/access/xlog.h

index aea48d9d548491ac4e7c57c9106967b0be2fcb51..6b78781b94894693baa16d6afcd099768212b97d 100644 (file)
@@ -470,9 +470,6 @@ btree_xlog_vacuum(XLogRecPtr lsn, XLogRecord *record)
        Page            page;
        BTPageOpaque opaque;
 
-       if (record->xl_info & XLR_BKP_BLOCK_1)
-               return;
-
        xlrec = (xl_btree_vacuum *) XLogRecGetData(record);
 
        /*
@@ -502,6 +499,15 @@ btree_xlog_vacuum(XLogRecPtr lsn, XLogRecord *record)
                }
        }
 
+       /*
+        * If the block was restored from a full page image, nothing more to do.
+        * The RestoreBkpBlocks() call already pinned and took cleanup lock on
+        * it. We call RestoreBkpBlocks() after skipping blocks so that we get
+        * sequential disk access.
+        */
+       if (record->xl_info & XLR_BKP_BLOCK_1)
+               return;
+
        /*
         * Like in btvacuumpage(), we need to take a cleanup lock on every leaf
         * page. See nbtree/README for details.
@@ -830,17 +836,17 @@ btree_redo(XLogRecPtr lsn, XLogRecord *record)
                                                                        true);
 
                        ResolveRecoveryConflictWithVirtualXIDs(backends,
-                                                                       "drop tablespace",
+                                                                       "b-tree delete",
                                                                        CONFLICT_MODE_ERROR_DEFERRABLE,
                                                                        lsn);
                }
        }
 
        /*
-        * Exclusive lock on a btree block is as good as a Cleanup lock,
-        * so need to special case btree delete and vacuum.
+        * Vacuum needs to pin and take cleanup lock on every leaf page,
+        * a regular exclusive lock is enough for all other purposes.
         */
-       RestoreBkpBlocks(lsn, record, false);
+       RestoreBkpBlocks(lsn, record, (info == XLOG_BTREE_VACUUM));
 
        switch (info)
        {
index 90de8b61b574061aa4c73b3834e0a12e14ef0ed8..c6c27a79bc41317d89859ebdd0249aa8d431388d 100644 (file)
@@ -35,7 +35,6 @@
 #include "access/clog.h"
 #include "access/slru.h"
 #include "access/transam.h"
-#include "access/xact.h"
 #include "access/xlogutils.h"
 #include "pg_trace.h"
 #include "postmaster/bgwriter.h"
index 8308e22ed0891c72ecd9d193a9430fe6047e617a..b5a7f6670165e4030eae295a54287bdaeadfb574 100644 (file)
@@ -3338,9 +3338,9 @@ CleanupBackupHistory(void)
  * ignoring them as already applied, but that's not a huge drawback.
  *
  * If 'cleanup' is true, a cleanup lock is used when restoring blocks.
- * Otherwise, a normal exclusive lock is used. At the moment, that's just
- * pro forma, because there can't be any regular backends in the system
- * during recovery.  The 'cleanup' argument applies to all backup blocks
+ * Otherwise, a normal exclusive lock is used. This is important to
+ * safeguard these changes against users accessing the system during recovery.
+ *  The 'cleanup' argument applies to all backup blocks
  * in the WAL record, that suffices for now.
  */
 void
index 7a9308204cd578ff1129cccfb68a9dfefbb51f60..7eec091e6104eef9bb6597eaef79333f6b56ca91 100644 (file)
@@ -20,7 +20,6 @@
 
 /* Handy constant for an invalid xlog recptr */
 static const XLogRecPtr InvalidXLogRecPtr = {0, 0};
-#define XLogRecPtrIsValid(xp)  (!(xp.xlogid ==0 && xp.xrecoff == 0))
 
 /*
  * The overall layout of an XLOG record is: