Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc859308

Browse files
committed
DropRelFileNodeBuffers failed to fix the state of the lookup hash table
that was added to localbuf.c in 8.1; therefore, applying it to a temp tableleft corrupt lookup state in memory. The only case where this had asignificant chance of causing problems was an ON COMMIT DELETE ROWS temptable; the other possible paths left bogus state that was unlikely tobe used again. Per report from Csaba Nagy.
1 parent84bb387 commitc859308

File tree

3 files changed

+54
-23
lines changed

3 files changed

+54
-23
lines changed

‎src/backend/storage/buffer/bufmgr.c

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/storage/buffer/bufmgr.c,v 1.198 2005/10/27 17:07:58 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/storage/buffer/bufmgr.c,v 1.199 2005/11/17 17:42:02 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1384,34 +1384,17 @@ DropRelFileNodeBuffers(RelFileNode rnode, bool istemp,
13841384
BlockNumberfirstDelBlock)
13851385
{
13861386
inti;
1387-
volatileBufferDesc*bufHdr;
13881387

13891388
if (istemp)
13901389
{
1391-
for (i=0;i<NLocBuffer;i++)
1392-
{
1393-
bufHdr=&LocalBufferDescriptors[i];
1394-
if (RelFileNodeEquals(bufHdr->tag.rnode,rnode)&&
1395-
bufHdr->tag.blockNum >=firstDelBlock)
1396-
{
1397-
if (LocalRefCount[i]!=0)
1398-
elog(ERROR,"block %u of %u/%u/%u is still referenced (local %u)",
1399-
bufHdr->tag.blockNum,
1400-
bufHdr->tag.rnode.spcNode,
1401-
bufHdr->tag.rnode.dbNode,
1402-
bufHdr->tag.rnode.relNode,
1403-
LocalRefCount[i]);
1404-
CLEAR_BUFFERTAG(bufHdr->tag);
1405-
bufHdr->flags=0;
1406-
bufHdr->usage_count=0;
1407-
}
1408-
}
1390+
DropRelFileNodeLocalBuffers(rnode,firstDelBlock);
14091391
return;
14101392
}
14111393

14121394
for (i=0;i<NBuffers;i++)
14131395
{
1414-
bufHdr=&BufferDescriptors[i];
1396+
volatileBufferDesc*bufHdr=&BufferDescriptors[i];
1397+
14151398
LockBufHdr(bufHdr);
14161399
if (RelFileNodeEquals(bufHdr->tag.rnode,rnode)&&
14171400
bufHdr->tag.blockNum >=firstDelBlock)

‎src/backend/storage/buffer/localbuf.c

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/storage/buffer/localbuf.c,v 1.70 2005/10/15 02:49:25 momjian Exp $
12+
* $PostgreSQL: pgsql/src/backend/storage/buffer/localbuf.c,v 1.71 2005/11/17 17:42:02 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -241,6 +241,52 @@ WriteLocalBuffer(Buffer buffer, bool release)
241241
}
242242
}
243243

244+
/*
245+
* DropRelFileNodeLocalBuffers
246+
*This function removes from the buffer pool all the pages of the
247+
*specified relation that have block numbers >= firstDelBlock.
248+
*(In particular, with firstDelBlock = 0, all pages are removed.)
249+
*Dirty pages are simply dropped, without bothering to write them
250+
*out first.Therefore, this is NOT rollback-able, and so should be
251+
*used only with extreme caution!
252+
*
253+
*See DropRelFileNodeBuffers in bufmgr.c for more notes.
254+
*/
255+
void
256+
DropRelFileNodeLocalBuffers(RelFileNodernode,BlockNumberfirstDelBlock)
257+
{
258+
inti;
259+
260+
for (i=0;i<NLocBuffer;i++)
261+
{
262+
BufferDesc*bufHdr=&LocalBufferDescriptors[i];
263+
LocalBufferLookupEnt*hresult;
264+
265+
if ((bufHdr->flags&BM_TAG_VALID)&&
266+
RelFileNodeEquals(bufHdr->tag.rnode,rnode)&&
267+
bufHdr->tag.blockNum >=firstDelBlock)
268+
{
269+
if (LocalRefCount[i]!=0)
270+
elog(ERROR,"block %u of %u/%u/%u is still referenced (local %u)",
271+
bufHdr->tag.blockNum,
272+
bufHdr->tag.rnode.spcNode,
273+
bufHdr->tag.rnode.dbNode,
274+
bufHdr->tag.rnode.relNode,
275+
LocalRefCount[i]);
276+
/* Remove entry from hashtable */
277+
hresult= (LocalBufferLookupEnt*)
278+
hash_search(LocalBufHash, (void*)&bufHdr->tag,
279+
HASH_REMOVE,NULL);
280+
if (!hresult)/* shouldn't happen */
281+
elog(ERROR,"local buffer hash table corrupted");
282+
/* Mark buffer invalid */
283+
CLEAR_BUFFERTAG(bufHdr->tag);
284+
bufHdr->flags=0;
285+
bufHdr->usage_count=0;
286+
}
287+
}
288+
}
289+
244290
/*
245291
* InitLocalBuffers -
246292
* init the local buffer cache. Since most queries (esp. multi-user ones)

‎src/include/storage/buf_internals.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
99
* Portions Copyright (c) 1994, Regents of the University of California
1010
*
11-
* $PostgreSQL: pgsql/src/include/storage/buf_internals.h,v 1.81 2005/10/15 02:49:46 momjian Exp $
11+
* $PostgreSQL: pgsql/src/include/storage/buf_internals.h,v 1.82 2005/11/17 17:42:02 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -198,6 +198,8 @@ extern void BufTableDelete(BufferTag *tagPtr);
198198
externBufferDesc*LocalBufferAlloc(Relationreln,BlockNumberblockNum,
199199
bool*foundPtr);
200200
externvoidWriteLocalBuffer(Bufferbuffer,boolrelease);
201+
externvoidDropRelFileNodeLocalBuffers(RelFileNodernode,
202+
BlockNumberfirstDelBlock);
201203
externvoidAtEOXact_LocalBuffers(boolisCommit);
202204

203205
#endif/* BUFMGR_INTERNALS_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp