7
7
* Portions Copyright (c) 1994, Regents of the University of California
8
8
*
9
9
* IDENTIFICATION
10
- * $PostgreSQL: pgsql/src/backend/access/transam/twophase.c,v 1.47 2008/11/02 21:24:51 tgl Exp $
10
+ * $PostgreSQL: pgsql/src/backend/access/transam/twophase.c,v 1.48 2008/11/19 10:34:50 heikki Exp $
11
11
*
12
12
* NOTES
13
13
* Each global transaction is associated with a global transaction
48
48
#include "access/twophase.h"
49
49
#include "access/twophase_rmgr.h"
50
50
#include "access/xact.h"
51
+ #include "access/xlogutils.h"
51
52
#include "catalog/pg_type.h"
53
+ #include "catalog/storage.h"
52
54
#include "funcapi.h"
53
55
#include "miscadmin.h"
54
56
#include "pg_trace.h"
@@ -141,12 +143,12 @@ static void RecordTransactionCommitPrepared(TransactionId xid,
141
143
int nchildren ,
142
144
TransactionId * children ,
143
145
int nrels ,
144
- RelFileFork * rels );
146
+ RelFileNode * rels );
145
147
static void RecordTransactionAbortPrepared (TransactionId xid ,
146
148
int nchildren ,
147
149
TransactionId * children ,
148
150
int nrels ,
149
- RelFileFork * rels );
151
+ RelFileNode * rels );
150
152
static void ProcessRecords (char * bufptr , TransactionId xid ,
151
153
const TwoPhaseCallback callbacks []);
152
154
@@ -694,8 +696,8 @@ TwoPhaseGetDummyProc(TransactionId xid)
694
696
*
695
697
* 1. TwoPhaseFileHeader
696
698
* 2. TransactionId[] (subtransactions)
697
- * 3. RelFileFork [] (files to be deleted at commit)
698
- * 4. RelFileFork [] (files to be deleted at abort)
699
+ * 3. RelFileNode [] (files to be deleted at commit)
700
+ * 4. RelFileNode [] (files to be deleted at abort)
699
701
* 5. TwoPhaseRecordOnDisk
700
702
* 6. ...
701
703
* 7. TwoPhaseRecordOnDisk (end sentinel, rmid == TWOPHASE_RM_END_ID)
@@ -793,8 +795,8 @@ StartPrepare(GlobalTransaction gxact)
793
795
TransactionId xid = gxact -> proc .xid ;
794
796
TwoPhaseFileHeader hdr ;
795
797
TransactionId * children ;
796
- RelFileFork * commitrels ;
797
- RelFileFork * abortrels ;
798
+ RelFileNode * commitrels ;
799
+ RelFileNode * abortrels ;
798
800
799
801
/* Initialize linked list */
800
802
records .head = palloc0 (sizeof (XLogRecData ));
@@ -832,12 +834,12 @@ StartPrepare(GlobalTransaction gxact)
832
834
}
833
835
if (hdr .ncommitrels > 0 )
834
836
{
835
- save_state_data (commitrels , hdr .ncommitrels * sizeof (RelFileFork ));
837
+ save_state_data (commitrels , hdr .ncommitrels * sizeof (RelFileNode ));
836
838
pfree (commitrels );
837
839
}
838
840
if (hdr .nabortrels > 0 )
839
841
{
840
- save_state_data (abortrels , hdr .nabortrels * sizeof (RelFileFork ));
842
+ save_state_data (abortrels , hdr .nabortrels * sizeof (RelFileNode ));
841
843
pfree (abortrels );
842
844
}
843
845
}
@@ -1140,8 +1142,10 @@ FinishPreparedTransaction(const char *gid, bool isCommit)
1140
1142
TwoPhaseFileHeader * hdr ;
1141
1143
TransactionId latestXid ;
1142
1144
TransactionId * children ;
1143
- RelFileFork * commitrels ;
1144
- RelFileFork * abortrels ;
1145
+ RelFileNode * commitrels ;
1146
+ RelFileNode * abortrels ;
1147
+ RelFileNode * delrels ;
1148
+ int ndelrels ;
1145
1149
int i ;
1146
1150
1147
1151
/*
@@ -1169,10 +1173,10 @@ FinishPreparedTransaction(const char *gid, bool isCommit)
1169
1173
bufptr = buf + MAXALIGN (sizeof (TwoPhaseFileHeader ));
1170
1174
children = (TransactionId * ) bufptr ;
1171
1175
bufptr += MAXALIGN (hdr -> nsubxacts * sizeof (TransactionId ));
1172
- commitrels = (RelFileFork * ) bufptr ;
1173
- bufptr += MAXALIGN (hdr -> ncommitrels * sizeof (RelFileFork ));
1174
- abortrels = (RelFileFork * ) bufptr ;
1175
- bufptr += MAXALIGN (hdr -> nabortrels * sizeof (RelFileFork ));
1176
+ commitrels = (RelFileNode * ) bufptr ;
1177
+ bufptr += MAXALIGN (hdr -> ncommitrels * sizeof (RelFileNode ));
1178
+ abortrels = (RelFileNode * ) bufptr ;
1179
+ bufptr += MAXALIGN (hdr -> nabortrels * sizeof (RelFileNode ));
1176
1180
1177
1181
/* compute latestXid among all children */
1178
1182
latestXid = TransactionIdLatest (xid , hdr -> nsubxacts , children );
@@ -1214,21 +1218,28 @@ FinishPreparedTransaction(const char *gid, bool isCommit)
1214
1218
*/
1215
1219
if (isCommit )
1216
1220
{
1217
- for (i = 0 ; i < hdr -> ncommitrels ; i ++ )
1218
- {
1219
- SMgrRelation srel = smgropen (commitrels [i ].rnode );
1220
- smgrdounlink (srel , commitrels [i ].forknum , false, false);
1221
- smgrclose (srel );
1222
- }
1221
+ delrels = commitrels ;
1222
+ ndelrels = hdr -> ncommitrels ;
1223
1223
}
1224
1224
else
1225
1225
{
1226
- for (i = 0 ; i < hdr -> nabortrels ; i ++ )
1226
+ delrels = abortrels ;
1227
+ ndelrels = hdr -> nabortrels ;
1228
+ }
1229
+ for (i = 0 ; i < ndelrels ; i ++ )
1230
+ {
1231
+ SMgrRelation srel = smgropen (delrels [i ]);
1232
+ ForkNumber fork ;
1233
+
1234
+ for (fork = 0 ; fork <= MAX_FORKNUM ; fork ++ )
1227
1235
{
1228
- SMgrRelation srel = smgropen (abortrels [i ].rnode );
1229
- smgrdounlink (srel , abortrels [i ].forknum , false, false);
1230
- smgrclose (srel );
1236
+ if (smgrexists (srel , fork ))
1237
+ {
1238
+ XLogDropRelation (delrels [i ], fork );
1239
+ smgrdounlink (srel , fork , false, true);
1240
+ }
1231
1241
}
1242
+ smgrclose (srel );
1232
1243
}
1233
1244
1234
1245
/* And now do the callbacks */
@@ -1639,8 +1650,8 @@ RecoverPreparedTransactions(void)
1639
1650
bufptr = buf + MAXALIGN (sizeof (TwoPhaseFileHeader ));
1640
1651
subxids = (TransactionId * ) bufptr ;
1641
1652
bufptr += MAXALIGN (hdr -> nsubxacts * sizeof (TransactionId ));
1642
- bufptr += MAXALIGN (hdr -> ncommitrels * sizeof (RelFileFork ));
1643
- bufptr += MAXALIGN (hdr -> nabortrels * sizeof (RelFileFork ));
1653
+ bufptr += MAXALIGN (hdr -> ncommitrels * sizeof (RelFileNode ));
1654
+ bufptr += MAXALIGN (hdr -> nabortrels * sizeof (RelFileNode ));
1644
1655
1645
1656
/*
1646
1657
* Reconstruct subtrans state for the transaction --- needed
@@ -1693,7 +1704,7 @@ RecordTransactionCommitPrepared(TransactionId xid,
1693
1704
int nchildren ,
1694
1705
TransactionId * children ,
1695
1706
int nrels ,
1696
- RelFileFork * rels )
1707
+ RelFileNode * rels )
1697
1708
{
1698
1709
XLogRecData rdata [3 ];
1699
1710
int lastrdata = 0 ;
@@ -1718,7 +1729,7 @@ RecordTransactionCommitPrepared(TransactionId xid,
1718
1729
{
1719
1730
rdata [0 ].next = & (rdata [1 ]);
1720
1731
rdata [1 ].data = (char * ) rels ;
1721
- rdata [1 ].len = nrels * sizeof (RelFileFork );
1732
+ rdata [1 ].len = nrels * sizeof (RelFileNode );
1722
1733
rdata [1 ].buffer = InvalidBuffer ;
1723
1734
lastrdata = 1 ;
1724
1735
}
@@ -1766,7 +1777,7 @@ RecordTransactionAbortPrepared(TransactionId xid,
1766
1777
int nchildren ,
1767
1778
TransactionId * children ,
1768
1779
int nrels ,
1769
- RelFileFork * rels )
1780
+ RelFileNode * rels )
1770
1781
{
1771
1782
XLogRecData rdata [3 ];
1772
1783
int lastrdata = 0 ;
@@ -1796,7 +1807,7 @@ RecordTransactionAbortPrepared(TransactionId xid,
1796
1807
{
1797
1808
rdata [0 ].next = & (rdata [1 ]);
1798
1809
rdata [1 ].data = (char * ) rels ;
1799
- rdata [1 ].len = nrels * sizeof (RelFileFork );
1810
+ rdata [1 ].len = nrels * sizeof (RelFileNode );
1800
1811
rdata [1 ].buffer = InvalidBuffer ;
1801
1812
lastrdata = 1 ;
1802
1813
}
0 commit comments