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

Commit25a26a7

Browse files
committed
WAL
1 parent0b33ace commit25a26a7

File tree

5 files changed

+703
-40
lines changed

5 files changed

+703
-40
lines changed

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

Lines changed: 18 additions & 2 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.86 2000/10/04 00:04:41 vadim Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.87 2000/10/13 02:02:59 vadim Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -2016,6 +2016,22 @@ void heap_redo(XLogRecPtr lsn, XLogRecord *record)
20162016
elog(STOP,"heap_redo: unknown op code %u",info);
20172017
}
20182018

2019+
voidheap_undo(XLogRecPtrlsn,XLogRecord*record)
2020+
{
2021+
uint8info=record->xl_info& ~XLR_INFO_MASK;
2022+
2023+
if (info==XLOG_HEAP_INSERT)
2024+
heap_xlog_insert(false,lsn,record);
2025+
elseif (info==XLOG_HEAP_DELETE)
2026+
heap_xlog_delete(false,lsn,record);
2027+
elseif (info==XLOG_HEAP_UPDATE)
2028+
heap_xlog_update(false,lsn,record);
2029+
elseif (info==XLOG_HEAP_MOVE)
2030+
heap_xlog_move(false,lsn,record);
2031+
else
2032+
elog(STOP,"heap_undo: unknown op code %u",info);
2033+
}
2034+
20192035
voidheap_xlog_delete(boolredo,XLogRecPtrlsn,XLogRecord*record)
20202036
{
20212037
xl_heap_delete*xlrec= (xl_heap_delete*)XLogRecGetData(record);
@@ -2199,7 +2215,7 @@ void heap_xlog_insert(bool redo, XLogRecPtr lsn, XLogRecord *record)
21992215
else/* we can't delete tuple right now */
22002216
{
22012217
lp->lp_flags |=LP_DELETE;/* mark for deletion */
2202-
MarkBufferForCleanup(buffer,PageCleanup);
2218+
MarkBufferForCleanup(buffer,HeapPageCleanup);
22032219
}
22042220

22052221
}

‎src/backend/access/nbtree/nbtinsert.c

