Nested transactions - Mailing list pgsql-patches

From Alvaro Herrera
Subject Nested transactions
Date
Msg-id 20040508211014.GA10814@dcc.uchile.cl
Whole thread Raw
List pgsql-patches
Hackers,

I attach my current nested transactions patch, plus the subtrans code
(src/backend/access/transam/subtrans.c and
src/include/access/subtrans.h)

I got somewhat further with the visibility issues and I think it's
"mostly there".  I have successfully executed some concurrent tests with
inserting into a table repeatedly with a concurrent vacuum, but there's
one thing I'm stuck into.

The problem is that the heap tuple headers compress some info about
"Xmin is Xmax," and I'm not sure the visibility can be done right
without reverting this change.  The following example fails:

begin;
        insert into baz values (3);
        begin;
                delete from baz where a=3;
        rollback;
        delete from baz where a=3;
commit;

The failure happens because the first time the tuple is deleted, it gets
XMAX_IS_INVALID.  The second time, HeapTupleSatisfiesSnapshot executes
the following:

        else if (TransactionIdIsCurrentTransactionId(HeapTupleHeaderGetXmin(tuple)))
        {
            if (HeapTupleHeaderGetCmin(tuple) >= snapshot->curcid)
                return false;   /* inserted after scan started */


The problem is that the HeapTuple's Cmin has been overlapped with Xmax,
which in my tests was around 19000, and the snapshot's Cid is 4 or 5 so
the tests fails.  The return result is incorrect, and the transaction
finishes with the tuple being visible which is, of course, also incorrect.

So I don't see how to do this.  Maybe the XMIN_IS_XMAX trick can be
changed to use a test based on the transaction tree instead of
TransactionIdEquals, but I'm not sure if this is correct or what other
effects it may have.

I'm not sure I'm correctly stating the problem, and of course I'm not
sure it's the only problem left.

Manfred, Tom, any comments?

--
Alvaro Herrera (<alvherre[a]dcc.uchile.cl>)
Essentially, you're proposing Kevlar shoes as a solution for the problem
that you want to walk around carrying a loaded gun aimed at your foot.
(Tom Lane)
/*
 * subtrans.h
 *
 * PostgreSQL subtrans-log manager
 *
 * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
 * Portions Copyright (c) 1994, Regents of the University of California
 *
 * $PostgreSQL$
 */
#ifndef SUBTRANS_H
#define SUBTRANS_H

#include "access/xlog.h"

/* exported because lwlock.c needs it */
#define NUM_SUBTRANS_BUFFERS    8


extern void SubTransSetParent(TransactionId xid, TransactionId parent);
extern TransactionId SubTransGetParent(TransactionId xid);

extern int    SubTransShmemSize(void);
extern void SubTransShmemInit(void);
extern void BootStrapSubTrans(void);
extern void StartupSubTrans(void);
extern void ShutdownSubTrans(void);
extern void CheckPointSubTrans(void);
extern void ExtendSubTrans(TransactionId newestXact);
extern void TruncateSubTrans(TransactionId oldestXact);

/* XLOG stuff */
#define SUBTRANS_ZEROPAGE        0x00

extern void subtrans_redo(XLogRecPtr lsn, XLogRecord *record);
extern void subtrans_undo(XLogRecPtr lsn, XLogRecord *record);
extern void subtrans_desc(char *buf, uint8 xl_info, char *rec);

#endif   /* SUBTRANS_H */

Attachment

pgsql-patches by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: mingw configure failure detection
Next
From: Peter Eisentraut
Date:
Subject: Re: mingw configure failure detection