aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>1999-09-24 00:25:33 +0000
committerTom Lane <tgl@sss.pgh.pa.us>1999-09-24 00:25:33 +0000
commite812458b273be00bde34fb74991ab4a99c24ab30 (patch)
treee7460ae5c0344782f6f6068399f6f7eab5be96f6 /src/backend/access
parentad791c1d140af97d93ee98883e2c45413d6f9836 (diff)
downloadpostgresql-e812458b273be00bde34fb74991ab4a99c24ab30.tar.gz
postgresql-e812458b273be00bde34fb74991ab4a99c24ab30.zip
Several changes here, not very related but touching some of the same files.
* Buffer refcount cleanup (per my "progress report" to pghackers, 9/22). * Add links to backend PROC structs to sinval's array of per-backend info, and use these links for routines that need to check the state of all backends (rather than the slow, complicated search of the ShmemIndex hashtable that was used before). Add databaseOID to PROC structs. * Use this to implement an interlock that prevents DESTROY DATABASE of a database containing running backends. (It's a little tricky to prevent a concurrently-starting backend from getting in there, since the new backend is not able to lock anything at the time it tries to look up its database in pg_database. My solution is to recheck that the DB is OK at the end of InitPostgres. It may not be a 100% solution, but it's a lot better than no interlock at all...) * In ALTER TABLE RENAME, flush buffers for the relation before doing the rename of the physical files, to ensure we don't get failures later from mdblindwrt(). * Update TRUNCATE patch so that it actually compiles against current sources :-(. You should do "make clean all" after pulling these changes.
Diffstat (limited to 'src/backend/access')
-rw-r--r--src/backend/access/gist/gist.c4
-rw-r--r--src/backend/access/hash/hash.c5
-rw-r--r--src/backend/access/heap/heapam.c36
-rw-r--r--src/backend/access/rtree/rtree.c4
-rw-r--r--src/backend/access/transam/xact.c12
5 files changed, 32 insertions, 29 deletions
diff --git a/src/backend/access/gist/gist.c b/src/backend/access/gist/gist.c
index 0535fd6278d..bc3338b1156 100644
--- a/src/backend/access/gist/gist.c
+++ b/src/backend/access/gist/gist.c
@@ -6,7 +6,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/access/gist/gist.c,v 1.45 1999/09/18 19:05:46 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/access/gist/gist.c,v 1.46 1999/09/24 00:23:42 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -141,7 +141,7 @@ gistbuild(Relation heap,
tupleTable = ExecCreateTupleTable(1);
slot = ExecAllocTableSlot(tupleTable);
econtext = makeNode(ExprContext);
- FillDummyExprContext(econtext, slot, hd, buffer);
+ FillDummyExprContext(econtext, slot, hd, InvalidBuffer);
}
else
/* shut the compiler up */
diff --git a/src/backend/access/hash/hash.c b/src/backend/access/hash/hash.c
index 6e729008e85..ca7c14d30df 100644
--- a/src/backend/access/hash/hash.c
+++ b/src/backend/access/hash/hash.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/access/hash/hash.c,v 1.31 1999/09/18 19:05:52 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/access/hash/hash.c,v 1.32 1999/09/24 00:23:48 tgl Exp $
*
* NOTES
* This file contains only the public interface routines.
@@ -58,7 +58,6 @@ hashbuild(Relation heap,
nitups;
int i;
HashItem hitem;
- Buffer buffer = InvalidBuffer;
#ifndef OMIT_PARTIAL_INDEX
ExprContext *econtext;
@@ -101,7 +100,7 @@ hashbuild(Relation heap,
tupleTable = ExecCreateTupleTable(1);
slot = ExecAllocTableSlot(tupleTable);
econtext = makeNode(ExprContext);
- FillDummyExprContext(econtext, slot, htupdesc, buffer);
+ FillDummyExprContext(econtext, slot, htupdesc, InvalidBuffer);
}
else
/* quiet the compiler */
diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c
index 092a23cc0ec..4c054921949 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.54 1999/09/18 19:05:58 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.55 1999/09/24 00:23:54 tgl Exp $
*
*
* INTERFACE ROUTINES
@@ -160,7 +160,7 @@ unpinscan(HeapScanDesc scan)
ReleaseBuffer(scan->rs_pbuf);
/* ------------------------------------
- * Scan will pin buffer one for each non-NULL tuple pointer
+ * Scan will pin buffer once for each non-NULL tuple pointer
* (ptup, ctup, ntup), so they have to be unpinned multiple
* times.
* ------------------------------------
@@ -170,6 +170,10 @@ unpinscan(HeapScanDesc scan)
if (BufferIsValid(scan->rs_nbuf))
ReleaseBuffer(scan->rs_nbuf);
+
+ /* we don't bother to clear rs_pbuf etc --- caller must
+ * reinitialize them if scan descriptor is not being deleted.
+ */
}
/* ------------------------------------------
@@ -826,6 +830,8 @@ heap_getnext(HeapScanDesc scandesc, int backw)
{
if (BufferIsValid(scan->rs_nbuf))
ReleaseBuffer(scan->rs_nbuf);
+ scan->rs_ntup.t_data = NULL;
+ scan->rs_nbuf = UnknownBuffer;
return NULL;
}
@@ -906,6 +912,8 @@ heap_getnext(HeapScanDesc scandesc, int backw)
{
if (BufferIsValid(scan->rs_pbuf))
ReleaseBuffer(scan->rs_pbuf);
+ scan->rs_ptup.t_data = NULL;
+ scan->rs_pbuf = UnknownBuffer;
HEAPDEBUG_3; /* heap_getnext returns NULL at end */
return NULL;
}
@@ -1014,8 +1022,6 @@ heap_fetch(Relation relation,
ItemPointer tid = &(tuple->t_self);
OffsetNumber offnum;
- AssertMacro(PointerIsValid(userbuf)); /* see comments above */
-
/* ----------------
* increment access statistics
* ----------------
@@ -1067,21 +1073,17 @@ heap_fetch(Relation relation,
if (tuple->t_data == NULL)
{
+ /* Tuple failed time check, so we can release now. */
ReleaseBuffer(buffer);
- return;
+ *userbuf = InvalidBuffer;
+ }
+ else
+ {
+ /* All checks passed, so return the tuple as valid.
+ * Caller is now responsible for releasing the buffer.
+ */
+ *userbuf = buffer;
}
-
- /* ----------------
- * all checks passed, now either return a copy of the tuple
- * or pin the buffer page and return a pointer, depending on
- * whether caller gave us a valid buf.
- * ----------------
- */
-
- *userbuf = buffer; /* user is required to ReleaseBuffer()
- * this */
-
- return;
}
/* ----------------
diff --git a/src/backend/access/rtree/rtree.c b/src/backend/access/rtree/rtree.c
index 133bbdbc032..ee36b418893 100644
--- a/src/backend/access/rtree/rtree.c
+++ b/src/backend/access/rtree/rtree.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/access/rtree/Attic/rtree.c,v 1.37 1999/09/18 19:06:16 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/access/rtree/Attic/rtree.c,v 1.38 1999/09/24 00:23:59 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -135,7 +135,7 @@ rtbuild(Relation heap,
tupleTable = ExecCreateTupleTable(1);
slot = ExecAllocTableSlot(tupleTable);
econtext = makeNode(ExprContext);
- FillDummyExprContext(econtext, slot, hd, buffer);
+ FillDummyExprContext(econtext, slot, hd, InvalidBuffer);
}
else
{
diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c
index 1c5dae27be2..b3bf5cd9737 100644
--- a/src/backend/access/transam/xact.c
+++ b/src/backend/access/transam/xact.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.52 1999/09/16 09:08:56 ishii Exp $
+ * $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.53 1999/09/24 00:24:05 tgl Exp $
*
* NOTES
* Transaction aborts can now occur two ways:
@@ -151,6 +151,7 @@
#include "commands/vacuum.h"
#include "libpq/be-fsstubs.h"
#include "storage/proc.h"
+#include "storage/sinval.h"
#include "utils/temprel.h"
#include "utils/inval.h"
#include "utils/portal.h"
@@ -749,8 +750,8 @@ RecordTransactionAbort()
static void
AtAbort_Cache()
{
- RegisterInvalid(false);
RelationCacheAbort();
+ RegisterInvalid(false);
}
/* --------------------------------
@@ -929,7 +930,7 @@ CommitTransaction()
/*
* Let others know about no transaction in progress by me.
* Note that this must be done _before_ releasing locks we hold
- * and SpinAcquire(ShmemIndexLock) is required: UPDATE with xid 0 is
+ * and SpinAcquire(SInvalLock) is required: UPDATE with xid 0 is
* blocked by xid 1' UPDATE, xid 1 is doing commit while xid 2
* gets snapshot - if xid 2' GetSnapshotData sees xid 1 as running
* then it must see xid 0 as running as well or it will see two
@@ -937,10 +938,11 @@ CommitTransaction()
*/
if (MyProc != (PROC *) NULL)
{
- SpinAcquire(ShmemIndexLock);
+ /* Lock SInvalLock because that's what GetSnapshotData uses. */
+ SpinAcquire(SInvalLock);
MyProc->xid = InvalidTransactionId;
MyProc->xmin = InvalidTransactionId;
- SpinRelease(ShmemIndexLock);
+ SpinRelease(SInvalLock);
}
RelationPurgeLocalRelation(true);