3434 * Portions Copyright (c) 1994, Regents of the University of California
3535 *
3636 * IDENTIFICATION
37- * $Header: /cvsroot/pgsql/src/backend/utils/cache/inval.c,v 1.42 2001/03/22 03:59:57 momjian Exp $
37+ * $Header: /cvsroot/pgsql/src/backend/utils/cache/inval.c,v 1.43 2001/06/01 20:23:06 tgl Exp $
3838 *
3939 * Note - this code is real crufty... badly needs a rewrite to improve
4040 * readability and portability. (Shouldn't assume Oid == Index, for example)
5353
5454/*
5555 * private invalidation structures
56- *
5756 */
5857
5958typedef struct InvalidationUserData
@@ -102,7 +101,6 @@ typedef InvalidationMessageData *InvalidationMessage;
102101
103102/*
104103 * variables and macros
105- *
106104 */
107105
108106/*
@@ -152,7 +150,6 @@ static void InvalidationMessageRegisterSharedInvalid(InvalidationMessage message
152150/*
153151 * InvalidationEntryAllocate
154152 * Allocates an invalidation entry.
155- *
156153 */
157154static InvalidationEntry
158155InvalidationEntryAllocate (uint16 size )
@@ -161,6 +158,8 @@ InvalidationEntryAllocate(uint16 size)
161158
162159 entryDataP = (InvalidationEntryData * )
163160 malloc (sizeof (char * ) + size ); /* XXX alignment */
161+ if (entryDataP == NULL )
162+ elog (ERROR , "Memory exhausted in InvalidationEntryAllocate" );
164163 entryDataP -> nextP = NULL ;
165164 return (Pointer ) & entryDataP -> userData ;
166165}
@@ -169,7 +168,6 @@ InvalidationEntryAllocate(uint16 size)
169168 * LocalInvalidRegister
170169 * Link an invalidation entry into a chain of them. Really ugly
171170 * coding here.
172- *
173171 */
174172static LocalInvalid
175173LocalInvalidRegister (LocalInvalid invalid ,
@@ -187,7 +185,6 @@ LocalInvalidRegister(LocalInvalid invalid,
187185 * LocalInvalidInvalidate
188186 * Processes, then frees all entries in a local cache
189187 * invalidation list unless freemember parameter is false.
190- *
191188 */
192189static void
193190LocalInvalidInvalidate (LocalInvalid invalid ,
@@ -258,7 +255,6 @@ elog(DEBUG, "CacheIdRegisterLocalRollback(%d, %d, [%d, %d])", \
258255
259256/*
260257 * CacheIdRegisterSpecifiedLocalInvalid
261- *
262258 */
263259static LocalInvalid
264260CacheIdRegisterSpecifiedLocalInvalid (LocalInvalid invalid ,
@@ -270,14 +266,12 @@ CacheIdRegisterSpecifiedLocalInvalid(LocalInvalid invalid,
270266
271267 /*
272268 * debugging stuff
273- *
274269 */
275270 CacheIdRegisterSpecifiedLocalInvalid_DEBUG1 ;
276271
277272 /*
278273 * create a message describing the system catalog tuple we wish to
279274 * invalidate.
280- *
281275 */
282276 message = (InvalidationMessage )
283277 InvalidationEntryAllocate (sizeof (InvalidationMessageData ));
@@ -290,15 +284,13 @@ CacheIdRegisterSpecifiedLocalInvalid(LocalInvalid invalid,
290284
291285 /*
292286 * Add message to linked list of unprocessed messages.
293- *
294287 */
295288 invalid = LocalInvalidRegister (invalid , (InvalidationEntry ) message );
296289 return invalid ;
297290}
298291
299292/*
300293 * CacheIdRegisterLocalInvalid
301- *
302294 */
303295static void
304296CacheIdRegisterLocalInvalid (int cacheId ,
@@ -308,28 +300,24 @@ CacheIdRegisterLocalInvalid(int cacheId,
308300
309301 /*
310302 * debugging stuff
311- *
312303 */
313304 CacheIdRegisterLocalInvalid_DEBUG1 ;
314305
315306 /*
316307 * Add message to InvalidForall linked list.
317- *
318308 */
319309 InvalidForall = CacheIdRegisterSpecifiedLocalInvalid (InvalidForall ,
320310 cacheId , hashIndex , pointer );
321311
322312 /*
323313 * Add message to InvalidLocal linked list.
324- *
325314 */
326315 InvalidLocal = CacheIdRegisterSpecifiedLocalInvalid (InvalidLocal ,
327316 cacheId , hashIndex , pointer );
328317}
329318
330319/*
331320 * CacheIdRegisterLocalRollback
332- *
333321 */
334322static void
335323CacheIdRegisterLocalRollback (int cacheId ,
@@ -339,21 +327,18 @@ CacheIdRegisterLocalRollback(int cacheId,
339327
340328 /*
341329 * debugging stuff
342- *
343330 */
344331 CacheIdRegisterLocalRollback_DEBUG1 ;
345332
346333 /*
347334 * Add message to RollbackStack linked list.
348- *
349335 */
350336 RollbackStack = CacheIdRegisterSpecifiedLocalInvalid (
351337 RollbackStack , cacheId , hashIndex , pointer );
352338}
353339
354340/*
355341 * RelationIdRegisterSpecifiedLocalInvalid
356- *
357342 */
358343static LocalInvalid
359344RelationIdRegisterSpecifiedLocalInvalid (LocalInvalid invalid ,
@@ -363,7 +348,6 @@ RelationIdRegisterSpecifiedLocalInvalid(LocalInvalid invalid,
363348
364349 /*
365350 * debugging stuff
366- *
367351 */
368352#ifdef INVALIDDEBUG
369353 elog (DEBUG , "RelationRegisterSpecifiedLocalInvalid(%u, %u)" , relationId ,
@@ -373,7 +357,6 @@ RelationIdRegisterSpecifiedLocalInvalid(LocalInvalid invalid,
373357 /*
374358 * create a message describing the relation descriptor we wish to
375359 * invalidate.
376- *
377360 */
378361 message = (InvalidationMessage )
379362 InvalidationEntryAllocate (sizeof (InvalidationMessageData ));
@@ -384,23 +367,20 @@ RelationIdRegisterSpecifiedLocalInvalid(LocalInvalid invalid,
384367
385368 /*
386369 * Add message to linked list of unprocessed messages.
387- *
388370 */
389371 invalid = LocalInvalidRegister (invalid , (InvalidationEntry ) message );
390372 return invalid ;
391373}
392374
393375/*
394376 * RelationIdRegisterLocalInvalid
395- *
396377 */
397378static void
398379RelationIdRegisterLocalInvalid (Oid relationId , Oid objectId )
399380{
400381
401382 /*
402383 * debugging stuff
403- *
404384 */
405385#ifdef INVALIDDEBUG
406386 elog (DEBUG , "RelationRegisterLocalInvalid(%u, %u)" , relationId ,
@@ -409,30 +389,26 @@ RelationIdRegisterLocalInvalid(Oid relationId, Oid objectId)
409389
410390 /*
411391 * Add message to InvalidForall linked list.
412- *
413392 */
414393 InvalidForall = RelationIdRegisterSpecifiedLocalInvalid (InvalidForall ,
415394 relationId , objectId );
416395
417396 /*
418397 * Add message to InvalidLocal linked list.
419- *
420398 */
421399 InvalidLocal = RelationIdRegisterSpecifiedLocalInvalid (InvalidLocal ,
422400 relationId , objectId );
423401}
424402
425403/*
426404 * RelationIdRegisterLocalRollback
427- *
428405 */
429406static void
430407RelationIdRegisterLocalRollback (Oid relationId , Oid objectId )
431408{
432409
433410 /*
434411 * debugging stuff
435- *
436412 */
437413#ifdef INVALIDDEBUG
438414 elog (DEBUG , "RelationRegisterLocalRollback(%u, %u)" , relationId ,
@@ -441,7 +417,6 @@ RelationIdRegisterLocalRollback(Oid relationId, Oid objectId)
441417
442418 /*
443419 * Add message to RollbackStack linked list.
444- *
445420 */
446421 RollbackStack = RelationIdRegisterSpecifiedLocalInvalid (
447422 RollbackStack , relationId , objectId );
@@ -453,7 +428,6 @@ RelationIdRegisterLocalRollback(Oid relationId, Oid objectId)
453428 * This routine can invalidate a tuple in a system catalog cache
454429 * or a cached relation descriptor. You pay your money and you
455430 * take your chances...
456- *
457431 */
458432#ifdef INVALIDDEBUG
459433#define CacheIdInvalidate_DEBUG1 \
@@ -472,7 +446,6 @@ CacheIdInvalidate(Index cacheId,
472446 /*
473447 * assume that if the item pointer is valid, then we are invalidating
474448 * an item in the specified system catalog cache.
475- *
476449 */
477450 if (ItemPointerIsValid (pointer ))
478451 {
@@ -485,7 +458,6 @@ CacheIdInvalidate(Index cacheId,
485458 /*
486459 * if the cacheId is the oid of any of the following system relations,
487460 * then assume we are invalidating a relation descriptor
488- *
489461 */
490462 if (cacheId == RelOid_pg_class )
491463 {
@@ -501,7 +473,6 @@ CacheIdInvalidate(Index cacheId,
501473
502474 /*
503475 * Yow! the caller asked us to invalidate something else.
504- *
505476 */
506477 elog (FATAL , "CacheIdInvalidate: cacheId=%d relation id?" , cacheId );
507478}
@@ -512,7 +483,6 @@ CacheIdInvalidate(Index cacheId,
512483 * This blows away all tuples in the system catalog caches and
513484 * all the cached relation descriptors (and closes their files too).
514485 * Relation descriptors that have positive refcounts are then rebuilt.
515- *
516486 */
517487static void
518488ResetSystemCaches (void )
@@ -523,7 +493,6 @@ ResetSystemCaches(void)
523493
524494/*
525495 * InvalidationMessageRegisterSharedInvalid
526- *
527496 */
528497#ifdef INVALIDDEBUG
529498#define InvalidationMessageRegisterSharedInvalid_DEBUG1 \
@@ -575,7 +544,6 @@ InvalidationMessageRegisterSharedInvalid(InvalidationMessage message)
575544
576545/*
577546 * InvalidationMessageCacheInvalidate
578- *
579547 */
580548#ifdef INVALIDDEBUG
581549#define InvalidationMessageCacheInvalidate_DEBUG1 \
@@ -624,7 +592,6 @@ InvalidationMessageCacheInvalidate(InvalidationMessage message)
624592
625593/*
626594 * PrepareToInvalidateRelationCache
627- *
628595 */
629596static void
630597PrepareToInvalidateRelationCache (Relation relation ,
@@ -636,13 +603,11 @@ PrepareToInvalidateRelationCache(Relation relation,
636603
637604 /*
638605 * get the relation object id
639- *
640606 */
641607 relationId = RelationGetRelid (relation );
642608
643609 /*
644610 * is it one of the ones we need to send an SI message for?
645- *
646611 */
647612 if (relationId == RelOid_pg_class )
648613 objectId = tuple -> t_data -> t_oid ;
@@ -653,7 +618,6 @@ PrepareToInvalidateRelationCache(Relation relation,
653618
654619 /*
655620 * register the relcache-invalidation action in the appropriate list
656- *
657621 */
658622 Assert (PointerIsValid (function ));
659623
@@ -674,7 +638,6 @@ DiscardInvalid(void)
674638
675639 /*
676640 * debugging stuff
677- *
678641 */
679642#ifdef INVALIDDEBUG
680643 elog (DEBUG , "DiscardInvalid called" );
@@ -697,15 +660,13 @@ RegisterInvalid(bool send)
697660
698661 /*
699662 * debugging stuff
700- *
701663 */
702664#ifdef INVALIDDEBUG
703665 elog (DEBUG , "RegisterInvalid(%d) called" , send );
704666#endif /* defined(INVALIDDEBUG) */
705667
706668 /*
707669 * Process and free the current list of inval messages.
708- *
709670 */
710671
711672 DiscardInvalidStack (& InvalidLocal );
@@ -741,15 +702,13 @@ ImmediateLocalInvalidation(bool send)
741702
742703 /*
743704 * debugging stuff
744- *
745705 */
746706#ifdef INVALIDDEBUG
747707 elog (DEBUG , "ImmediateLocalInvalidation(%d) called" , send );
748708#endif /* defined(INVALIDDEBUG) */
749709
750710 /*
751711 * Process and free the local list of inval messages.
752- *
753712 */
754713
755714 if (send )
@@ -801,7 +760,6 @@ PrepareForTupleInvalidation(Relation relation, HeapTuple tuple,
801760
802761 /*
803762 * sanity checks
804- *
805763 */
806764 Assert (RelationIsValid (relation ));
807765 Assert (HeapTupleIsValid (tuple ));
@@ -813,14 +771,12 @@ PrepareForTupleInvalidation(Relation relation, HeapTuple tuple,
813771 * We only need to worry about invalidation for tuples that are in
814772 * system relations; user-relation tuples are never in catcaches and
815773 * can't affect the relcache either.
816- *
817774 */
818775 if (!IsSystemRelationName (NameStr (RelationGetForm (relation )-> relname )))
819776 return ;
820777
821778 /*
822779 * debugging stuff
823- *
824780 */
825781 PrepareForTupleInvalidation_DEBUG1 ;
826782
0 commit comments