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

Commitbf1c8f2

Browse files
committed
heap' xlog records
1 parent664dd61 commitbf1c8f2

File tree

5 files changed

+150
-24
lines changed

5 files changed

+150
-24
lines changed

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

Lines changed: 36 additions & 1 deletion
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.69 2000/05/30 00:49:39 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.70 2000/06/02 10:20:24 vadim Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -1246,6 +1246,27 @@ heap_insert(Relation relation, HeapTuple tup)
12461246

12471247
RelationPutHeapTupleAtEnd(relation,tup);
12481248

1249+
#ifdefXLOG
1250+
/* XLOG stuff */
1251+
{
1252+
xl_heap_insertxlrec;
1253+
xlrec.itid.dbId=relation->rd_lockInfo.lockRelId.dbId;
1254+
xlrec.itid.relId=relation->rd_lockInfo.lockRelId.relId;
1255+
XXXxlrec.itid.tid=tp.t_self;
1256+
xlrec.t_natts=tup->t_data->t_natts;
1257+
xlrec.t_oid=tup->t_data->t_oid;
1258+
xlrec.t_hoff=tup->t_data->t_hoff;
1259+
xlrec.mask=tup->t_data->t_infomask;
1260+
1261+
XLogRecPtrrecptr=XLogInsert(RM_HEAP_ID,XLOG_HEAP_INSERT,
1262+
(char*)xlrec,sizeof(xlrec),
1263+
(char*)tup->t_data+ offsetof(HeapTupleHeaderData,tbits),
1264+
tup->t_len- offsetof(HeapTupleHeaderData,tbits));
1265+
1266+
dp->pd_lsn=recptr;
1267+
}
1268+
#endif
1269+
12491270
if (IsSystemRelationName(RelationGetRelationName(relation)))
12501271
RelationMark4RollbackHeapTuple(relation,tup);
12511272

@@ -1333,6 +1354,20 @@ heap_delete(Relation relation, ItemPointer tid, ItemPointer ctid)
13331354
returnresult;
13341355
}
13351356

1357+
#ifdefXLOG
1358+
/* XLOG stuff */
1359+
{
1360+
xl_heap_deletexlrec;
1361+
xlrec.dtid.dbId=relation->rd_lockInfo.lockRelId.dbId;
1362+
xlrec.dtid.relId=relation->rd_lockInfo.lockRelId.relId;
1363+
xlrec.dtid.tid=tp.t_self;
1364+
XLogRecPtrrecptr=XLogInsert(RM_HEAP_ID,XLOG_HEAP_DELETE,
1365+
(char*)xlrec,sizeof(xlrec),NULL,0);
1366+
1367+
dp->pd_lsn=recptr;
1368+
}
1369+
#endif
1370+
13361371
/* store transaction information of xact deleting the tuple */
13371372
TransactionIdStore(GetCurrentTransactionId(),&(tp.t_data->t_xmax));
13381373
tp.t_data->t_cmax=GetCurrentCommandId();

‎src/backend/access/transam/xlog.c

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.14 2000/06/0203:58:34 tgl Exp $
9+
* $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.15 2000/06/0210:20:25 vadim Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -219,7 +219,7 @@ static char readBuf[BLCKSZ];
219219
staticXLogRecord*nextRecord=NULL;
220220

221221
XLogRecPtr
222-
XLogInsert(RmgrIdrmid,char*hdr,uint32hdrlen,char*buf,uint32buflen)
222+
XLogInsert(RmgrIdrmid,uint8info,char*hdr,uint32hdrlen,char*buf,uint32buflen)
223223
{
224224
XLogCtlInsert*Insert=&XLogCtl->Insert;
225225
XLogRecord*record;
@@ -231,6 +231,7 @@ XLogInsert(RmgrId rmid, char *hdr, uint32 hdrlen, char *buf, uint32 buflen)
231231
uint16curridx;
232232
boolupdrqst= false;
233233

234+
Assert(!(info&XLR_INFO_MASK));
234235
if (len==0||len>MAXLOGRECSZ)
235236
elog(STOP,"XLogInsert: invalid record len %u",len);
236237

@@ -306,7 +307,8 @@ XLogInsert(RmgrId rmid, char *hdr, uint32 hdrlen, char *buf, uint32 buflen)
306307
}
307308
record->xl_xid=GetCurrentTransactionId();
308309
record->xl_len= (len>freespace) ?freespace :len;
309-
record->xl_info= (len>freespace) ?XLR_TO_BE_CONTINUED :0;
310+
record->xl_info= (len>freespace) ?
311+
(info |XLR_TO_BE_CONTINUED) :info;
310312
record->xl_rmid=rmid;
311313
RecPtr.xlogid=XLogCtl->xlblocks[curridx].xlogid;
312314
RecPtr.xrecoff=
@@ -318,8 +320,7 @@ XLogInsert(RmgrId rmid, char *hdr, uint32 hdrlen, char *buf, uint32 buflen)
318320
MyProc->logRec=RecPtr;
319321
SpinRelease(SInvalLock);
320322
}
321-
MyLastRecPtr=RecPtr;
322-
RecPtr.xrecoff+=record->xl_len;
323+
MyLastRecPtr=RecPtr;/* begin of record */
323324
Insert->currpos+=SizeOfXLogRecord;
324325
if (freespace>0)
325326
{
@@ -364,6 +365,7 @@ XLogInsert(RmgrId rmid, char *hdr, uint32 hdrlen, char *buf, uint32 buflen)
364365
if (hdrlen>freespace)
365366
{
366367
subrecord->xl_len=freespace;
368+
/* we don't store info in subrecord' xl_info */
367369
subrecord->xl_info=XLR_TO_BE_CONTINUED;
368370
memcpy(Insert->currpos,hdr,freespace);
369371
hdrlen-=freespace;
@@ -383,6 +385,7 @@ XLogInsert(RmgrId rmid, char *hdr, uint32 hdrlen, char *buf, uint32 buflen)
383385
if (buflen>freespace)
384386
{
385387
subrecord->xl_len+=freespace;
388+
/* we don't store info in subrecord' xl_info */
386389
subrecord->xl_info=XLR_TO_BE_CONTINUED;
387390
memcpy(Insert->currpos,buf,freespace);
388391
buflen-=freespace;
@@ -395,15 +398,22 @@ XLogInsert(RmgrId rmid, char *hdr, uint32 hdrlen, char *buf, uint32 buflen)
395398
memcpy(Insert->currpos,buf,buflen);
396399
Insert->currpos+=buflen;
397400
}
401+
/* we don't store info in subrecord' xl_info */
398402
subrecord->xl_info=0;
399-
RecPtr.xlogid=XLogCtl->xlblocks[curridx].xlogid;
400-
RecPtr.xrecoff=XLogCtl->xlblocks[curridx].xrecoff-
401-
BLCKSZ+SizeOfXLogPHD+subrecord->xl_len;
402403
Insert->currpos= ((char*)Insert->currpage)+
403404
DOUBLEALIGN(Insert->currpos- ((char*)Insert->currpage));
404405
}
405406
freespace= ((char*)Insert->currpage)+BLCKSZ-Insert->currpos;
406407

408+
/*
409+
* Begin of the next record will be stored as LSN for
410+
* changed data page...
411+
*/
412+
RecPtr.xlogid=XLogCtl->xlblocks[curridx].xlogid;
413+
RecPtr.xrecoff=
414+
XLogCtl->xlblocks[curridx].xrecoff-BLCKSZ+
415+
Insert->currpos- ((char*)Insert->currpage);
416+
407417
/*
408418
* All done! Update global LgwrRqst if some block was filled up.
409419
*/
@@ -884,7 +894,8 @@ got_record:;
884894
XLogSubRecord*subrecord;
885895
uint32len=record->xl_len;
886896

887-
if (record->xl_len+RecPtr->xrecoff %BLCKSZ+SizeOfXLogRecord!=BLCKSZ)
897+
if (DOUBLEALIGN(record->xl_len)+RecPtr->xrecoff %BLCKSZ+
898+
SizeOfXLogRecord!=BLCKSZ)
888899
{
889900
elog(emode,"ReadRecord: invalid fragmented record len %u in (%u, %u)",
890901
record->xl_len,RecPtr->xlogid,RecPtr->xrecoff);
@@ -945,7 +956,7 @@ got_record:;
945956
buffer+=subrecord->xl_len;
946957
if (subrecord->xl_info&XLR_TO_BE_CONTINUED)
947958
{
948-
if (subrecord->xl_len+
959+
if (DOUBLEALIGN(subrecord->xl_len)+
949960
SizeOfXLogPHD+SizeOfXLogSubRecord!=BLCKSZ)
950961
{
951962
elog(emode,"ReadRecord: invalid fragmented subrecord len %u in logfile %u seg %u off %u",
@@ -956,23 +967,26 @@ got_record:;
956967
}
957968
break;
958969
}
959-
if (BLCKSZ-SizeOfXLogRecord >=
960-
subrecord->xl_len+SizeOfXLogPHD+SizeOfXLogSubRecord)
970+
if (BLCKSZ-SizeOfXLogRecord >=DOUBLEALIGN(subrecord->xl_len)+
971+
SizeOfXLogPHD+SizeOfXLogSubRecord)
961972
{
962-
nextRecord= (XLogRecord*)
963-
((char*)subrecord+subrecord->xl_len+SizeOfXLogSubRecord);
973+
nextRecord= (XLogRecord*) ((char*)subrecord+
974+
DOUBLEALIGN(subrecord->xl_len)+SizeOfXLogSubRecord);
964975
}
965976
EndRecPtr.xlogid=readId;
966977
EndRecPtr.xrecoff=readSeg*XLogSegSize+readOff*BLCKSZ+
967-
SizeOfXLogPHD+SizeOfXLogSubRecord+subrecord->xl_len;
978+
SizeOfXLogPHD+SizeOfXLogSubRecord+
979+
DOUBLEALIGN(subrecord->xl_len);
968980
ReadRecPtr=*RecPtr;
969981
return (record);
970982
}
971-
if (BLCKSZ-SizeOfXLogRecord >=
972-
record->xl_len+RecPtr->xrecoff %BLCKSZ+SizeOfXLogRecord)
973-
nextRecord= (XLogRecord*) ((char*)record+record->xl_len+SizeOfXLogRecord);
983+
if (BLCKSZ-SizeOfXLogRecord >=DOUBLEALIGN(record->xl_len)+
984+
RecPtr->xrecoff %BLCKSZ+SizeOfXLogRecord)
985+
nextRecord= (XLogRecord*) ((char*)record+
986+
DOUBLEALIGN(record->xl_len)+SizeOfXLogRecord);
974987
EndRecPtr.xlogid=RecPtr->xlogid;
975-
EndRecPtr.xrecoff=RecPtr->xrecoff+record->xl_len+SizeOfXLogRecord;
988+
EndRecPtr.xrecoff=RecPtr->xrecoff+
989+
DOUBLEALIGN(record->xl_len)+SizeOfXLogRecord;
976990
ReadRecPtr=*RecPtr;
977991

978992
return (record);

‎src/include/access/htup.h

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: htup.h,v 1.29 2000/04/12 17:16:26momjian Exp $
10+
* $Id: htup.h,v 1.30 2000/06/02 10:20:26vadim Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -44,6 +44,8 @@ typedef struct HeapTupleHeaderData
4444

4545
uint8t_hoff;/* sizeof tuple header */
4646

47+
/* ^ - 31 bytes - ^ */
48+
4749
bits8t_bits[MinHeapTupleBitmapSize /8];
4850
/* bit map of domains */
4951

@@ -52,6 +54,71 @@ typedef struct HeapTupleHeaderData
5254

5355
typedefHeapTupleHeaderData*HeapTupleHeader;
5456

57+
58+
#ifdefXLOG
59+
60+
/* XLOG stuff */
61+
62+
/*
63+
* XLOG allows to store some information in high 4 bits of log
64+
* record xl_info field
65+
*/
66+
#defineXLOG_HEAP_INSERT0x00
67+
#defineXLOG_HEAP_DELETE0x10
68+
#defineXLOG_HEAP_UPDATE0x20
69+
#defineXLOG_HEAP_MOVE0x30
70+
71+
/*
72+
* All what we need to find changed tuple (14 bytes)
73+
*/
74+
typedefstructxl_heaptid
75+
{
76+
OiddbId;/* database */
77+
OidrelId;/* relation */
78+
ItemPointerDatatid;/* changed tuple id */
79+
}xl_heaptid;
80+
81+
/* This is what we need to know about delete - ALIGN(14) = 16 bytes */
82+
typedefstructxl_heap_delete
83+
{
84+
xl_heaptiddtid;/* deleted tuple id */
85+
}xl_heap_delete;
86+
87+
/* This is what we need to know about insert - 22 + data */
88+
typedefstructxl_heap_insert
89+
{
90+
xl_heaptiditid;/* inserted tuple id */
91+
/* something from tuple header */
92+
int16t_natts;
93+
Oidt_oid;
94+
uint8t_hoff;
95+
uint8mask;/* low 8 bits of t_infomask */
96+
/* TUPLE DATA FOLLOWS AT END OF STRUCT */
97+
}xl_heap_insert;
98+
99+
/* This is what we need to know about update - 28 + data */
100+
typedefstructxl_heap_update
101+
{
102+
xl_heaptiddtid;/* deleted tuple id */
103+
ItemPointerDataitid;/* new inserted tuple id */
104+
/* something from header of new tuple version */
105+
int16t_natts;
106+
uint8t_hoff;
107+
uint8mask;/* low 8 bits of t_infomask */
108+
/* NEW TUPLE DATA FOLLOWS AT END OF STRUCT */
109+
}xl_heap_update;
110+
111+
/* This is what we need to know about tuple move - ALIGN(20) = 24 bytes */
112+
typedefstructxl_heap_move
113+
{
114+
xl_heaptidftid;/* moved from */
115+
ItemPointerDatattid;/* moved to */
116+
}xl_heap_move;
117+
118+
/* end of XLOG stuff */
119+
120+
#endif/* XLOG */
121+
55122
#defineMinTupleSize(MAXALIGN(sizeof (PageHeaderData)) + \
56123
MAXALIGN(sizeof(HeapTupleHeaderData)) + \
57124
MAXALIGN(sizeof(char)))

‎src/include/access/xlog.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ typedef struct XLogSubRecord
4747

4848
#defineSizeOfXLogSubRecord DOUBLEALIGN(sizeof(XLogSubRecord))
4949

50+
/*
51+
* XLOG uses only low 4 bits of xl_info. High 4 bits may be used
52+
* by rmgr...
53+
*/
5054
#defineXLR_TO_BE_CONTINUED0x01
55+
#defineXLR_INFO_MASK0x0F
5156

5257
#defineXLOG_PAGE_MAGIC 0x17345168
5358

@@ -63,8 +68,9 @@ typedef XLogPageHeaderData *XLogPageHeader;
6368

6469
#defineXLP_FIRST_IS_SUBRECORD0x0001
6570

66-
externXLogRecPtrXLogInsert(RmgrIdrmid,char*hdr,uint32hdrlen,
67-
char*buf,uint32buflen);
71+
externXLogRecPtrXLogInsert(RmgrIdrmid,uint8info,
72+
char*hdr,uint32hdrlen,
73+
char*buf,uint32buflen);
6874
externvoidXLogFlush(XLogRecPtrRecPtr);
6975

7076
#endif/* XLOG_H */

‎src/include/storage/bufpage.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: bufpage.h,v 1.28 2000/01/26 05:58:32 momjian Exp $
10+
* $Id: bufpage.h,v 1.29 2000/06/02 10:20:27 vadim Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -117,6 +117,10 @@ typedef OpaqueData *Opaque;
117117
*/
118118
typedefstructPageHeaderData
119119
{
120+
#ifdefXLOG
121+
XLogRecPtrpd_lsn;/* XLOG: next byte after last byte of xlog */
122+
/* record for last change of this page */
123+
#endif
120124
LocationIndexpd_lower;/* offset to start of free space */
121125
LocationIndexpd_upper;/* offset to end of free space */
122126
LocationIndexpd_special;/* offset to start of special space */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp