mirror of
https://github.com/postgres/postgres.git
synced 2025-11-10 17:42:29 +03:00
Modify hash_search() API to prevent future occurrences of the error
spotted by Qingqing Zhou. The HASH_ENTER action now automatically fails with elog(ERROR) on out-of-memory --- which incidentally lets us eliminate duplicate error checks in quite a bunch of places. If you really need the old return-NULL-on-out-of-memory behavior, you can ask for HASH_ENTER_NULL. But there is now an Assert in that path checking that you aren't hoping to get that behavior in a palloc-based hash table. Along the way, remove the old HASH_FIND_SAVE/HASH_REMOVE_SAVED actions, which were not being used anywhere anymore, and were surely too ugly and unsafe to want to see revived again.
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/storage/buffer/buf_table.c,v 1.40 2005/03/04 20:21:06 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/storage/buffer/buf_table.c,v 1.41 2005/05/29 04:23:04 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -110,11 +110,6 @@ BufTableInsert(BufferTag *tagPtr, int buf_id)
|
||||
result = (BufferLookupEnt *)
|
||||
hash_search(SharedBufHash, (void *) tagPtr, HASH_ENTER, &found);
|
||||
|
||||
if (!result)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_OUT_OF_MEMORY),
|
||||
errmsg("out of shared memory")));
|
||||
|
||||
if (found) /* found something already in the table */
|
||||
return result->id;
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/storage/buffer/localbuf.c,v 1.66 2005/03/19 23:27:05 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/storage/buffer/localbuf.c,v 1.67 2005/05/29 04:23:04 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -192,10 +192,6 @@ LocalBufferAlloc(Relation reln, BlockNumber blockNum, bool *foundPtr)
|
||||
|
||||
hresult = (LocalBufferLookupEnt *)
|
||||
hash_search(LocalBufHash, (void *) &newTag, HASH_ENTER, &found);
|
||||
if (!hresult)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_OUT_OF_MEMORY),
|
||||
errmsg("out of memory")));
|
||||
if (found) /* shouldn't happen */
|
||||
elog(ERROR, "local buffer hash table corrupted");
|
||||
hresult->id = b;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/storage/freespace/freespace.c,v 1.44 2005/04/24 03:51:49 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/storage/freespace/freespace.c,v 1.45 2005/05/29 04:23:04 tgl Exp $
|
||||
*
|
||||
*
|
||||
* NOTES:
|
||||
@@ -1036,10 +1036,6 @@ create_fsm_rel(RelFileNode *rel)
|
||||
(void *) rel,
|
||||
HASH_ENTER,
|
||||
&found);
|
||||
if (!fsmrel)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_OUT_OF_MEMORY),
|
||||
errmsg("out of shared memory")));
|
||||
|
||||
if (!found)
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/storage/ipc/shmem.c,v 1.83 2005/04/04 04:34:41 neilc Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/storage/ipc/shmem.c,v 1.84 2005/05/29 04:23:04 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -235,10 +235,6 @@ InitShmemIndex(void)
|
||||
|
||||
result = (ShmemIndexEnt *)
|
||||
hash_search(ShmemIndex, (void *) &item, HASH_ENTER, &found);
|
||||
if (!result)
|
||||
ereport(FATAL,
|
||||
(errcode(ERRCODE_OUT_OF_MEMORY),
|
||||
errmsg("out of shared memory")));
|
||||
|
||||
Assert(!found);
|
||||
|
||||
@@ -367,7 +363,7 @@ ShmemInitStruct(const char *name, Size size, bool *foundPtr)
|
||||
|
||||
/* look it up in the shmem index */
|
||||
result = (ShmemIndexEnt *)
|
||||
hash_search(ShmemIndex, (void *) &item, HASH_ENTER, foundPtr);
|
||||
hash_search(ShmemIndex, (void *) &item, HASH_ENTER_NULL, foundPtr);
|
||||
|
||||
if (!result)
|
||||
{
|
||||
@@ -375,7 +371,6 @@ ShmemInitStruct(const char *name, Size size, bool *foundPtr)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_OUT_OF_MEMORY),
|
||||
errmsg("out of shared memory")));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (*foundPtr)
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/storage/lmgr/lock.c,v 1.152 2005/05/19 23:30:18 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/storage/lmgr/lock.c,v 1.153 2005/05/29 04:23:04 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* Outside modules can create a lock table and acquire/release
|
||||
@@ -470,10 +470,6 @@ LockAcquire(LOCKMETHODID lockmethodid, LOCKTAG *locktag,
|
||||
locallock = (LOCALLOCK *) hash_search(LockMethodLocalHash[lockmethodid],
|
||||
(void *) &localtag,
|
||||
HASH_ENTER, &found);
|
||||
if (!locallock)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_OUT_OF_MEMORY),
|
||||
errmsg("out of memory")));
|
||||
|
||||
/*
|
||||
* if it's a new locallock object, initialize it
|
||||
@@ -531,7 +527,7 @@ LockAcquire(LOCKMETHODID lockmethodid, LOCKTAG *locktag,
|
||||
*/
|
||||
lock = (LOCK *) hash_search(LockMethodLockHash[lockmethodid],
|
||||
(void *) locktag,
|
||||
HASH_ENTER, &found);
|
||||
HASH_ENTER_NULL, &found);
|
||||
if (!lock)
|
||||
{
|
||||
LWLockRelease(masterLock);
|
||||
@@ -578,7 +574,7 @@ LockAcquire(LOCKMETHODID lockmethodid, LOCKTAG *locktag,
|
||||
*/
|
||||
proclock = (PROCLOCK *) hash_search(LockMethodProcLockHash[lockmethodid],
|
||||
(void *) &proclocktag,
|
||||
HASH_ENTER, &found);
|
||||
HASH_ENTER_NULL, &found);
|
||||
if (!proclock)
|
||||
{
|
||||
/* Ooops, not enough shmem for the proclock */
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/storage/smgr/md.c,v 1.114 2004/12/31 22:01:13 pgsql Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/storage/smgr/md.c,v 1.115 2005/05/29 04:23:05 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -805,9 +805,8 @@ register_dirty_segment(SMgrRelation reln, MdfdVec *seg)
|
||||
entry.rnode = reln->smgr_rnode;
|
||||
entry.segno = seg->mdfd_segno;
|
||||
|
||||
if (hash_search(pendingOpsTable, &entry, HASH_ENTER, NULL) != NULL)
|
||||
return true;
|
||||
/* out of memory: fall through to do it locally */
|
||||
(void) hash_search(pendingOpsTable, &entry, HASH_ENTER, NULL);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -838,10 +837,7 @@ RememberFsyncRequest(RelFileNode rnode, BlockNumber segno)
|
||||
entry.rnode = rnode;
|
||||
entry.segno = segno;
|
||||
|
||||
if (hash_search(pendingOpsTable, &entry, HASH_ENTER, NULL) == NULL)
|
||||
ereport(FATAL,
|
||||
(errcode(ERRCODE_OUT_OF_MEMORY),
|
||||
errmsg("out of memory")));
|
||||
(void) hash_search(pendingOpsTable, &entry, HASH_ENTER, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/storage/smgr/smgr.c,v 1.86 2005/03/20 22:00:53 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/storage/smgr/smgr.c,v 1.87 2005/05/29 04:23:05 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -207,10 +207,6 @@ smgropen(RelFileNode rnode)
|
||||
reln = (SMgrRelation) hash_search(SMgrRelationHash,
|
||||
(void *) &rnode,
|
||||
HASH_ENTER, &found);
|
||||
if (reln == NULL)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_OUT_OF_MEMORY),
|
||||
errmsg("out of memory")));
|
||||
|
||||
/* Initialize it if not present before */
|
||||
if (!found)
|
||||
|
||||
Reference in New Issue
Block a user