Skip to content

Commit 0f2e794

Browse files
author
Hiroshi Inoue
committed
Improve cache invalidation handling. Eespecially this would fix TODO * elog() flushes cache, try invalidating just entries from current xact, perhaps using invalidation cache
1 parent 5770935 commit 0f2e794

File tree

5 files changed

+471
-46
lines changed

5 files changed

+471
-46
lines changed

src/backend/access/heap/heapam.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.62 1999/12/21 00:06:40 wieck Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.63 2000/01/10 06:30:50 inoue Exp $
1111
*
1212
*
1313
* INTERFACE ROUTINES
@@ -1262,7 +1262,7 @@ heap_insert(Relation relation, HeapTuple tup)
12621262
RelationPutHeapTupleAtEnd(relation, tup);
12631263

12641264
if (IsSystemRelationName(RelationGetRelationName(relation)))
1265-
RelationInvalidateHeapTuple(relation, tup);
1265+
RelationMark4RollbackHeapTuple(relation, tup);
12661266

12671267
return tup->t_data->t_oid;
12681268
}
@@ -1473,6 +1473,8 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
14731473
RelationPutHeapTupleAtEnd(relation, newtup);
14741474
LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE);
14751475
}
1476+
/* mark for rollback caches */
1477+
RelationMark4RollbackHeapTuple(relation, newtup);
14761478

14771479
/*
14781480
* New item in place, now record address of new tuple in t_ctid of old

src/backend/access/transam/xact.c

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.57 2000/01/05 18:23:44 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.58 2000/01/10 06:30:50 inoue Exp $
1111
*
1212
* NOTES
1313
* Transaction aborts can now occur two ways:
@@ -165,6 +165,7 @@ static void AtAbort_Cache(void);
165165
static void AtAbort_Locks(void);
166166
static void AtAbort_Memory(void);
167167
static void AtCommit_Cache(void);
168+
static void AtCommit_LocalCache(void);
168169
static void AtCommit_Locks(void);
169170
static void AtCommit_Memory(void);
170171
static void AtStart_Cache(void);
@@ -512,8 +513,11 @@ CommandCounterIncrement()
512513

513514
CurrentTransactionStateData.scanCommandId = CurrentTransactionStateData.commandId;
514515

515-
/* make cache changes visible to me */
516-
AtCommit_Cache();
516+
/*
517+
* make cache changes visible to me. AtCommit_LocalCache()
518+
* instead of AtCommit_Cache() is called here.
519+
*/
520+
AtCommit_LocalCache();
517521
AtStart_Cache();
518522

519523
}
@@ -663,15 +667,26 @@ static void
663667
AtCommit_Cache()
664668
{
665669
/* ----------------
666-
* Make catalog changes visible to me for the next command.
667-
* Other backends will not process my invalidation messages until
668-
* after I commit and free my locks--though they will do
669-
* unnecessary work if I abort.
670+
* Make catalog changes visible to all backend.
670671
* ----------------
671672
*/
672673
RegisterInvalid(true);
673674
}
674675

676+
/* --------------------------------
677+
* AtCommit_LocalCache
678+
* --------------------------------
679+
*/
680+
static void
681+
AtCommit_LocalCache()
682+
{
683+
/* ----------------
684+
* Make catalog changes visible to me for the next command.
685+
* ----------------
686+
*/
687+
ImmediateLocalInvalidation(true);
688+
}
689+
675690
/* --------------------------------
676691
* AtCommit_Locks
677692
* --------------------------------

src/backend/storage/smgr/md.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/storage/smgr/md.c,v 1.60 1999/11/16 04:13:56 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/storage/smgr/md.c,v 1.61 2000/01/10 06:30:51 inoue Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -20,6 +20,7 @@
2020
#include "catalog/catalog.h"
2121
#include "miscadmin.h"
2222
#include "storage/smgr.h"
23+
#include "utils/inval.h" /* ImmediateSharedRelationCacheInvalidate() */
2324

2425
#undef DIAGNOSTIC
2526

@@ -203,6 +204,15 @@ mdunlink(Relation reln)
203204
*/
204205
if (reln->rd_unlinked && reln->rd_fd < 0)
205206
return SM_SUCCESS;
207+
/*
208+
* This call isn't good for independency of md stuff,but
209+
* mdunlink() unlinks the base file immediately and couldn't
210+
* be rollbacked in case of abort. We must guarantee all
211+
* backends' relation cache invalidation here.
212+
* This would be unnecessary if unlinking is postponed
213+
* till end of transaction.
214+
*/
215+
ImmediateSharedRelationCacheInvalidate(reln);
206216
/*
207217
* Force all segments of the relation to be opened, so that we
208218
* won't miss deleting any of them.
@@ -779,6 +789,7 @@ mdtruncate(Relation reln, int nblocks)
779789
#ifndef LET_OS_MANAGE_FILESIZE
780790
MemoryContext oldcxt;
781791
int priorblocks;
792+
bool invalregistered = false;
782793
#endif
783794

784795
/* NOTE: mdnblocks makes sure we have opened all existing segments,
@@ -810,6 +821,20 @@ mdtruncate(Relation reln, int nblocks)
810821
* a big file...
811822
*/
812823
FileTruncate(v->mdfd_vfd, 0);
824+
/*
825+
* To call ImmediateSharedRelationCacheInvalidate() here
826+
* isn't good for independency of md stuff,but smgrunlink()
827+
* removes the base file immediately and couldn't be
828+
* rollbacked in case of abort. We must guarantee
829+
* all backends' relation cache invalidation here.
830+
* This would be unnecessary if the truncation is postponed
831+
* till end of transaction.
832+
*/
833+
if (!invalregistered)
834+
{
835+
ImmediateSharedRelationCacheInvalidate(reln);
836+
invalregistered = true;
837+
}
813838
FileUnlink(v->mdfd_vfd);
814839
v = v->mdfd_chain;
815840
Assert(ov != &Md_fdvec[fd]); /* we never drop the 1st segment */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy