Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc87469e

Browse files
committed
Fix problems with loss of tuple commit status bits during WAL redo of
VACUUM FULL tuple moves. Store full-width t_infomask in WAL, ratherthan storing low 8 bits and expecting to be able to reconstruct upperbits. While at it, remove redundant t_oid field from WAL headers(the OID, if present, is now recorded in the data portion of the tuple).WAL version number bumped --- this does not force an initdb, you caninstead run pg_resetxlog after a clean shutdown of the old postmaster.
1 parent72f8efd commitc87469e

File tree

3 files changed

+41
-28
lines changed

3 files changed

+41
-28
lines changed

‎src/backend/access/heap/heapam.c

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.148 2002/09/04 20:31:09 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.149 2002/09/26 22:46:29 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -1185,10 +1185,14 @@ heap_insert(Relation relation, HeapTuple tup, CommandId cid)
11851185
rdata[0].len=SizeOfHeapInsert;
11861186
rdata[0].next=&(rdata[1]);
11871187

1188-
xlhdr.t_oid=HeapTupleGetOid(tup);
11891188
xlhdr.t_natts=tup->t_data->t_natts;
1189+
xlhdr.t_infomask=tup->t_data->t_infomask;
11901190
xlhdr.t_hoff=tup->t_data->t_hoff;
1191-
xlhdr.mask=tup->t_data->t_infomask;
1191+
/*
1192+
* note we mark rdata[1] as belonging to buffer; if XLogInsert
1193+
* decides to write the whole page to the xlog, we don't need to
1194+
* store xl_heap_header in the xlog.
1195+
*/
11921196
rdata[1].buffer=buffer;
11931197
rdata[1].data= (char*)&xlhdr;
11941198
rdata[1].len=SizeOfHeapHeader;
@@ -1200,7 +1204,11 @@ heap_insert(Relation relation, HeapTuple tup, CommandId cid)
12001204
rdata[2].len=tup->t_len- offsetof(HeapTupleHeaderData,t_bits);
12011205
rdata[2].next=NULL;
12021206

