Commit 0f2e7948 authored by Hiroshi Inoue's avatar Hiroshi Inoue

Improve cache invalidation handling. Eespecially

this would fix TODO
* elog() flushes cache, try invalidating just entries from
  current xact, perhaps using invalidation cache
parent 57709359
......@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.62 1999/12/21 00:06:40 wieck Exp $
* $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.63 2000/01/10 06:30:50 inoue Exp $
*
*
* INTERFACE ROUTINES
......@@ -1262,7 +1262,7 @@ heap_insert(Relation relation, HeapTuple tup)
RelationPutHeapTupleAtEnd(relation, tup);
if (IsSystemRelationName(RelationGetRelationName(relation)))
RelationInvalidateHeapTuple(relation, tup);
RelationMark4RollbackHeapTuple(relation, tup);
return tup->t_data->t_oid;
}
......@@ -1473,6 +1473,8 @@ l2:
RelationPutHeapTupleAtEnd(relation, newtup);
LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE);
}
/* mark for rollback caches */
RelationMark4RollbackHeapTuple(relation, newtup);
/*
* New item in place, now record address of new tuple in t_ctid of old
......
......@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.57 2000/01/05 18:23:44 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.58 2000/01/10 06:30:50 inoue Exp $
*
* NOTES
* Transaction aborts can now occur two ways:
......@@ -165,6 +165,7 @@ static void AtAbort_Cache(void);
static void AtAbort_Locks(void);
static void AtAbort_Memory(void);
static void AtCommit_Cache(void);
static void AtCommit_LocalCache(void);
static void AtCommit_Locks(void);
static void AtCommit_Memory(void);
static void AtStart_Cache(void);
......@@ -512,8 +513,11 @@ CommandCounterIncrement()
CurrentTransactionStateData.scanCommandId = CurrentTransactionStateData.commandId;
/* make cache changes visible to me */
AtCommit_Cache();
/*
* make cache changes visible to me. AtCommit_LocalCache()
* instead of AtCommit_Cache() is called here.
*/
AtCommit_LocalCache();
AtStart_Cache();
}
......@@ -663,15 +667,26 @@ static void
AtCommit_Cache()
{
/* ----------------
* Make catalog changes visible to me for the next command.
* Other backends will not process my invalidation messages until
* after I commit and free my locks--though they will do
* unnecessary work if I abort.
* Make catalog changes visible to all backend.
* ----------------
*/
RegisterInvalid(true);
}
/* --------------------------------
* AtCommit_LocalCache
* --------------------------------
*/
static void
AtCommit_LocalCache()
{
/* ----------------
* Make catalog changes visible to me for the next command.
* ----------------
*/
ImmediateLocalInvalidation(true);
}
/* --------------------------------
* AtCommit_Locks
* --------------------------------
......
......@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/smgr/md.c,v 1.60 1999/11/16 04:13:56 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/storage/smgr/md.c,v 1.61 2000/01/10 06:30:51 inoue Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -20,6 +20,7 @@
#include "catalog/catalog.h"
#include "miscadmin.h"
#include "storage/smgr.h"
#include "utils/inval.h" /* ImmediateSharedRelationCacheInvalidate() */
#undef DIAGNOSTIC
......@@ -203,6 +204,15 @@ mdunlink(Relation reln)
*/
if (reln->rd_unlinked && reln->rd_fd < 0)
return SM_SUCCESS;
/*
* This call isn't good for independency of md stuff,but
* mdunlink() unlinks the base file immediately and couldn't
* be rollbacked in case of abort. We must guarantee all
* backends' relation cache invalidation here.
* This would be unnecessary if unlinking is postponed
* till end of transaction.
*/
ImmediateSharedRelationCacheInvalidate(reln);
/*
* Force all segments of the relation to be opened, so that we
* won't miss deleting any of them.
......@@ -779,6 +789,7 @@ mdtruncate(Relation reln, int nblocks)
#ifndef LET_OS_MANAGE_FILESIZE
MemoryContext oldcxt;
int priorblocks;
bool invalregistered = false;
#endif
/* NOTE: mdnblocks makes sure we have opened all existing segments,
......@@ -810,6 +821,20 @@ mdtruncate(Relation reln, int nblocks)
* a big file...
*/
FileTruncate(v->mdfd_vfd, 0);
/*
* To call ImmediateSharedRelationCacheInvalidate() here
* isn't good for independency of md stuff,but smgrunlink()
* removes the base file immediately and couldn't be
* rollbacked in case of abort. We must guarantee
* all backends' relation cache invalidation here.
* This would be unnecessary if the truncation is postponed
* till end of transaction.
*/
if (!invalregistered)
{
ImmediateSharedRelationCacheInvalidate(reln);
invalregistered = true;
}
FileUnlink(v->mdfd_vfd);
v = v->mdfd_chain;
Assert(ov != &Md_fdvec[fd]); /* we never drop the 1st segment */
......
This diff is collapsed.
......@@ -6,7 +6,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: inval.h,v 1.14 1999/11/21 01:58:20 tgl Exp $
* $Id: inval.h,v 1.15 2000/01/10 06:30:56 inoue Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -19,6 +19,14 @@ extern void DiscardInvalid(void);
extern void RegisterInvalid(bool send);
extern void ImmediateLocalInvalidation(bool send);
extern void RelationInvalidateHeapTuple(Relation relation, HeapTuple tuple);
extern void RelationMark4RollbackHeapTuple(Relation relation, HeapTuple tuple);
extern void ImmediateInvalidateSharedHeapTuple(Relation relation, HeapTuple tuple);
extern void ImmediateSharedRelationCacheInvalidate(Relation relation);
#endif /* INVAL_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment