Skip to content

Commit 67f99d2

Browse files
committed
Fix oversight in async-commit patch: there were some places in heapam.c
that still thought they could set HEAP_XMAX_COMMITTED immediately after seeing the other transaction commit. Make them use the same logic as tqual.c does to determine if the hint bit can be set yet.
1 parent 6ccc262 commit 67f99d2

File tree

3 files changed

+197
-172
lines changed

3 files changed

+197
-172
lines changed

src/backend/access/heap/heapam.c

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.236 2007/06/09 18:49:54 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.237 2007/08/14 17:35:18 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -1509,6 +1509,34 @@ heap_get_latest_tid(Relation relation,
15091509
} /* end of loop */
15101510
}
15111511

1512+
1513+
/*
1514+
* UpdateXmaxHintBits - update tuple hint bits after xmax transaction ends
1515+
*
1516+
* This is called after we have waited for the XMAX transaction to terminate.
1517+
* If the transaction aborted, we guarantee the XMAX_INVALID hint bit will
1518+
* be set on exit. If the transaction committed, we set the XMAX_COMMITTED
1519+
* hint bit if possible --- but beware that that may not yet be possible,
1520+
* if the transaction committed asynchronously. Hence callers should look
1521+
* only at XMAX_INVALID.
1522+
*/
1523+
static void
1524+
UpdateXmaxHintBits(HeapTupleHeader tuple, Buffer buffer, TransactionId xid)
1525+
{
1526+
Assert(TransactionIdEquals(HeapTupleHeaderGetXmax(tuple), xid));
1527+
1528+
if (!(tuple->t_infomask & (HEAP_XMAX_COMMITTED | HEAP_XMAX_INVALID)))
1529+
{
1530+
if (TransactionIdDidCommit(xid))
1531+
HeapTupleSetHintBits(tuple, buffer, HEAP_XMAX_COMMITTED,
1532+
xid);
1533+
else
1534+
HeapTupleSetHintBits(tuple, buffer, HEAP_XMAX_INVALID,
1535+
InvalidTransactionId);
1536+
}
1537+
}
1538+
1539+
15121540
/*
15131541
* heap_insert - insert tuple into a heap
15141542
*
@@ -1840,16 +1868,8 @@ heap_delete(Relation relation, ItemPointer tid,
18401868
xwait))
18411869
goto l1;
18421870

1843-
/* Otherwise we can mark it committed or aborted */
1844-
if (!(tp.t_data->t_infomask & (HEAP_XMAX_COMMITTED |
1845-
HEAP_XMAX_INVALID)))
1846-
{
1847-
if (TransactionIdDidCommit(xwait))
1848-
tp.t_data->t_infomask |= HEAP_XMAX_COMMITTED;
1849-
else
1850-
tp.t_data->t_infomask |= HEAP_XMAX_INVALID;
1851-
SetBufferCommitInfoNeedsSave(buffer);
1852-
}
1871+
/* Otherwise check if it committed or aborted */
1872+
UpdateXmaxHintBits(tp.t_data, buffer, xwait);
18531873
}
18541874

18551875
/*
@@ -2164,16 +2184,8 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
21642184
xwait))
21652185
goto l2;
21662186

2167-
/* Otherwise we can mark it committed or aborted */
2168-
if (!(oldtup.t_data->t_infomask & (HEAP_XMAX_COMMITTED |
2169-
HEAP_XMAX_INVALID)))
2170-
{
2171-
if (TransactionIdDidCommit(xwait))
2172-
oldtup.t_data->t_infomask |= HEAP_XMAX_COMMITTED;
2173-
else
2174-
oldtup.t_data->t_infomask |= HEAP_XMAX_INVALID;
2175-
SetBufferCommitInfoNeedsSave(buffer);
2176-
}
2187+
/* Otherwise check if it committed or aborted */
2188+
UpdateXmaxHintBits(oldtup.t_data, buffer, xwait);
21772189
}
21782190

21792191
/*
@@ -2713,16 +2725,8 @@ heap_lock_tuple(Relation relation, HeapTuple tuple, Buffer *buffer,
27132725
xwait))
27142726
goto l3;
27152727

2716-
/* Otherwise we can mark it committed or aborted */
2717-
if (!(tuple->t_data->t_infomask & (HEAP_XMAX_COMMITTED |
2718-
HEAP_XMAX_INVALID)))
2719-
{
2720-
if (TransactionIdDidCommit(xwait))
2721-
tuple->t_data->t_infomask |= HEAP_XMAX_COMMITTED;
2722-
else
2723-
tuple->t_data->t_infomask |= HEAP_XMAX_INVALID;
2724-
SetBufferCommitInfoNeedsSave(*buffer);
2725-
}
2728+
/* Otherwise check if it committed or aborted */
2729+
UpdateXmaxHintBits(tuple->t_data, *buffer, xwait);
27262730
}
27272731

27282732
/*

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