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

Commite92a882

Browse files
committed
Modify hash_search() API to prevent future occurrences of the error
spotted by Qingqing Zhou. The HASH_ENTER action now automaticallyfails with elog(ERROR) on out-of-memory --- which incidentally letsus eliminate duplicate error checks in quite a bunch of places. Ifyou really need the old return-NULL-on-out-of-memory behavior, youcan ask for HASH_ENTER_NULL. But there is now an Assert in that pathchecking that you aren't hoping to get that behavior in a palloc-basedhash 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 uglyand unsafe to want to see revived again.
1 parentecd70d7 commite92a882

File tree

23 files changed

+90
-213
lines changed

23 files changed

+90
-213
lines changed

‎contrib/dblink/dblink.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2061,11 +2061,6 @@ createNewConnection(const char *name, remoteConn * con)
20612061
hentry= (remoteConnHashEnt*)hash_search(remoteConnHash,key,
20622062
HASH_ENTER,&found);
20632063

2064-
if (!hentry)
2065-
ereport(ERROR,
2066-
(errcode(ERRCODE_OUT_OF_MEMORY),
2067-
errmsg("out of memory")));
2068-
20692064
if (found)
20702065
ereport(ERROR,
20712066
(errcode(ERRCODE_DUPLICATE_OBJECT),

‎contrib/tablefunc/tablefunc.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,6 @@ do { \
144144
snprintf(key, MAX_CATNAME_LEN - 1, "%s", CATDESC->catname); \
145145
hentry = (crosstab_HashEnt*) hash_search(crosstab_HashTable, \
146146
key, HASH_ENTER, &found); \
147-
if (hentry == NULL) \
148-
ereport(ERROR, \
149-
(errcode(ERRCODE_OUT_OF_MEMORY), \
150-
errmsg("out of memory"))); \
151147
if (found) \
152148
ereport(ERROR, \
153149
(errcode(ERRCODE_DUPLICATE_OBJECT), \

‎src/backend/access/transam/xlogutils.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
1212
* Portions Copyright (c) 1994, Regents of the University of California
1313
*
14-
* $PostgreSQL: pgsql/src/backend/access/transam/xlogutils.c,v 1.36 2005/01/10 20:02:19 tgl Exp $
14+
* $PostgreSQL: pgsql/src/backend/access/transam/xlogutils.c,v 1.37 2005/05/29 04:23:03 tgl Exp $
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
@@ -223,9 +223,6 @@ XLogOpenRelation(bool redo, RmgrId rmid, RelFileNode rnode)
223223
hentry= (XLogRelCacheEntry*)
224224
hash_search(_xlrelcache, (void*)&rnode,HASH_ENTER,&found);
225225

226-
if (hentry==NULL)
227-
elog(PANIC,"XLogOpenRelation: out of memory for cache");
228-
229226
if (found)
230227
elog(PANIC,"XLogOpenRelation: file found on insert into cache");
231228

‎src/backend/commands/prepare.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Copyright (c) 2002-2005, PostgreSQL Global Development Group
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.37 2005/05/24 04:18:04 momjian Exp $
13+
* $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.38 2005/05/29 04:23:03 tgl Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -346,9 +346,9 @@ StorePreparedStatement(const char *stmt_name,
346346
HASH_ENTER,
347347
&found);
348348

349-
/* Shouldn't get afailure, nor aduplicate entry */
350-
if (!entry||found)
351-
elog(ERROR,"could not store prepared statement \"%s\"",
349+
/* Shouldn't get a duplicate entry */
350+
if (found)
351+
elog(ERROR,"duplicate prepared statement \"%s\"",
352352
stmt_name);
353353

354354
/* Fill in the hash table entry with copied data */

‎src/backend/executor/execGrouping.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/executor/execGrouping.c,v 1.14 2005/03/16 21:38:06 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/executor/execGrouping.c,v 1.15 2005/05/29 04:23:03 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -379,13 +379,9 @@ LookupTupleHashEntry(TupleHashTable hashtable, TupleTableSlot *slot,
379379
}
380380
else
381381
{
382-
/* created new entry ... we hope */
383-
if (entry==NULL)
384-
ereport(ERROR,
385-
(errcode(ERRCODE_OUT_OF_MEMORY),
386-
errmsg("out of memory")));
387-
388382
/*
383+
* created new entry
384+
*
389385
* Zero any caller-requested space in the entry. (This zaps
390386
* the "key data" dynahash.c copied into the new entry, but we
391387
* don't care since we're about to overwrite it anyway.)

‎src/backend/nodes/tidbitmap.c

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* Copyright (c) 2003-2005, PostgreSQL Global Development Group
2424
*
2525
* IDENTIFICATION
26-
* $PostgreSQL: pgsql/src/backend/nodes/tidbitmap.c,v 1.3 2005/05/17 00:43:47 tgl Exp $
26+
* $PostgreSQL: pgsql/src/backend/nodes/tidbitmap.c,v 1.4 2005/05/29 04:23:03 tgl Exp $
2727
*
2828
*-------------------------------------------------------------------------
2929
*/
@@ -220,10 +220,6 @@ tbm_create_pagetable(TIDBitmap *tbm)
220220
page= (PagetableEntry*)hash_search(tbm->pagetable,
221221
(void*)&tbm->entry1.blockno,
222222
HASH_ENTER,&found);
223-
if (page==NULL)
224-
ereport(ERROR,
225-
(errcode(ERRCODE_OUT_OF_MEMORY),
226-
errmsg("out of memory")));
227223
Assert(!found);
228224
memcpy(page,&tbm->entry1,sizeof(PagetableEntry));
229225
}
@@ -726,10 +722,6 @@ tbm_get_pageentry(TIDBitmap *tbm, BlockNumber pageno)
726722
page= (PagetableEntry*)hash_search(tbm->pagetable,
727723
(void*)&pageno,
728724
HASH_ENTER,&found);
729-
if (page==NULL)
730-
ereport(ERROR,
731-
(errcode(ERRCODE_OUT_OF_MEMORY),
732-
errmsg("out of memory")));
733725
}
734726

735727
/* Initialize it if not present before */
@@ -820,10 +812,6 @@ tbm_mark_page_lossy(TIDBitmap *tbm, BlockNumber pageno)
820812
page= (PagetableEntry*)hash_search(tbm->pagetable,
821813
(void*)&chunk_pageno,
822814
HASH_ENTER,&found);
823-
if (page==NULL)
824-
ereport(ERROR,
825-
(errcode(ERRCODE_OUT_OF_MEMORY),
826-
errmsg("out of memory")));
827815

828816
/* Initialize it if not present before */
829817
if (!found)

‎src/backend/postmaster/pgstat.c

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
*Copyright (c) 2001-2005, PostgreSQL Global Development Group
1515
*
16-
*$PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.94 2005/05/11 01:41:40 neilc Exp $
16+
*$PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.95 2005/05/29 04:23:03 tgl Exp $
1717
* ----------
1818
*/
1919
#include"postgres.h"
@@ -2061,10 +2061,6 @@ pgstat_get_db_entry(int databaseid)
20612061
result= (PgStat_StatDBEntry*)hash_search(pgStatDBHash,
20622062
&databaseid,
20632063
HASH_ENTER,&found);
2064-
if (result==NULL)
2065-
ereport(ERROR,
2066-
(errcode(ERRCODE_OUT_OF_MEMORY),
2067-
errmsg("out of memory in statistics collector --- abort")));
20682064

20692065
/* If not found, initialize the new one. */
20702066
if (!found)
@@ -2126,10 +2122,6 @@ pgstat_sub_backend(int procpid)
21262122
(void*)&procpid,
21272123
HASH_ENTER,
21282124
&found);
2129-
if (deadbe==NULL)
2130-
ereport(ERROR,
2131-
(errcode(ERRCODE_OUT_OF_MEMORY),
2132-
errmsg("out of memory in statistics collector --- abort")));
21332125

21342126
if (!found)
21352127
{
@@ -2435,12 +2427,6 @@ pgstat_read_statsfile(HTAB **dbhash, Oid onlydb,
24352427
(void*)&dbbuf.databaseid,
24362428
HASH_ENTER,
24372429
&found);
2438-
if (dbentry==NULL)
2439-
{
2440-
ereport(ERROR,
2441-
(errcode(ERRCODE_OUT_OF_MEMORY),
2442-
errmsg("out of memory")));
2443-
}
24442430
if (found)
24452431
{
24462432
ereport(pgStatRunningInCollector ?LOG :WARNING,
@@ -2503,10 +2489,6 @@ pgstat_read_statsfile(HTAB **dbhash, Oid onlydb,
25032489
tabentry= (PgStat_StatTabEntry*)hash_search(tabhash,
25042490
(void*)&tabbuf.tableid,
25052491
HASH_ENTER,&found);
2506-
if (tabentry==NULL)
2507-
ereport(ERROR,
2508-
(errcode(ERRCODE_OUT_OF_MEMORY),
2509-
errmsg("out of memory")));
25102492

25112493
if (found)
25122494
{
@@ -2730,10 +2712,6 @@ pgstat_recv_tabstat(PgStat_MsgTabstat *msg, int len)
27302712
tabentry= (PgStat_StatTabEntry*)hash_search(dbentry->tables,
27312713
(void*)&(tabmsg[i].t_id),
27322714
HASH_ENTER,&found);
2733-
if (tabentry==NULL)
2734-
ereport(ERROR,
2735-
(errcode(ERRCODE_OUT_OF_MEMORY),
2736-
errmsg("out of memory in statistics collector --- abort")));
27372715

27382716
if (!found)
27392717
{

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
*
1515
* IDENTIFICATION
16-
* $PostgreSQL: pgsql/src/backend/storage/buffer/buf_table.c,v 1.40 2005/03/04 20:21:06 tgl Exp $
16+
* $PostgreSQL: pgsql/src/backend/storage/buffer/buf_table.c,v 1.41 2005/05/29 04:23:04 tgl Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -110,11 +110,6 @@ BufTableInsert(BufferTag *tagPtr, int buf_id)
110110
result= (BufferLookupEnt*)
111111
hash_search(SharedBufHash, (void*)tagPtr,HASH_ENTER,&found);
112112

113-
if (!result)
114-
ereport(ERROR,
115-
(errcode(ERRCODE_OUT_OF_MEMORY),
116-
errmsg("out of shared memory")));
117-
118113
if (found)/* found something already in the table */
119114
returnresult->id;
120115

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

Lines changed: 1 addition & 5 deletions
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.66 2005/03/1923:27:05 tgl Exp $
12+
* $PostgreSQL: pgsql/src/backend/storage/buffer/localbuf.c,v 1.67 2005/05/29 04:23:04 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -192,10 +192,6 @@ LocalBufferAlloc(Relation reln, BlockNumber blockNum, bool *foundPtr)
192192

193193
hresult= (LocalBufferLookupEnt*)
194194
hash_search(LocalBufHash, (void*)&newTag,HASH_ENTER,&found);
195-
if (!hresult)
196-
ereport(ERROR,
197-
(errcode(ERRCODE_OUT_OF_MEMORY),
198-
errmsg("out of memory")));
199195
if (found)/* shouldn't happen */
200196
elog(ERROR,"local buffer hash table corrupted");
201197
hresult->id=b;

‎src/backend/storage/freespace/freespace.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/storage/freespace/freespace.c,v 1.44 2005/04/24 03:51:49 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/storage/freespace/freespace.c,v 1.45 2005/05/29 04:23:04 tgl Exp $
1212
*
1313
*
1414
* NOTES:
@@ -1036,10 +1036,6 @@ create_fsm_rel(RelFileNode *rel)
10361036
(void*)rel,
10371037
HASH_ENTER,
10381038
&found);
1039-
if (!fsmrel)
1040-
ereport(ERROR,
1041-
(errcode(ERRCODE_OUT_OF_MEMORY),
1042-
errmsg("out of shared memory")));
10431039

10441040
if (!found)
10451041
{

‎src/backend/storage/ipc/shmem.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/storage/ipc/shmem.c,v 1.83 2005/04/04 04:34:41 neilc Exp $
11+
* $PostgreSQL: pgsql/src/backend/storage/ipc/shmem.c,v 1.84 2005/05/29 04:23:04 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -235,10 +235,6 @@ InitShmemIndex(void)
235235

236236
result= (ShmemIndexEnt*)
237237
hash_search(ShmemIndex, (void*)&item,HASH_ENTER,&found);
238-
if (!result)
239-
ereport(FATAL,
240-
(errcode(ERRCODE_OUT_OF_MEMORY),
241-
errmsg("out of shared memory")));
242238

243239
Assert(!found);
244240

@@ -367,15 +363,14 @@ ShmemInitStruct(const char *name, Size size, bool *foundPtr)
367363

368364
/* look it up in the shmem index */
369365
result= (ShmemIndexEnt*)
370-
hash_search(ShmemIndex, (void*)&item,HASH_ENTER,foundPtr);
366+
hash_search(ShmemIndex, (void*)&item,HASH_ENTER_NULL,foundPtr);
371367

372368
if (!result)
373369
{
374370
SpinLockRelease(ShmemIndexLock);
375371
ereport(ERROR,
376372
(errcode(ERRCODE_OUT_OF_MEMORY),
377373
errmsg("out of shared memory")));
378-
returnNULL;
379374
}
380375

381376
if (*foundPtr)

‎src/backend/storage/lmgr/lock.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/storage/lmgr/lock.c,v 1.152 2005/05/1923:30:18 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/storage/lmgr/lock.c,v 1.153 2005/05/29 04:23:04 tgl Exp $
1212
*
1313
* NOTES
1414
* Outside modules can create a lock table and acquire/release
@@ -470,10 +470,6 @@ LockAcquire(LOCKMETHODID lockmethodid, LOCKTAG *locktag,
470470
locallock= (LOCALLOCK*)hash_search(LockMethodLocalHash[lockmethodid],
471471
(void*)&localtag,
472472
HASH_ENTER,&found);
473-
if (!locallock)
474-
ereport(ERROR,
475-
(errcode(ERRCODE_OUT_OF_MEMORY),
476-
errmsg("out of memory")));
477473

478474
/*
479475
* if it's a new locallock object, initialize it
@@ -531,7 +527,7 @@ LockAcquire(LOCKMETHODID lockmethodid, LOCKTAG *locktag,
531527
*/
532528
lock= (LOCK*)hash_search(LockMethodLockHash[lockmethodid],
533529
(void*)locktag,
534-
HASH_ENTER,&found);
530+
HASH_ENTER_NULL,&found);
535531
if (!lock)
536532
{
537533
LWLockRelease(masterLock);
@@ -578,7 +574,7 @@ LockAcquire(LOCKMETHODID lockmethodid, LOCKTAG *locktag,
578574
*/
579575
proclock= (PROCLOCK*)hash_search(LockMethodProcLockHash[lockmethodid],
580576
(void*)&proclocktag,
581-
HASH_ENTER,&found);
577+
HASH_ENTER_NULL,&found);
582578
if (!proclock)
583579
{
584580
/* Ooops, not enough shmem for the proclock */

‎src/backend/storage/smgr/md.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/storage/smgr/md.c,v 1.114 2004/12/31 22:01:13 pgsql Exp $
11+
* $PostgreSQL: pgsql/src/backend/storage/smgr/md.c,v 1.115 2005/05/29 04:23:05 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -805,9 +805,8 @@ register_dirty_segment(SMgrRelation reln, MdfdVec *seg)
805805
entry.rnode=reln->smgr_rnode;
806806
entry.segno=seg->mdfd_segno;
807807

808-
if (hash_search(pendingOpsTable,&entry,HASH_ENTER,NULL)!=NULL)
809-
return true;
810-
/* out of memory: fall through to do it locally */
808+
(void)hash_search(pendingOpsTable,&entry,HASH_ENTER,NULL);
809+
return true;
811810
}
812811
else
813812
{
@@ -838,10 +837,7 @@ RememberFsyncRequest(RelFileNode rnode, BlockNumber segno)
838837
entry.rnode=rnode;
839838
entry.segno=segno;
840839

841-
if (hash_search(pendingOpsTable,&entry,HASH_ENTER,NULL)==NULL)
842-
ereport(FATAL,
843-
(errcode(ERRCODE_OUT_OF_MEMORY),
844-
errmsg("out of memory")));
840+
(void)hash_search(pendingOpsTable,&entry,HASH_ENTER,NULL);
845841
}
846842

847843
/*

‎src/backend/storage/smgr/smgr.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $PostgreSQL: pgsql/src/backend/storage/smgr/smgr.c,v 1.86 2005/03/20 22:00:53 tgl Exp $
14+
* $PostgreSQL: pgsql/src/backend/storage/smgr/smgr.c,v 1.87 2005/05/29 04:23:05 tgl Exp $
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
@@ -207,10 +207,6 @@ smgropen(RelFileNode rnode)
207207
reln= (SMgrRelation)hash_search(SMgrRelationHash,
208208
(void*)&rnode,
209209
HASH_ENTER,&found);
210-
if (reln==NULL)
211-
ereport(ERROR,
212-
(errcode(ERRCODE_OUT_OF_MEMORY),
213-
errmsg("out of memory")));
214210

215211
/* Initialize it if not present before */
216212
if (!found)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp