From 67797231263701553ce0e11c34e473efe8c10096 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sun, 22 Oct 2000 20:33:22 +0000 Subject: [PATCH] Back-patch fix for bogus clearing of BufferDirtiedByMe. --- src/backend/storage/buffer/bufmgr.c | 33 ++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 3f659ada46..8390feeaa4 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -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); }