Lines changed: 74 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.64 2000/10/05 20:10:20 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.65 2000/10/13 02:03:00 vadim Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -61,6 +61,10 @@ static void _bt_pgaddtup(Relation rel, Page page,
6161
staticbool_bt_isequal(TupleDescitupdesc,Pagepage,OffsetNumberoffnum,
6262
intkeysz,ScanKeyscankey);
6363

64+
#ifdefXLOG
65+
staticRelation_xlheapRel;/* temporary hack */
66+
#endif
67+
6468
/*
6569
*_bt_doinsert() -- Handle insertion of a single btitem in the tree.
6670
*
@@ -119,6 +123,10 @@ _bt_doinsert(Relation rel, BTItem btitem,
119123
}
120124
}
121125

126+
#ifdefXLOG
127+
_xlheapRel=heapRel;/* temporary hack */
128+
#endif
129+
122130
/* do the insertion */
123131
res=_bt_insertonpg(rel,buf,stack,natts,itup_scankey,btitem,0);
124132

@@ -517,21 +525,38 @@ _bt_insertonpg(Relation rel,
517525
#ifdefXLOG
518526
/* XLOG stuff */
519527
{
520-
charxlbuf[sizeof(xl_btree_insert)+2*sizeof(CommandId)];
528+
charxlbuf[sizeof(xl_btree_insert)+
529+
sizeof(CommandId)+sizeof(RelFileNode)];
521530
xl_btree_insert*xlrec=xlbuf;
522531
inthsize=SizeOfBtreeInsert;
532+
BTItemDatatruncitem;
533+
BTItemxlitem=btitem;
534+
Sizexlsize=IndexTupleDSize(btitem->bti_itup)+
535+
(sizeof(BTItemData)-sizeof(IndexTupleData));
523536

524537
xlrec->target.node=rel->rd_node;
525538
ItemPointerSet(&(xlrec->target.tid),BufferGetBlockNumber(buf),newitemoff);
526539
if (P_ISLEAF(lpageop))
527-
{
540+
{
528541
CommandIdcid=GetCurrentCommandId();
529-
memcpy(xlbuf+SizeOfBtreeInsert,&(char*)cid,sizeof(CommandId));
542+
memcpy(xlbuf+hsize,&cid,sizeof(CommandId));
530543
hsize+=sizeof(CommandId);
544+
memcpy(xlbuf+hsize,&(_xlheapRel->rd_node),sizeof(RelFileNode));
545+
hsize+=sizeof(RelFileNode);
546+
}
547+
/*
548+
* Read comments in _bt_pgaddtup
549+
*/
550+
elseif (newitemoff==P_FIRSTDATAKEY(lpageop))
551+
{
552+
truncitem=*btitem;
553+
truncitem.bti_itup.t_info=sizeof(BTItemData);
554+
xlitem=&truncitem;
555+
xlsize=sizeof(BTItemData);
531556
}
532557

533558
XLogRecPtrrecptr=XLogInsert(RM_BTREE_ID,XLOG_BTREE_INSERT,
534-
xlbuf,hsize, (char*)btitem,itemsz);
559+
xlbuf,hsize, (char*)xlitem,xlsize);
535560

536561
PageSetLSN(page,recptr);
537562
PageSetSUI(page,ThisStartUpID);
@@ -752,7 +777,7 @@ _bt_split(Relation rel, Buffer buf, OffsetNumber firstright,
752777
*/
753778
{
754779
charxlbuf[sizeof(xl_btree_split)+
755-
2*sizeof(CommandId)+BLCKSZ];
780+
sizeof(CommandId)+sizeof(RelFileNode)+BLCKSZ];
756781
xl_btree_split*xlrec=xlbuf;
757782
inthsize=SizeOfBtreeSplit;
758783
intflag= (newitemonleft) ?
@@ -765,11 +790,30 @@ _bt_split(Relation rel, Buffer buf, OffsetNumber firstright,
765790
CommandIdcid=GetCurrentCommandId();
766791
memcpy(xlbuf+hsize,&(char*)cid,sizeof(CommandId));
767792
hsize+=sizeof(CommandId);
793+
memcpy(xlbuf+hsize,&(_xlheapRel->rd_node),sizeof(RelFileNode));
794+
hsize+=sizeof(RelFileNode);
768795
}
769796
if (newitemonleft)
770797
{
771-
memcpy(xlbuf+hsize, (char*)newitem,newitemsz);
772-
hsize+=newitemsz;
798+
/*
799+
* Read comments in _bt_pgaddtup.
800+
* Actually, seems that in non-leaf splits newitem shouldn't
801+
* go to first data key position.
802+
*/
803+
if (!P_ISLEAF(lopaque)&&itup_off==P_FIRSTDATAKEY(lopaque))
804+
{
805+
BTItemDatatruncitem=*newitem;
806+
truncitem.bti_itup.t_info=sizeof(BTItemData);
807+
memcpy(xlbuf+hsize,&truncitem,sizeof(BTItemData));
808+
hsize+=sizeof(BTItemData);
809+
}
810+
else
811+
{
812+
Sizeitemsz=IndexTupleDSize(newitem->bti_itup)+
813+
(sizeof(BTItemData)-sizeof(IndexTupleData));
814+
memcpy(xlbuf+hsize, (char*)newitem,itemsz);
815+
hsize+=itemsz;
816+
}
773817
xlrec->otherblk=BufferGetBlockNumber(rbuf);
774818
}
775819
else
@@ -1012,7 +1056,7 @@ static Buffer
10121056
_bt_getstackbuf(Relationrel,BTStackstack)
10131057
{
10141058
BlockNumberblkno;
1015-
Bufferbuf;
1059+
Bufferbuf,newbuf;
10161060
OffsetNumberstart,
10171061
offnum,
10181062
maxoff;
@@ -1101,11 +1145,18 @@ _bt_newroot(Relation rel, Buffer lbuf, Buffer rbuf)
11011145
Sizeitemsz;
11021146
BTItemnew_item;
11031147

1148+
#ifdefXLOG
1149+
Buffermetabuf;
1150+
#endif
1151+
11041152
/* get a new root page */
11051153
rootbuf=_bt_getbuf(rel,P_NEW,BT_WRITE);
11061154
rootpage=BufferGetPage(rootbuf);
11071155
rootblknum=BufferGetBlockNumber(rootbuf);
11081156

1157+
#ifdefXLOG
1158+
metabuf=_bt_getbuf(rel,BTREE_METAPAGE,BT_WRITE);
1159+
#endif
11091160

11101161
/* NO ELOG(ERROR) from here till newroot op is logged */
11111162

@@ -1168,9 +1219,12 @@ _bt_newroot(Relation rel, Buffer lbuf, Buffer rbuf)
11681219
#ifdefXLOG
11691220
/* XLOG stuff */
11701221
{
1171-
xl_btree_newrootxlrec;
1222+
xl_btree_newrootxlrec;
1223+
Pagemetapg=BufferGetPage(metabuf);
1224+
BTMetaPageData*metad=BTPageGetMeta(metapg);
1225+
11721226
xlrec.node=rel->rd_node;
1173-
xlrec.rootblk=rootblknum;
1227+
BlockIdSet(&(xlrec.rootblk),rootblknum);
11741228

11751229
/*
11761230
* Dirrect access to page is not good but faster - we should
@@ -1181,16 +1235,25 @@ _bt_newroot(Relation rel, Buffer lbuf, Buffer rbuf)
11811235
(char*)rootpage+ (PageHeader)rootpage)->pd_upper,
11821236
((PageHeader)rootpage)->pd_special- ((PageHeader)rootpage)->upper);
11831237

1238+
metad->btm_root=rootblknum;
1239+
(metad->btm_level)++;
1240+
11841241
PageSetLSN(rootpage,recptr);
11851242
PageSetSUI(rootpage,ThisStartUpID);
1243+
PageSetLSN(metapg,recptr);
1244+
PageSetSUI(metapg,ThisStartUpID);
1245+
1246+
_bt_wrtbuf(rel,metabuf);
11861247
}
11871248
#endif
11881249

11891250
/* write and let go of the new root buffer */
11901251
_bt_wrtbuf(rel,rootbuf);
11911252

1253+
#ifndefXLOG
11921254
/* update metadata page with new root block number */
11931255
_bt_metaproot(rel,rootblknum,0);
1256+
#endif
11941257

11951258
/* update and release new sibling, and finally the old root */
11961259
_bt_wrtbuf(rel,rbuf);

‎src/backend/access/nbtree/nbtpage.c

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtpage.c,v 1.38 2000/10/04 00:04:42 vadim Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtpage.c,v 1.39 2000/10/13 02:03:00 vadim Exp $
1313
*
1414
*NOTES
1515
* Postgres btree pages look like ordinary relation pages.The opaque
@@ -27,23 +27,6 @@
2727
#include"access/nbtree.h"
2828
#include"miscadmin.h"
2929

30-
#defineBTREE_METAPAGE0
31-
#defineBTREE_MAGIC0x053162
32-
33-
#defineBTREE_VERSION1
34-
35-
typedefstructBTMetaPageData
36-
{
37-
uint32btm_magic;
38-
uint32btm_version;
39-
BlockNumberbtm_root;
40-
int32btm_level;
41-
}BTMetaPageData;
42-
43-
#defineBTPageGetMeta(p) \
44-
((BTMetaPageData *) &((PageHeader) p)->pd_linp[0])
45-
46-
4730
/*
4831
*We use high-concurrency locking on btrees.There are two cases in
4932
*which we don't do locking. One is when we're building the btree.
@@ -188,14 +171,18 @@ _bt_getroot(Relation rel, int access)
188171
#ifdefXLOG
189172
/* XLOG stuff */
190173
{
191-
xl_btree_insertxlrec;
174+
xl_btree_newrootxlrec;
175+
192176
xlrec.node=rel->rd_node;
177+
BlockIdSet(&(xlrec.rootblk),rootblkno);
193178

194179
XLogRecPtrrecptr=XLogInsert(RM_BTREE_ID,XLOG_BTREE_NEWROOT,
195180
&xlrec,SizeOfBtreeNewroot,NULL,0);
196181

197182
PageSetLSN(rootpage,recptr);
198183
PageSetSUI(rootpage,ThisStartUpID);
184+
PageSetLSN(metapg,recptr);
185+
PageSetSUI(metapg,ThisStartUpID);
199186
}
200187
#endif
201188

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp