1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-11 10:01:57 +03:00

2nd try for the ARC strategy.

I added a couple more Assertions while tracking down the exact
cause of the former bug.

All 93 regression tests pass now.

Jan
This commit is contained in:
Jan Wieck
2003-11-13 14:57:15 +00:00
parent 923e994d79
commit 6b86d62b00
9 changed files with 967 additions and 225 deletions

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/buf_table.c,v 1.31 2003/11/13 05:34:58 wieck Exp $
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/buf_table.c,v 1.32 2003/11/13 14:57:15 wieck Exp $
*
*-------------------------------------------------------------------------
*/
@ -38,7 +38,7 @@ static HTAB *SharedBufHash;
* Initialize shmem hash table for mapping buffers
*/
void
InitBufTable(void)
InitBufTable(int size)
{
HASHCTL info;
@ -50,7 +50,7 @@ InitBufTable(void)
info.hash = tag_hash;
SharedBufHash = ShmemInitHash("Shared Buffer Lookup Table",
NBuffers, NBuffers,
size, size,
&info,
HASH_ELEM | HASH_FUNCTION);
@ -58,69 +58,36 @@ InitBufTable(void)
elog(FATAL, "could not initialize shared buffer hash table");
}
BufferDesc *
/*
* BufTableLookup
*/
int
BufTableLookup(BufferTag *tagPtr)
{
BufferLookupEnt *result;
if (tagPtr->blockNum == P_NEW)
return NULL;
return -1;
result = (BufferLookupEnt *)
hash_search(SharedBufHash, (void *) tagPtr, HASH_FIND, NULL);
if (!result)
return NULL;
return -1;
return &(BufferDescriptors[result->id]);
return result->id;
}
/*
* BufTableDelete
*/
bool
BufTableDelete(BufferDesc *buf)
{
BufferLookupEnt *result;
/*
* buffer not initialized or has been removed from table already.
* BM_DELETED keeps us from removing buffer twice.
*/
if (buf->flags & BM_DELETED)
return TRUE;
buf->flags |= BM_DELETED;
result = (BufferLookupEnt *)
hash_search(SharedBufHash, (void *) &(buf->tag), HASH_REMOVE, NULL);
if (!result) /* shouldn't happen */
elog(ERROR, "shared buffer hash table corrupted");
/*
* Clear the buffer's tag. This doesn't matter for the hash table,
* since the buffer is already removed from it, but it ensures that
* sequential searches through the buffer table won't think the buffer
* is still valid for its old page.
*/
buf->tag.rnode.relNode = InvalidOid;
buf->tag.rnode.tblNode = InvalidOid;
return TRUE;
}
bool
BufTableInsert(BufferDesc *buf)
BufTableInsert(BufferTag *tagPtr, Buffer buf_id)
{
BufferLookupEnt *result;
bool found;
/* cannot insert it twice */
Assert(buf->flags & BM_DELETED);
buf->flags &= ~(BM_DELETED);
result = (BufferLookupEnt *)
hash_search(SharedBufHash, (void *) &(buf->tag), HASH_ENTER, &found);
hash_search(SharedBufHash, (void *) tagPtr, HASH_ENTER, &found);
if (!result)
ereport(ERROR,
@ -130,7 +97,24 @@ BufTableInsert(BufferDesc *buf)
if (found) /* found something else in the table? */
elog(ERROR, "shared buffer hash table corrupted");
result->id = buf->buf_id;
result->id = buf_id;
return TRUE;
}
/*
* BufTableDelete
*/
bool
BufTableDelete(BufferTag *tagPtr)
{
BufferLookupEnt *result;
result = (BufferLookupEnt *)
hash_search(SharedBufHash, (void *) tagPtr, HASH_REMOVE, NULL);
if (!result) /* shouldn't happen */
elog(ERROR, "shared buffer hash table corrupted");
return TRUE;
}