mirror of
https://github.com/postgres/postgres.git
synced 2025-09-08 00:47:37 +03:00
Further cleanup of dynahash.c API, in pursuit of portability and
readability. Bizarre '(long *) TRUE' return convention is gone, in favor of just raising an error internally in dynahash.c when we detect hashtable corruption. HashTableWalk is gone, in favor of using hash_seq_search directly, since it had no hope of working with non-LONGALIGNable datatypes. Simplify some other code that was made undesirably grotty by promixity to HashTableWalk.
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/buf_table.c,v 1.23 2001/10/01 05:36:13 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/buf_table.c,v 1.24 2001/10/05 17:28:12 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -62,21 +62,15 @@ BufferDesc *
|
||||
BufTableLookup(BufferTag *tagPtr)
|
||||
{
|
||||
BufferLookupEnt *result;
|
||||
bool found;
|
||||
|
||||
if (tagPtr->blockNum == P_NEW)
|
||||
return NULL;
|
||||
|
||||
result = (BufferLookupEnt *)
|
||||
hash_search(SharedBufHash, (void *) tagPtr, HASH_FIND, &found);
|
||||
|
||||
hash_search(SharedBufHash, (void *) tagPtr, HASH_FIND, NULL);
|
||||
if (!result)
|
||||
{
|
||||
elog(ERROR, "BufTableLookup: BufferLookup table corrupted");
|
||||
return NULL;
|
||||
}
|
||||
if (!found)
|
||||
return NULL;
|
||||
|
||||
return &(BufferDescriptors[result->id]);
|
||||
}
|
||||
|
||||
@@ -87,7 +81,6 @@ bool
|
||||
BufTableDelete(BufferDesc *buf)
|
||||
{
|
||||
BufferLookupEnt *result;
|
||||
bool found;
|
||||
|
||||
/*
|
||||
* buffer not initialized or has been removed from table already.
|
||||
@@ -99,10 +92,11 @@ BufTableDelete(BufferDesc *buf)
|
||||
buf->flags |= BM_DELETED;
|
||||
|
||||
result = (BufferLookupEnt *)
|
||||
hash_search(SharedBufHash, (void *) &(buf->tag), HASH_REMOVE, &found);
|
||||
hash_search(SharedBufHash, (void *) &(buf->tag), HASH_REMOVE, NULL);
|
||||
|
||||
if (!(result && found))
|
||||
if (!result)
|
||||
{
|
||||
/* shouldn't happen */
|
||||
elog(ERROR, "BufTableDelete: BufferLookup table corrupted");
|
||||
return FALSE;
|
||||
}
|
||||
@@ -134,14 +128,13 @@ BufTableInsert(BufferDesc *buf)
|
||||
|
||||
if (!result)
|
||||
{
|
||||
Assert(0);
|
||||
elog(ERROR, "BufTableInsert: BufferLookup table corrupted");
|
||||
elog(ERROR, "BufTableInsert: BufferLookup table out of memory");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* found something else in the table ! */
|
||||
if (found)
|
||||
{
|
||||
Assert(0);
|
||||
elog(ERROR, "BufTableInsert: BufferLookup table corrupted");
|
||||
return FALSE;
|
||||
}
|
||||
|
@@ -8,7 +8,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/storage/freespace/freespace.c,v 1.6 2001/10/01 05:36:14 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/storage/freespace/freespace.c,v 1.7 2001/10/05 17:28:12 tgl Exp $
|
||||
*
|
||||
*
|
||||
* NOTES:
|
||||
@@ -490,16 +490,12 @@ static FSMRelation *
|
||||
lookup_fsm_rel(RelFileNode *rel)
|
||||
{
|
||||
FSMRelation *fsmrel;
|
||||
bool found;
|
||||
|
||||
fsmrel = (FSMRelation *) hash_search(FreeSpaceMap->relHash,
|
||||
(void *) rel,
|
||||
HASH_FIND,
|
||||
&found);
|
||||
NULL);
|
||||
if (!fsmrel)
|
||||
elog(ERROR, "FreeSpaceMap hashtable corrupted");
|
||||
|
||||
if (!found)
|
||||
return NULL;
|
||||
|
||||
return fsmrel;
|
||||
@@ -523,7 +519,7 @@ create_fsm_rel(RelFileNode *rel)
|
||||
HASH_ENTER,
|
||||
&found);
|
||||
if (!fsmrel)
|
||||
elog(ERROR, "FreeSpaceMap hashtable corrupted");
|
||||
elog(ERROR, "FreeSpaceMap hashtable out of memory");
|
||||
|
||||
if (!found)
|
||||
{
|
||||
@@ -584,7 +580,6 @@ static void
|
||||
delete_fsm_rel(FSMRelation *fsmrel)
|
||||
{
|
||||
FSMRelation *result;
|
||||
bool found;
|
||||
|
||||
free_chunk_chain(fsmrel->relChunks);
|
||||
unlink_fsm_rel(fsmrel);
|
||||
@@ -592,8 +587,8 @@ delete_fsm_rel(FSMRelation *fsmrel)
|
||||
result = (FSMRelation *) hash_search(FreeSpaceMap->relHash,
|
||||
(void *) &(fsmrel->key),
|
||||
HASH_REMOVE,
|
||||
&found);
|
||||
if (!result || !found)
|
||||
NULL);
|
||||
if (!result)
|
||||
elog(ERROR, "FreeSpaceMap hashtable corrupted");
|
||||
}
|
||||
|
||||
|
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/shmem.c,v 1.60 2001/10/01 05:36:14 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/shmem.c,v 1.61 2001/10/05 17:28:12 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -210,7 +210,7 @@ InitShmemIndex(void)
|
||||
result = (ShmemIndexEnt *)
|
||||
hash_search(ShmemIndex, (void *) &item, HASH_ENTER, &found);
|
||||
if (!result)
|
||||
elog(FATAL, "InitShmemIndex: corrupted shmem index");
|
||||
elog(FATAL, "InitShmemIndex: Shmem Index out of memory");
|
||||
|
||||
Assert(ShmemBootstrap && !found);
|
||||
|
||||
@@ -234,7 +234,7 @@ InitShmemIndex(void)
|
||||
* table at once.
|
||||
*/
|
||||
HTAB *
|
||||
ShmemInitHash(char *name, /* table string name for shmem index */
|
||||
ShmemInitHash(const char *name, /* table string name for shmem index */
|
||||
long init_size, /* initial table size */
|
||||
long max_size, /* max size of the table */
|
||||
HASHCTL *infoP, /* info about key and bucket size */
|
||||
@@ -277,7 +277,7 @@ ShmemInitHash(char *name, /* table string name for shmem index */
|
||||
infoP->hctl = (HASHHDR *) location;
|
||||
infoP->dir = (HASHSEGMENT *) (((char *) location) + sizeof(HASHHDR));
|
||||
|
||||
return hash_create(init_size, infoP, hash_flags);
|
||||
return hash_create(name, init_size, infoP, hash_flags);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -295,7 +295,7 @@ ShmemInitHash(char *name, /* table string name for shmem index */
|
||||
* initialized).
|
||||
*/
|
||||
void *
|
||||
ShmemInitStruct(char *name, Size size, bool *foundPtr)
|
||||
ShmemInitStruct(const char *name, Size size, bool *foundPtr)
|
||||
{
|
||||
ShmemIndexEnt *result,
|
||||
item;
|
||||
@@ -328,7 +328,7 @@ ShmemInitStruct(char *name, Size size, bool *foundPtr)
|
||||
if (!result)
|
||||
{
|
||||
LWLockRelease(ShmemIndexLock);
|
||||
elog(ERROR, "ShmemInitStruct: Shmem Index corrupted");
|
||||
elog(ERROR, "ShmemInitStruct: Shmem Index out of memory");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -357,12 +357,12 @@ ShmemInitStruct(char *name, Size size, bool *foundPtr)
|
||||
{
|
||||
/* out of memory */
|
||||
Assert(ShmemIndex);
|
||||
hash_search(ShmemIndex, (void *) &item, HASH_REMOVE, foundPtr);
|
||||
hash_search(ShmemIndex, (void *) &item, HASH_REMOVE, NULL);
|
||||
LWLockRelease(ShmemIndexLock);
|
||||
*foundPtr = FALSE;
|
||||
|
||||
elog(NOTICE, "ShmemInitStruct: cannot allocate '%s'",
|
||||
name);
|
||||
*foundPtr = FALSE;
|
||||
return NULL;
|
||||
}
|
||||
result->size = size;
|
||||
|
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.99 2001/10/01 05:36:14 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.100 2001/10/05 17:28:12 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* Outside modules can create a lock table and acquire/release
|
||||
@@ -491,7 +491,8 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag,
|
||||
if (!lock)
|
||||
{
|
||||
LWLockRelease(masterLock);
|
||||
elog(FATAL, "LockAcquire: lock table %d is corrupted", lockmethod);
|
||||
elog(ERROR, "LockAcquire: lock table %d is out of memory",
|
||||
lockmethod);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@@ -537,7 +538,7 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag,
|
||||
if (!holder)
|
||||
{
|
||||
LWLockRelease(masterLock);
|
||||
elog(FATAL, "LockAcquire: holder table corrupted");
|
||||
elog(ERROR, "LockAcquire: holder table out of memory");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@@ -658,8 +659,8 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag,
|
||||
SHMQueueDelete(&holder->procLink);
|
||||
holder = (HOLDER *) hash_search(holderTable,
|
||||
(void *) holder,
|
||||
HASH_REMOVE, &found);
|
||||
if (!holder || !found)
|
||||
HASH_REMOVE, NULL);
|
||||
if (!holder)
|
||||
elog(NOTICE, "LockAcquire: remove holder, table corrupted");
|
||||
}
|
||||
else
|
||||
@@ -991,7 +992,6 @@ LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag,
|
||||
{
|
||||
LOCK *lock;
|
||||
LWLockId masterLock;
|
||||
bool found;
|
||||
LOCKMETHODTABLE *lockMethodTable;
|
||||
HOLDER *holder;
|
||||
HOLDERTAG holdertag;
|
||||
@@ -1023,20 +1023,13 @@ LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag,
|
||||
Assert(lockMethodTable->lockHash->hash == tag_hash);
|
||||
lock = (LOCK *) hash_search(lockMethodTable->lockHash,
|
||||
(void *) locktag,
|
||||
HASH_FIND, &found);
|
||||
HASH_FIND, NULL);
|
||||
|
||||
/*
|
||||
* let the caller print its own error message, too. Do not
|
||||
* elog(ERROR).
|
||||
*/
|
||||
if (!lock)
|
||||
{
|
||||
LWLockRelease(masterLock);
|
||||
elog(NOTICE, "LockRelease: locktable corrupted");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!found)
|
||||
{
|
||||
LWLockRelease(masterLock);
|
||||
elog(NOTICE, "LockRelease: no such lock");
|
||||
@@ -1056,12 +1049,12 @@ LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag,
|
||||
holderTable = lockMethodTable->holderHash;
|
||||
holder = (HOLDER *) hash_search(holderTable,
|
||||
(void *) &holdertag,
|
||||
HASH_FIND_SAVE, &found);
|
||||
if (!holder || !found)
|
||||
HASH_FIND_SAVE, NULL);
|
||||
if (!holder)
|
||||
{
|
||||
LWLockRelease(masterLock);
|
||||
#ifdef USER_LOCKS
|
||||
if (!found && lockmethod == USER_LOCKMETHOD)
|
||||
if (lockmethod == USER_LOCKMETHOD)
|
||||
elog(NOTICE, "LockRelease: no lock with this tag");
|
||||
else
|
||||
#endif
|
||||
@@ -1130,8 +1123,8 @@ LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag,
|
||||
lock = (LOCK *) hash_search(lockMethodTable->lockHash,
|
||||
(void *) &(lock->tag),
|
||||
HASH_REMOVE,
|
||||
&found);
|
||||
if (!lock || !found)
|
||||
NULL);
|
||||
if (!lock)
|
||||
{
|
||||
LWLockRelease(masterLock);
|
||||
elog(NOTICE, "LockRelease: remove lock, table corrupted");
|
||||
@@ -1159,8 +1152,8 @@ LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag,
|
||||
SHMQueueDelete(&holder->procLink);
|
||||
holder = (HOLDER *) hash_search(holderTable,
|
||||
(void *) &holder,
|
||||
HASH_REMOVE_SAVED, &found);
|
||||
if (!holder || !found)
|
||||
HASH_REMOVE_SAVED, NULL);
|
||||
if (!holder)
|
||||
{
|
||||
LWLockRelease(masterLock);
|
||||
elog(NOTICE, "LockRelease: remove holder, table corrupted");
|
||||
@@ -1201,7 +1194,6 @@ LockReleaseAll(LOCKMETHOD lockmethod, PROC *proc,
|
||||
int i,
|
||||
numLockModes;
|
||||
LOCK *lock;
|
||||
bool found;
|
||||
|
||||
#ifdef LOCK_DEBUG
|
||||
if (lockmethod == USER_LOCKMETHOD ? Trace_userlocks : Trace_locks)
|
||||
@@ -1313,8 +1305,8 @@ LockReleaseAll(LOCKMETHOD lockmethod, PROC *proc,
|
||||
holder = (HOLDER *) hash_search(lockMethodTable->holderHash,
|
||||
(void *) holder,
|
||||
HASH_REMOVE,
|
||||
&found);
|
||||
if (!holder || !found)
|
||||
NULL);
|
||||
if (!holder)
|
||||
{
|
||||
LWLockRelease(masterLock);
|
||||
elog(NOTICE, "LockReleaseAll: holder table corrupted");
|
||||
@@ -1323,7 +1315,6 @@ LockReleaseAll(LOCKMETHOD lockmethod, PROC *proc,
|
||||
|
||||
if (lock->nRequested == 0)
|
||||
{
|
||||
|
||||
/*
|
||||
* We've just released the last lock, so garbage-collect the
|
||||
* lock object.
|
||||
@@ -1332,8 +1323,8 @@ LockReleaseAll(LOCKMETHOD lockmethod, PROC *proc,
|
||||
Assert(lockMethodTable->lockHash->hash == tag_hash);
|
||||
lock = (LOCK *) hash_search(lockMethodTable->lockHash,
|
||||
(void *) &(lock->tag),
|
||||
HASH_REMOVE, &found);
|
||||
if (!lock || !found)
|
||||
HASH_REMOVE, NULL);
|
||||
if (!lock)
|
||||
{
|
||||
LWLockRelease(masterLock);
|
||||
elog(NOTICE, "LockReleaseAll: cannot remove lock from HTAB");
|
||||
@@ -1438,7 +1429,7 @@ void
|
||||
DumpAllLocks(void)
|
||||
{
|
||||
PROC *proc;
|
||||
HOLDER *holder = NULL;
|
||||
HOLDER *holder;
|
||||
LOCK *lock;
|
||||
int lockmethod = DEFAULT_LOCKMETHOD;
|
||||
LOCKMETHODTABLE *lockMethodTable;
|
||||
@@ -1460,8 +1451,7 @@ DumpAllLocks(void)
|
||||
LOCK_PRINT("DumpAllLocks: waiting on", proc->waitLock, 0);
|
||||
|
||||
hash_seq_init(&status, holderTable);
|
||||
while ((holder = (HOLDER *) hash_seq_search(&status)) &&
|
||||
(holder != (HOLDER *) TRUE))
|
||||
while ((holder = (HOLDER *) hash_seq_search(&status)) != NULL)
|
||||
{
|
||||
HOLDER_PRINT("DumpAllLocks", holder);
|
||||
|
||||
|
@@ -11,7 +11,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/storage/smgr/Attic/mm.c,v 1.26 2001/10/01 05:36:15 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/storage/smgr/Attic/mm.c,v 1.27 2001/10/05 17:28:12 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -186,7 +186,7 @@ mmcreate(Relation reln)
|
||||
if (entry == (MMRelHashEntry *) NULL)
|
||||
{
|
||||
LWLockRelease(MMCacheLock);
|
||||
elog(FATAL, "main memory storage mgr rel cache hash table corrupt");
|
||||
elog(FATAL, "main memory storage mgr hash table out of memory");
|
||||
}
|
||||
|
||||
if (found)
|
||||
@@ -214,7 +214,6 @@ mmunlink(RelFileNode rnode)
|
||||
int i;
|
||||
MMHashEntry *entry;
|
||||
MMRelHashEntry *rentry;
|
||||
bool found;
|
||||
MMRelTag rtag;
|
||||
|
||||
LWLockAcquire(MMCacheLock, LW_EXCLUSIVE);
|
||||
@@ -226,8 +225,8 @@ mmunlink(RelFileNode rnode)
|
||||
{
|
||||
entry = (MMHashEntry *) hash_search(MMCacheHT,
|
||||
(void *) &MMBlockTags[i],
|
||||
HASH_REMOVE, &found);
|
||||
if (entry == (MMHashEntry *) NULL || !found)
|
||||
HASH_REMOVE, NULL);
|
||||
if (entry == (MMHashEntry *) NULL)
|
||||
{
|
||||
LWLockRelease(MMCacheLock);
|
||||
elog(FATAL, "mmunlink: cache hash table corrupted");
|
||||
@@ -242,9 +241,9 @@ mmunlink(RelFileNode rnode)
|
||||
|
||||
rentry = (MMRelHashEntry *) hash_search(MMRelCacheHT,
|
||||
(void *) &rtag,
|
||||
HASH_REMOVE, &found);
|
||||
HASH_REMOVE, NULL);
|
||||
|
||||
if (rentry == (MMRelHashEntry *) NULL || !found)
|
||||
if (rentry == (MMRelHashEntry *) NULL)
|
||||
{
|
||||
LWLockRelease(MMCacheLock);
|
||||
elog(FATAL, "mmunlink: rel cache hash table corrupted");
|
||||
@@ -306,8 +305,8 @@ mmextend(Relation reln, BlockNumber blocknum, char *buffer)
|
||||
|
||||
rentry = (MMRelHashEntry *) hash_search(MMRelCacheHT,
|
||||
(void *) &rtag,
|
||||
HASH_FIND, &found);
|
||||
if (rentry == (MMRelHashEntry *) NULL || !found)
|
||||
HASH_FIND, NULL);
|
||||
if (rentry == (MMRelHashEntry *) NULL)
|
||||
{
|
||||
LWLockRelease(MMCacheLock);
|
||||
elog(FATAL, "mmextend: rel cache hash table corrupt");
|
||||
@@ -372,7 +371,6 @@ int
|
||||
mmread(Relation reln, BlockNumber blocknum, char *buffer)
|
||||
{
|
||||
MMHashEntry *entry;
|
||||
bool found;
|
||||
int offset;
|
||||
MMCacheTag tag;
|
||||
|
||||
@@ -387,15 +385,9 @@ mmread(Relation reln, BlockNumber blocknum, char *buffer)
|
||||
LWLockAcquire(MMCacheLock, LW_EXCLUSIVE);
|
||||
entry = (MMHashEntry *) hash_search(MMCacheHT,
|
||||
(void *) &tag,
|
||||
HASH_FIND, &found);
|
||||
HASH_FIND, NULL);
|
||||
|
||||
if (entry == (MMHashEntry *) NULL)
|
||||
{
|
||||
LWLockRelease(MMCacheLock);
|
||||
elog(FATAL, "mmread: hash table corrupt");
|
||||
}
|
||||
|
||||
if (!found)
|
||||
{
|
||||
/* reading nonexistent pages is defined to fill them with zeroes */
|
||||
LWLockRelease(MMCacheLock);
|
||||
@@ -420,7 +412,6 @@ int
|
||||
mmwrite(Relation reln, BlockNumber blocknum, char *buffer)
|
||||
{
|
||||
MMHashEntry *entry;
|
||||
bool found;
|
||||
int offset;
|
||||
MMCacheTag tag;
|
||||
|
||||
@@ -435,15 +426,9 @@ mmwrite(Relation reln, BlockNumber blocknum, char *buffer)
|
||||
LWLockAcquire(MMCacheLock, LW_EXCLUSIVE);
|
||||
entry = (MMHashEntry *) hash_search(MMCacheHT,
|
||||
(void *) &tag,
|
||||
HASH_FIND, &found);
|
||||
HASH_FIND, NULL);
|
||||
|
||||
if (entry == (MMHashEntry *) NULL)
|
||||
{
|
||||
LWLockRelease(MMCacheLock);
|
||||
elog(FATAL, "mmread: hash table corrupt");
|
||||
}
|
||||
|
||||
if (!found)
|
||||
{
|
||||
LWLockRelease(MMCacheLock);
|
||||
elog(FATAL, "mmwrite: hash table missing requested page");
|
||||
@@ -496,7 +481,6 @@ mmnblocks(Relation reln)
|
||||
{
|
||||
MMRelTag rtag;
|
||||
MMRelHashEntry *rentry;
|
||||
bool found;
|
||||
BlockNumber nblocks;
|
||||
|
||||
if (reln->rd_rel->relisshared)
|
||||
@@ -510,15 +494,9 @@ mmnblocks(Relation reln)
|
||||
|
||||
rentry = (MMRelHashEntry *) hash_search(MMRelCacheHT,
|
||||
(void *) &rtag,
|
||||
HASH_FIND, &found);
|
||||
HASH_FIND, NULL);
|
||||
|
||||
if (rentry == (MMRelHashEntry *) NULL)
|
||||
{
|
||||
LWLockRelease(MMCacheLock);
|
||||
elog(FATAL, "mmnblocks: rel cache hash table corrupt");
|
||||
}
|
||||
|
||||
if (found)
|
||||
if (rentry)
|
||||
nblocks = rentry->mmrhe_nblocks;
|
||||
else
|
||||
nblocks = InvalidBlockNumber;
|
||||
|
Reference in New Issue
Block a user