Back-patch fix for bogus clearing of BufferDirtiedByMe.
authorTom Lane <[email protected]>
Sun, 22 Oct 2000 20:33:22 +0000 (20:33 +0000)
committerTom Lane <[email protected]>
Sun, 22 Oct 2000 20:33:22 +0000 (20:33 +0000)
src/backend/storage/buffer/bufmgr.c

index 3f659ada4613e16e10779e3bec8ca0a14fc2bd77..8390feeaa4291430e160461457e4bd8540da1727 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.81.2.2 2000/10/04 07:50:00 inoue Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.81.2.3 2000/10/22 20:33:22 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -1656,7 +1656,6 @@ recheck:
            }
            /* Now we can do what we came for */
            buf->flags &= ~(BM_DIRTY | BM_JUST_DIRTIED);
-           ClearBufferDirtiedByMe(i, buf);
 
            /*
             * Release any refcount we may have.
@@ -1680,7 +1679,23 @@ recheck:
             */
            BufTableDelete(buf);
        }
+
+       /*
+        * Also check to see if BufferDirtiedByMe info for this buffer
+        * refers to the target relation, and clear it if so.  This is
+        * independent of whether the current contents of the buffer
+        * belong to the target relation!
+        *
+        * NOTE: we have no way to clear BufferDirtiedByMe info in other
+        * backends, but hopefully there are none with that bit set for
+        * this rel, since we hold exclusive lock on this rel.
+        */
+       if (BufferTagLastDirtied[i - 1].relId.relId == relid &&
+           (BufferTagLastDirtied[i - 1].relId.dbId == MyDatabaseId ||
+            BufferTagLastDirtied[i - 1].relId.dbId == (Oid) NULL))
+           BufferDirtiedByMe[i - 1] = false;
    }
+
    SpinRelease(BufMgrLock);
 }
 
@@ -1726,7 +1741,6 @@ recheck:
            }
            /* Now we can do what we came for */
            buf->flags &= ~(BM_DIRTY | BM_JUST_DIRTIED);
-           ClearBufferDirtiedByMe(i, buf);
 
            /*
             * The thing should be free, if caller has checked that no
@@ -1738,7 +1752,20 @@ recheck:
             */
            BufTableDelete(buf);
        }
+
+       /*
+        * Also check to see if BufferDirtiedByMe info for this buffer
+        * refers to the target database, and clear it if so.  This is
+        * independent of whether the current contents of the buffer
+        * belong to the target database!
+        *
+        * (Actually, this is probably unnecessary, since I shouldn't have
+        * ever dirtied pages of the target database, but...)
+        */
+       if (BufferTagLastDirtied[i - 1].relId.dbId == dbid)
+           BufferDirtiedByMe[i - 1] = false;
    }
+
    SpinRelease(BufMgrLock);
 }