mirror of
https://github.com/postgres/postgres.git
synced 2025-08-28 18:48:04 +03:00
Initial MVCC code.
New code for locking buffer' context.
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.31 1998/11/27 19:51:40 vadim Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.32 1998/12/15 12:45:20 vadim Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <storage/bufpage.h>
|
||||
#include <access/nbtree.h>
|
||||
#include <access/heapam.h>
|
||||
#include <access/xact.h>
|
||||
#include <storage/bufmgr.h>
|
||||
#include <fmgr.h>
|
||||
|
||||
@@ -67,6 +68,8 @@ _bt_doinsert(Relation rel, BTItem btitem, bool index_is_unique, Relation heapRel
|
||||
|
||||
/* trade in our read lock for a write lock */
|
||||
_bt_relbuf(rel, buf, BT_READ);
|
||||
|
||||
l1:
|
||||
buf = _bt_getbuf(rel, blkno, BT_WRITE);
|
||||
|
||||
/*
|
||||
@@ -120,9 +123,25 @@ _bt_doinsert(Relation rel, BTItem btitem, bool index_is_unique, Relation heapRel
|
||||
{ /* they're equal */
|
||||
btitem = (BTItem) PageGetItem(page, PageGetItemId(page, offset));
|
||||
htup.t_self = btitem->bti_itup.t_tid;
|
||||
heap_fetch(heapRel, SnapshotSelf, &htup, &buffer);
|
||||
if (htup.t_data != NULL)
|
||||
{ /* it is a duplicate */
|
||||
heap_fetch(heapRel, SnapshotDirty, &htup, &buffer);
|
||||
if (htup.t_data != NULL) /* it is a duplicate */
|
||||
{
|
||||
TransactionId xwait =
|
||||
(TransactionIdIsValid(SnapshotDirty->xmin)) ?
|
||||
SnapshotDirty->xmin : SnapshotDirty->xmax;
|
||||
|
||||
/*
|
||||
* If this tuple is being updated by other transaction
|
||||
* then we have to wait for its commit/abort.
|
||||
*/
|
||||
if (TransactionIdIsValid(xwait))
|
||||
{
|
||||
if (nbuf != InvalidBuffer)
|
||||
_bt_relbuf(rel, nbuf, BT_READ);
|
||||
_bt_relbuf(rel, buf, BT_WRITE);
|
||||
XactLockTableWait(xwait);
|
||||
goto l1; /* continue from the begin */
|
||||
}
|
||||
elog(ERROR, "Cannot insert a duplicate key into a unique index");
|
||||
}
|
||||
/* htup null so no buffer to release */
|
||||
|
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtpage.c,v 1.16 1998/09/01 03:21:14 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtpage.c,v 1.17 1998/12/15 12:45:23 vadim Exp $
|
||||
*
|
||||
* NOTES
|
||||
* Postgres btree pages look like ordinary relation pages. The opaque
|
||||
@@ -93,7 +93,7 @@ _bt_metapinit(Relation rel)
|
||||
|
||||
/* can't be sharing this with anyone, now... */
|
||||
if (USELOCKING)
|
||||
RelationSetLockForWrite(rel);
|
||||
LockRelation(rel, AccessExclusiveLock);
|
||||
|
||||
if ((nblocks = RelationGetNumberOfBlocks(rel)) != 0)
|
||||
{
|
||||
@@ -120,7 +120,7 @@ _bt_metapinit(Relation rel)
|
||||
|
||||
/* all done */
|
||||
if (USELOCKING)
|
||||
RelationUnsetLockForWrite(rel);
|
||||
UnlockRelation(rel, AccessExclusiveLock);
|
||||
}
|
||||
|
||||
#ifdef NOT_USED
|
||||
@@ -571,32 +571,26 @@ _bt_getstackbuf(Relation rel, BTStack stack, int access)
|
||||
static void
|
||||
_bt_setpagelock(Relation rel, BlockNumber blkno, int access)
|
||||
{
|
||||
ItemPointerData iptr;
|
||||
|
||||
if (USELOCKING)
|
||||
{
|
||||
ItemPointerSet(&iptr, blkno, P_HIKEY);
|
||||
|
||||
if (access == BT_WRITE)
|
||||
RelationSetSingleWLockPage(rel, &iptr);
|
||||
LockPage(rel, blkno, ExclusiveLock);
|
||||
else
|
||||
RelationSetSingleRLockPage(rel, &iptr);
|
||||
LockPage(rel, blkno, ShareLock);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_bt_unsetpagelock(Relation rel, BlockNumber blkno, int access)
|
||||
{
|
||||
ItemPointerData iptr;
|
||||
|
||||
if (USELOCKING)
|
||||
{
|
||||
ItemPointerSet(&iptr, blkno, P_HIKEY);
|
||||
|
||||
if (access == BT_WRITE)
|
||||
RelationUnsetSingleWLockPage(rel, &iptr);
|
||||
UnlockPage(rel, blkno, ExclusiveLock);
|
||||
else
|
||||
RelationUnsetSingleRLockPage(rel, &iptr);
|
||||
UnlockPage(rel, blkno, ShareLock);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user