1203-
/* If this is the single and first tuple on page... */
1207+
/*
1208+
* If this is the single and first tuple on page, we can reinit the
1209+
* page instead of restoring the whole thing. Set flag, and hide
1210+
* buffer references from XLogInsert.
1211+
*/
12041212
if (ItemPointerGetOffsetNumber(&(tup->t_self))==FirstOffsetNumber&&
12051213
PageGetMaxOffsetNumber(page)==FirstOffsetNumber)
12061214
{
@@ -2041,11 +2049,10 @@ log_heap_update(Relation reln, Buffer oldbuf, ItemPointerData from,
20412049
rdata[1].len=0;
20422050
rdata[1].next=&(rdata[2]);
20432051

2044-
xlhdr.hdr.t_oid=HeapTupleGetOid(newtup);
20452052
xlhdr.hdr.t_natts=newtup->t_data->t_natts;
2053+
xlhdr.hdr.t_infomask=newtup->t_data->t_infomask;
20462054
xlhdr.hdr.t_hoff=newtup->t_data->t_hoff;
2047-
xlhdr.hdr.mask=newtup->t_data->t_infomask;
2048-
if (move)/* remember xmin & xmax */
2055+
if (move)/* remember xmax & xmin */
20492056
{
20502057
TransactionIdxid[2];/* xmax, xmin */
20512058

@@ -2060,6 +2067,10 @@ log_heap_update(Relation reln, Buffer oldbuf, ItemPointerData from,
20602067
2*sizeof(TransactionId));
20612068
hsize+=2*sizeof(TransactionId);
20622069
}
2070+
/*
2071+
* As with insert records, we need not store the rdata[2] segment
2072+
* if we decide to store the whole buffer instead.
2073+
*/
20632074
rdata[2].buffer=newbuf;
20642075
rdata[2].data= (char*)&xlhdr;
20652076
rdata[2].len=hsize;
@@ -2276,18 +2287,16 @@ heap_xlog_insert(bool redo, XLogRecPtr lsn, XLogRecord *record)
22762287
htup=&tbuf.hdr;
22772288
MemSet((char*)htup,0,sizeof(HeapTupleHeaderData));
22782289
/* PG73FORMAT: get bitmap [+ padding] [+ oid] + data */
2279-
memcpy((char*)&tbuf+ offsetof(HeapTupleHeaderData,t_bits),
2290+
memcpy((char*)htup+ offsetof(HeapTupleHeaderData,t_bits),
22802291
(char*)xlrec+SizeOfHeapInsert+SizeOfHeapHeader,
22812292
newlen);
22822293
newlen+= offsetof(HeapTupleHeaderData,t_bits);
22832294
htup->t_natts=xlhdr.t_natts;
2295+
htup->t_infomask=xlhdr.t_infomask;
22842296
htup->t_hoff=xlhdr.t_hoff;
2285-
htup->t_infomask=HEAP_XMAX_INVALID |xlhdr.mask;
22862297
HeapTupleHeaderSetXmin(htup,record->xl_xid);
22872298
HeapTupleHeaderSetCmin(htup,FirstCommandId);
22882299
htup->t_ctid=xlrec->target.tid;
2289-
if (reln->rd_rel->relhasoids)
2290-
HeapTupleHeaderSetOid(htup,xlhdr.t_oid);
22912300

22922301
offnum=PageAddItem(page, (Item)htup,newlen,offnum,
22932302
LP_USED |OverwritePageMode);
@@ -2454,34 +2463,27 @@ newsame:;
24542463
htup=&tbuf.hdr;
24552464
MemSet((char*)htup,0,sizeof(HeapTupleHeaderData));
24562465
/* PG73FORMAT: get bitmap [+ padding] [+ oid] + data */
2457-
memcpy((char*)&tbuf+ offsetof(HeapTupleHeaderData,t_bits),
2466+
memcpy((char*)htup+ offsetof(HeapTupleHeaderData,t_bits),
24582467
(char*)xlrec+hsize,
24592468
newlen);
24602469
newlen+= offsetof(HeapTupleHeaderData,t_bits);
24612470
htup->t_natts=xlhdr.t_natts;
2471+
htup->t_infomask=xlhdr.t_infomask;
24622472
htup->t_hoff=xlhdr.t_hoff;
2463-
if (reln->rd_rel->relhasoids)
2464-
HeapTupleHeaderSetOid(htup,xlhdr.t_oid);
24652473

24662474
if (move)
24672475
{
24682476
TransactionIdxid[2];/* xmax, xmin */
24692477

2470-
hsize=SizeOfHeapUpdate+SizeOfHeapHeader;
24712478
memcpy((char*)xid,
2472-
(char*)xlrec+hsize,2*sizeof(TransactionId));
2473-
htup->t_infomask=xlhdr.mask;
2474-
htup->t_infomask &= ~(HEAP_XMIN_COMMITTED |
2475-
HEAP_XMIN_INVALID |
2476-
HEAP_MOVED_OFF);
2477-
htup->t_infomask |=HEAP_MOVED_IN;
2479+
(char*)xlrec+SizeOfHeapUpdate+SizeOfHeapHeader,
2480+
2*sizeof(TransactionId));
24782481
HeapTupleHeaderSetXmin(htup,xid[1]);
24792482
HeapTupleHeaderSetXmax(htup,xid[0]);
24802483
HeapTupleHeaderSetXvac(htup,record->xl_xid);
24812484
}
24822485
else
24832486
{
2484-
htup->t_infomask=HEAP_XMAX_INVALID |xlhdr.mask;
24852487
HeapTupleHeaderSetXmin(htup,record->xl_xid);
24862488
HeapTupleHeaderSetCmin(htup,FirstCommandId);
24872489
}

‎src/include/access/htup.h

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: htup.h,v 1.60 2002/09/04 20:31:37 momjian Exp $
10+
* $Id: htup.h,v 1.61 2002/09/26 22:46:29 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -261,6 +261,8 @@ do { \
261261

262262

263263
/*
264+
* WAL record definitions for heapam.c's WAL operations
265+
*
264266
* XLOG allows to store some information in high 4 bits of log
265267
* record xl_info field
266268
*/
@@ -300,15 +302,22 @@ typedef struct xl_heap_delete
300302

301303
#defineSizeOfHeapDelete(offsetof(xl_heap_delete, target) + SizeOfHeapTid)
302304

305+
/*
306+
* We don't store the whole fixed part (HeapTupleHeaderData) of an inserted
307+
* or updated tuple in WAL; we can save a few bytes by reconstructing the
308+
* fields that are available elsewhere in the WAL record, or perhaps just
309+
* plain needn't be reconstructed. These are the fields we must store.
310+
* NOTE: t_hoff could be recomputed, but we may as well store it because
311+
* it will come for free due to alignment considerations.
312+
*/
303313
typedefstructxl_heap_header
304314
{
305-
Oidt_oid;
306315
int16t_natts;
316+
uint16t_infomask;
307317
uint8t_hoff;
308-
uint8mask;/* low 8 bits of t_infomask */
309318
}xl_heap_header;
310319

311-
#defineSizeOfHeapHeader(offsetof(xl_heap_header,mask) + sizeof(uint8))
320+
#defineSizeOfHeapHeader(offsetof(xl_heap_header,t_hoff) + sizeof(uint8))
312321

313322
/* This is what we need to know about insert */
314323
typedefstructxl_heap_insert
@@ -340,6 +349,8 @@ typedef struct xl_heap_clean
340349

341350
#defineSizeOfHeapClean (offsetof(xl_heap_clean, block) + sizeof(BlockNumber))
342351

352+
353+
343354
/*
344355
* MaxTupleSize is the maximum allowed size of a tuple, including header and
345356
* MAXALIGN alignment padding.Basically it's BLCKSZ minus the other stuff

‎src/include/access/xlog.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: xlog.h,v 1.37 2002/09/04 20:31:37 momjian Exp $
9+
* $Id: xlog.h,v 1.38 2002/09/26 22:46:29 tgl Exp $
1010
*/
1111
#ifndefXLOG_H
1212
#defineXLOG_H
@@ -110,7 +110,7 @@ typedef struct XLogContRecord
110110
/*
111111
* Each page of XLOG file has a header like this:
112112
*/
113-
#defineXLOG_PAGE_MAGIC0xD059/* can be used as WAL version indicator */
113+
#defineXLOG_PAGE_MAGIC0xD05A/* can be used as WAL version indicator */
114114

115115
typedefstructXLogPageHeaderData
116116
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp