@@ -1264,11 +1264,15 @@ StandbyTransactionIdIsPrepared(TransactionId xid)
1264
1264
TwoPhaseFileHeader * hdr ;
1265
1265
bool result ;
1266
1266
1267
+ fprintf (stderr , "===(%u) StandbyTransactionIdIsPrepared(%u) \n" , getpid (), xid );
1268
+
1267
1269
Assert (TransactionIdIsValid (xid ));
1268
1270
1269
1271
if (max_prepared_xacts <= 0 )
1270
1272
return false; /* nothing to do */
1271
1273
1274
+ // check for in-memory tx here too
1275
+
1272
1276
/* Read and validate file */
1273
1277
buf = ReadTwoPhaseFile (xid , false);
1274
1278
if (buf == NULL )
@@ -1848,90 +1852,90 @@ PrescanPreparedTransactions(TransactionId **xids_p, int *nxids_p)
1848
1852
return result ;
1849
1853
}
1850
1854
1851
- /*
1852
- * StandbyRecoverPreparedTransactions
1853
- *
1854
- * Scan the pg_twophase directory and setup all the required information to
1855
- * allow standby queries to treat prepared transactions as still active.
1856
- * This is never called at the end of recovery - we use
1857
- * RecoverPreparedTransactions() at that point.
1858
- *
1859
- * Currently we simply call SubTransSetParent() for any subxids of prepared
1860
- * transactions. If overwriteOK is true, it's OK if some XIDs have already
1861
- * been marked in pg_subtrans.
1862
- */
1863
- void
1864
- StandbyRecoverPreparedTransactions (bool overwriteOK )
1865
- {
1866
- DIR * cldir ;
1867
- struct dirent * clde ;
1868
-
1869
- fprintf (stderr , "!===(%u) StandbyRecoverPreparedTransactions called, overwriteOK = %u\n" , getpid (), (int )overwriteOK );
1870
-
1871
- cldir = AllocateDir (TWOPHASE_DIR );
1872
- while ((clde = ReadDir (cldir , TWOPHASE_DIR )) != NULL )
1873
- {
1874
- if (strlen (clde -> d_name ) == 8 &&
1875
- strspn (clde -> d_name , "0123456789ABCDEF" ) == 8 )
1876
- {
1877
- TransactionId xid ;
1878
- char * buf ;
1879
- TwoPhaseFileHeader * hdr ;
1880
- TransactionId * subxids ;
1881
- int i ;
1882
-
1883
- xid = (TransactionId ) strtoul (clde -> d_name , NULL , 16 );
1884
-
1885
- /* Already processed? */
1886
- if (TransactionIdDidCommit (xid ) || TransactionIdDidAbort (xid ))
1887
- {
1888
- ereport (WARNING ,
1889
- (errmsg ("removing stale two-phase state file \"%s\"" ,
1890
- clde -> d_name )));
1891
- RemoveTwoPhaseFile (xid , true);
1892
- continue ;
1893
- }
1894
-
1895
- /* Read and validate file */
1896
- buf = ReadTwoPhaseFile (xid , true);
1897
- if (buf == NULL )
1898
- {
1899
- ereport (WARNING ,
1900
- (errmsg ("removing corrupt two-phase state file \"%s\"" ,
1901
- clde -> d_name )));
1902
- RemoveTwoPhaseFile (xid , true);
1903
- continue ;
1904
- }
1905
-
1906
- /* Deconstruct header */
1907
- hdr = (TwoPhaseFileHeader * ) buf ;
1908
- if (!TransactionIdEquals (hdr -> xid , xid ))
1909
- {
1910
- ereport (WARNING ,
1911
- (errmsg ("removing corrupt two-phase state file \"%s\"" ,
1912
- clde -> d_name )));
1913
- RemoveTwoPhaseFile (xid , true);
1914
- pfree (buf );
1915
- continue ;
1916
- }
1917
-
1918
- /*
1919
- * Examine subtransaction XIDs ... they should all follow main
1920
- * XID.
1921
- */
1922
- subxids = (TransactionId * )
1923
- (buf + MAXALIGN (sizeof (TwoPhaseFileHeader )));
1924
- for (i = 0 ; i < hdr -> nsubxacts ; i ++ )
1925
- {
1926
- TransactionId subxid = subxids [i ];
1927
-
1928
- Assert (TransactionIdFollows (subxid , xid ));
1929
- SubTransSetParent (xid , subxid , overwriteOK );
1930
- }
1931
- }
1932
- }
1933
- FreeDir (cldir );
1934
- }
1855
+ // / *
1856
+ // * StandbyRecoverPreparedTransactions
1857
+ // *
1858
+ // * Scan the pg_twophase directory and setup all the required information to
1859
+ // * allow standby queries to treat prepared transactions as still active.
1860
+ // * This is never called at the end of recovery - we use
1861
+ // * RecoverPreparedTransactions() at that point.
1862
+ // *
1863
+ // * Currently we simply call SubTransSetParent() for any subxids of prepared
1864
+ // * transactions. If overwriteOK is true, it's OK if some XIDs have already
1865
+ // * been marked in pg_subtrans.
1866
+ // */
1867
+ // void
1868
+ // StandbyRecoverPreparedTransactions(bool overwriteOK)
1869
+ // {
1870
+ // DIR *cldir;
1871
+ // struct dirent *clde;
1872
+
1873
+ // fprintf(stderr, "!===(%u) StandbyRecoverPreparedTransactions called, overwriteOK = %u\n", getpid(), (int)overwriteOK);
1874
+
1875
+ // cldir = AllocateDir(TWOPHASE_DIR);
1876
+ // while ((clde = ReadDir(cldir, TWOPHASE_DIR)) != NULL)
1877
+ // {
1878
+ // if (strlen(clde->d_name) == 8 &&
1879
+ // strspn(clde->d_name, "0123456789ABCDEF") == 8)
1880
+ // {
1881
+ // TransactionId xid;
1882
+ // char *buf;
1883
+ // TwoPhaseFileHeader *hdr;
1884
+ // TransactionId *subxids;
1885
+ // int i;
1886
+
1887
+ // xid = (TransactionId) strtoul(clde->d_name, NULL, 16);
1888
+
1889
+ // /* Already processed? */
1890
+ // if (TransactionIdDidCommit(xid) || TransactionIdDidAbort(xid))
1891
+ // {
1892
+ // ereport(WARNING,
1893
+ // (errmsg("removing stale two-phase state file \"%s\"",
1894
+ // clde->d_name)));
1895
+ // RemoveTwoPhaseFile(xid, true);
1896
+ // continue;
1897
+ // }
1898
+
1899
+ // /* Read and validate file */
1900
+ // buf = ReadTwoPhaseFile(xid, true);
1901
+ // if (buf == NULL)
1902
+ // {
1903
+ // ereport(WARNING,
1904
+ // (errmsg("removing corrupt two-phase state file \"%s\"",
1905
+ // clde->d_name)));
1906
+ // RemoveTwoPhaseFile(xid, true);
1907
+ // continue;
1908
+ // }
1909
+
1910
+ // /* Deconstruct header */
1911
+ // hdr = (TwoPhaseFileHeader *) buf;
1912
+ // if (!TransactionIdEquals(hdr->xid, xid))
1913
+ // {
1914
+ // ereport(WARNING,
1915
+ // (errmsg("removing corrupt two-phase state file \"%s\"",
1916
+ // clde->d_name)));
1917
+ // RemoveTwoPhaseFile(xid, true);
1918
+ // pfree(buf);
1919
+ // continue;
1920
+ // }
1921
+
1922
+ // /*
1923
+ // * Examine subtransaction XIDs ... they should all follow main
1924
+ // * XID.
1925
+ // */
1926
+ // subxids = (TransactionId *)
1927
+ // (buf + MAXALIGN(sizeof(TwoPhaseFileHeader)));
1928
+ // for (i = 0; i < hdr->nsubxacts; i++)
1929
+ // {
1930
+ // TransactionId subxid = subxids[i];
1931
+
1932
+ // Assert(TransactionIdFollows(subxid, xid));
1933
+ // SubTransSetParent(xid, subxid, overwriteOK);
1934
+ // }
1935
+ // }
1936
+ // }
1937
+ // FreeDir(cldir);
1938
+ // }
1935
1939
1936
1940
/*
1937
1941
* RecoverPreparedFromFiles
@@ -1941,12 +1945,12 @@ StandbyRecoverPreparedTransactions(bool overwriteOK)
1941
1945
* startup.
1942
1946
*/
1943
1947
void
1944
- RecoverPreparedFromFiles (void )
1948
+ RecoverPreparedFromFiles (bool overwriteOK )
1945
1949
{
1946
1950
char dir [MAXPGPATH ];
1947
1951
DIR * cldir ;
1948
1952
struct dirent * clde ;
1949
- bool overwriteOK = false;
1953
+ // bool overwriteOK = false;
1950
1954
1951
1955
fprintf (stderr , "===(%u) RecoverPreparedFromFiles called\n" , getpid ());
1952
1956
@@ -1965,32 +1969,32 @@ RecoverPreparedFromFiles(void)
1965
1969
TransactionId * subxids ;
1966
1970
GlobalTransaction gxact ;
1967
1971
int i ;
1968
- // PGXACT *pgxact;
1972
+ PGXACT * pgxact ;
1969
1973
1970
1974
1971
1975
xid = (TransactionId ) strtoul (clde -> d_name , NULL , 16 );
1972
1976
1973
- /* Already recovered from WAL? */
1974
- if (TransactionIdIsInProgress (xid ))
1975
- {
1976
- fprintf (stderr , "! xid %x is in progress\n" , xid );
1977
- continue ;
1978
- }
1979
-
1980
1977
// /* Already recovered from WAL? */
1981
- // for (i = 0; i < TwoPhaseState->numPrepXacts; i++ )
1978
+ // if (TransactionIdIsInProgress(xid) )
1982
1979
// {
1983
- // gxact = TwoPhaseState->prepXacts[i];
1984
- // pgxact = &ProcGlobal->allPgXact[gxact->pgprocno];
1980
+ // fprintf(stderr, "! xid %x is in progress\n", xid);
1981
+ // continue;
1982
+ // }
1983
+
1984
+ /* Already recovered from WAL? */
1985
+ for (i = 0 ; i < TwoPhaseState -> numPrepXacts ; i ++ )
1986
+ {
1987
+ gxact = TwoPhaseState -> prepXacts [i ];
1988
+ pgxact = & ProcGlobal -> allPgXact [gxact -> pgprocno ];
1985
1989
1986
1990
1987
- // fprintf(stderr, "! %x ?= %x\n", xid, pgxact->xid);
1991
+ fprintf (stderr , "! %x ?= %x\n" , xid , pgxact -> xid );
1988
1992
1989
1993
1990
1994
1991
- // if (xid == pgxact->xid)
1992
- // goto next_file;
1993
- // }
1995
+ if (xid == pgxact -> xid )
1996
+ goto next_file ;
1997
+ }
1994
1998
1995
1999
/* Already processed? */
1996
2000
if (TransactionIdDidCommit (xid ) || TransactionIdDidAbort (xid ))
@@ -2080,8 +2084,8 @@ RecoverPreparedFromFiles(void)
2080
2084
pfree (buf );
2081
2085
}
2082
2086
2083
- // next_file:
2084
- // continue;
2087
+ next_file :
2088
+ continue ;
2085
2089
2086
2090
}
2087
2091
FreeDir (cldir );
0 commit comments