1
0
mirror of https://github.com/postgres/postgres.git synced 2025-12-06 00:02:13 +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:
Tom Lane
2005-05-29 04:23:07 +00:00
parent ecd70d7526
commit e92a88272e
23 changed files with 95 additions and 218 deletions

View File

@@ -13,7 +13,7 @@
*
* Copyright (c) 2001-2005, PostgreSQL Global Development Group
*
* $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.94 2005/05/11 01:41:40 neilc Exp $
* $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.95 2005/05/29 04:23:03 tgl Exp $
* ----------
*/
#include "postgres.h"
@@ -2061,10 +2061,6 @@ pgstat_get_db_entry(int databaseid)
result = (PgStat_StatDBEntry *) hash_search(pgStatDBHash,
&databaseid,
HASH_ENTER, &found);
if (result == NULL)
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory in statistics collector --- abort")));
/* If not found, initialize the new one. */
if (!found)
@@ -2126,10 +2122,6 @@ pgstat_sub_backend(int procpid)
(void *) &procpid,
HASH_ENTER,
&found);
if (deadbe == NULL)
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory in statistics collector --- abort")));
if (!found)
{
@@ -2435,12 +2427,6 @@ pgstat_read_statsfile(HTAB **dbhash, Oid onlydb,
(void *) &dbbuf.databaseid,
HASH_ENTER,
&found);
if (dbentry == NULL)
{
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
}
if (found)
{
ereport(pgStatRunningInCollector ? LOG : WARNING,
@@ -2503,10 +2489,6 @@ pgstat_read_statsfile(HTAB **dbhash, Oid onlydb,
tabentry = (PgStat_StatTabEntry *) hash_search(tabhash,
(void *) &tabbuf.tableid,
HASH_ENTER, &found);
if (tabentry == NULL)
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
if (found)
{
@@ -2730,10 +2712,6 @@ pgstat_recv_tabstat(PgStat_MsgTabstat *msg, int len)
tabentry = (PgStat_StatTabEntry *) hash_search(dbentry->tables,
(void *) &(tabmsg[i].t_id),
HASH_ENTER, &found);
if (tabentry == NULL)
ereport(ERROR,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory in statistics collector --- abort")));
if (!found)
{