@@ -221,8 +221,7 @@ static void RemoveGXact(GlobalTransaction gxact);
221
221
static void XlogReadTwoPhaseData (XLogRecPtr lsn , char * * buf , int * len );
222
222
static char * ProcessTwoPhaseBuffer (TransactionId xid ,
223
223
XLogRecPtr prepare_start_lsn ,
224
- bool fromdisk , bool overwriteOK , bool setParent ,
225
- bool setNextXid );
224
+ bool fromdisk , bool setParent , bool setNextXid );
226
225
static void MarkAsPreparingGuts (GlobalTransaction gxact , TransactionId xid ,
227
226
const char * gid , TimestampTz prepared_at , Oid owner ,
228
227
Oid databaseid );
@@ -1743,8 +1742,7 @@ restoreTwoPhaseData(void)
1743
1742
xid = (TransactionId ) strtoul (clde -> d_name , NULL , 16 );
1744
1743
1745
1744
buf = ProcessTwoPhaseBuffer (xid , InvalidXLogRecPtr ,
1746
- true, false, false,
1747
- false);
1745
+ true, false, false);
1748
1746
if (buf == NULL )
1749
1747
continue ;
1750
1748
@@ -1804,8 +1802,7 @@ PrescanPreparedTransactions(TransactionId **xids_p, int *nxids_p)
1804
1802
1805
1803
buf = ProcessTwoPhaseBuffer (xid ,
1806
1804
gxact -> prepare_start_lsn ,
1807
- gxact -> ondisk , false, false,
1808
- true);
1805
+ gxact -> ondisk , false, true);
1809
1806
1810
1807
if (buf == NULL )
1811
1808
continue ;
@@ -1858,12 +1855,12 @@ PrescanPreparedTransactions(TransactionId **xids_p, int *nxids_p)
1858
1855
* This is never called at the end of recovery - we use
1859
1856
* RecoverPreparedTransactions() at that point.
1860
1857
*
1861
- * Currently we simply call SubTransSetParent() for any subxids of prepared
1862
- * transactions. If overwriteOK is true, it's OK if some XIDs have already
1863
- * been marked in pg_subtrans .
1858
+ * The lack of calls to SubTransSetParent() calls here is by design;
1859
+ * those calls are made by RecoverPreparedTransactions() at the end of recovery
1860
+ * for those xacts that need this .
1864
1861
*/
1865
1862
void
1866
- StandbyRecoverPreparedTransactions (bool overwriteOK )
1863
+ StandbyRecoverPreparedTransactions (void )
1867
1864
{
1868
1865
int i ;
1869
1866
@@ -1880,8 +1877,7 @@ StandbyRecoverPreparedTransactions(bool overwriteOK)
1880
1877
1881
1878
buf = ProcessTwoPhaseBuffer (xid ,
1882
1879
gxact -> prepare_start_lsn ,
1883
- gxact -> ondisk , overwriteOK , true,
1884
- false);
1880
+ gxact -> ondisk , false, false);
1885
1881
if (buf != NULL )
1886
1882
pfree (buf );
1887
1883
}
@@ -1895,6 +1891,13 @@ StandbyRecoverPreparedTransactions(bool overwriteOK)
1895
1891
* each prepared transaction (reacquire locks, etc).
1896
1892
*
1897
1893
* This is run during database startup.
1894
+ *
1895
+ * At the end of recovery the way we take snapshots will change. We now need
1896
+ * to mark all running transactions with their full SubTransSetParent() info
1897
+ * to allow normal snapshots to work correctly if snapshots overflow.
1898
+ * We do this here because by definition prepared transactions are the only
1899
+ * type of write transaction still running, so this is necessary and
1900
+ * complete.
1898
1901
*/
1899
1902
void
1900
1903
RecoverPreparedTransactions (void )
@@ -1913,15 +1916,21 @@ RecoverPreparedTransactions(void)
1913
1916
TwoPhaseFileHeader * hdr ;
1914
1917
TransactionId * subxids ;
1915
1918
const char * gid ;
1916
- bool overwriteOK = false;
1917
- int i ;
1918
1919
1919
1920
xid = gxact -> xid ;
1920
1921
1922
+ /*
1923
+ * Reconstruct subtrans state for the transaction --- needed
1924
+ * because pg_subtrans is not preserved over a restart. Note that
1925
+ * we are linking all the subtransactions directly to the
1926
+ * top-level XID; there may originally have been a more complex
1927
+ * hierarchy, but there's no need to restore that exactly.
1928
+ * It's possible that SubTransSetParent has been set before, if
1929
+ * the prepared transaction generated xid assignment records.
1930
+ */
1921
1931
buf = ProcessTwoPhaseBuffer (xid ,
1922
1932
gxact -> prepare_start_lsn ,
1923
- gxact -> ondisk , false, false,
1924
- false);
1933
+ gxact -> ondisk , true, false);
1925
1934
if (buf == NULL )
1926
1935
continue ;
1927
1936
@@ -1939,25 +1948,6 @@ RecoverPreparedTransactions(void)
1939
1948
bufptr += MAXALIGN (hdr -> nabortrels * sizeof (RelFileNode ));
1940
1949
bufptr += MAXALIGN (hdr -> ninvalmsgs * sizeof (SharedInvalidationMessage ));
1941
1950
1942
- /*
1943
- * It's possible that SubTransSetParent has been set before, if
1944
- * the prepared transaction generated xid assignment records. Test
1945
- * here must match one used in AssignTransactionId().
1946
- */
1947
- if (InHotStandby && (hdr -> nsubxacts >= PGPROC_MAX_CACHED_SUBXIDS ||
1948
- XLogLogicalInfoActive ()))
1949
- overwriteOK = true;
1950
-
1951
- /*
1952
- * Reconstruct subtrans state for the transaction --- needed
1953
- * because pg_subtrans is not preserved over a restart. Note that
1954
- * we are linking all the subtransactions directly to the
1955
- * top-level XID; there may originally have been a more complex
1956
- * hierarchy, but there's no need to restore that exactly.
1957
- */
1958
- for (i = 0 ; i < hdr -> nsubxacts ; i ++ )
1959
- SubTransSetParent (subxids [i ], xid , true);
1960
-
1961
1951
/*
1962
1952
* Recreate its GXACT and dummy PGPROC. But, check whether
1963
1953
* it was added in redo and already has a shmem entry for
@@ -2006,16 +1996,15 @@ RecoverPreparedTransactions(void)
2006
1996
* Given a transaction id, read it either from disk or read it directly
2007
1997
* via shmem xlog record pointer using the provided "prepare_start_lsn".
2008
1998
*
2009
- * If setParent is true, then use the overwriteOK parameter to set up
2010
- * subtransaction parent linkages.
1999
+ * If setParent is true, set up subtransaction parent linkages.
2011
2000
*
2012
2001
* If setNextXid is true, set ShmemVariableCache->nextXid to the newest
2013
2002
* value scanned.
2014
2003
*/
2015
2004
static char *
2016
2005
ProcessTwoPhaseBuffer (TransactionId xid ,
2017
2006
XLogRecPtr prepare_start_lsn ,
2018
- bool fromdisk , bool overwriteOK ,
2007
+ bool fromdisk ,
2019
2008
bool setParent , bool setNextXid )
2020
2009
{
2021
2010
TransactionId origNextXid = ShmemVariableCache -> nextXid ;
@@ -2142,7 +2131,7 @@ ProcessTwoPhaseBuffer(TransactionId xid,
2142
2131
}
2143
2132
2144
2133
if (setParent )
2145
- SubTransSetParent (subxid , xid , overwriteOK );
2134
+ SubTransSetParent (subxid , xid );
2146
2135
}
2147
2136
2148
2137
return buf ;
0 commit comments