@@ -291,16 +291,15 @@ static bool doPageWrites;
291
291
*
292
292
* LogwrtRqst indicates a byte position that we need to write and/or fsync
293
293
* the log up to (all records before that point must be written or fsynced).
294
- * LogwrtResult indicates the byte positions we have already written/fsynced.
295
- * These structs are identical but are declared separately to indicate their
296
- * slightly different functions.
294
+ * The positions already written/fsynced are maintained in logWriteResult
295
+ * and logFlushResult.
297
296
*
298
- * To read XLogCtl->LogwrtResult , you must hold either info_lck or
299
- * WALWriteLock. To update it , you need to hold both locks. The point of
300
- * this arrangement is that the value can be examined by code that already
301
- * holds WALWriteLock without needing to grab info_lck as well. In addition
302
- * to the shared variable, each backend has a private copy of LogwrtResult,
303
- * which is updated when convenient.
297
+ * To read XLogCtl->logWriteResult or ->logFlushResult , you must hold either
298
+ * info_lck or WALWriteLock. To update them , you need to hold both locks.
299
+ * The point of this arrangement is that the value can be examined by code
300
+ * that already holds WALWriteLock without needing to grab info_lck as well.
301
+ * In addition to the shared variable, each backend has a private copy of
302
+ * both in LogwrtResult, which is updated when convenient.
304
303
*
305
304
* The request bookkeeping is simpler: there is a shared XLogCtl->LogwrtRqst
306
305
* (protected by info_lck), but we don't need to cache any copies of it.
@@ -478,7 +477,8 @@ typedef struct XLogCtlData
478
477
* Protected by info_lck and WALWriteLock (you must hold either lock to
479
478
* read it, but both to update)
480
479
*/
481
- XLogwrtResult LogwrtResult ;
480
+ XLogRecPtr logWriteResult ; /* last byte + 1 written out */
481
+ XLogRecPtr logFlushResult ; /* last byte + 1 flushed */
482
482
483
483
/*
484
484
* Latest initialized page in the cache (last byte position + 1).
@@ -614,6 +614,15 @@ static int UsableBytesInSegment;
614
614
*/
615
615
static XLogwrtResult LogwrtResult = {0 , 0 };
616
616
617
+ /*
618
+ * Update local copy of shared XLogCtl->log{Write,Flush}Result
619
+ */
620
+ #define RefreshXLogWriteResult (_target ) \
621
+ do { \
622
+ _target.Write = XLogCtl->logWriteResult; \
623
+ _target.Flush = XLogCtl->logFlushResult; \
624
+ } while (0)
625
+
617
626
/*
618
627
* openLogFile is -1 or a kernel FD for an open log file segment.
619
628
* openLogSegNo identifies the segment, and openLogTLI the corresponding TLI.
@@ -960,7 +969,7 @@ XLogInsertRecord(XLogRecData *rdata,
960
969
if (XLogCtl -> LogwrtRqst .Write < EndPos )
961
970
XLogCtl -> LogwrtRqst .Write = EndPos ;
962
971
/* update local result copy while I have the chance */
963
- LogwrtResult = XLogCtl -> LogwrtResult ;
972
+ RefreshXLogWriteResult ( LogwrtResult ) ;
964
973
SpinLockRelease (& XLogCtl -> info_lck );
965
974
}
966
975
@@ -1984,7 +1993,7 @@ AdvanceXLInsertBuffer(XLogRecPtr upto, TimeLineID tli, bool opportunistic)
1984
1993
SpinLockAcquire (& XLogCtl -> info_lck );
1985
1994
if (XLogCtl -> LogwrtRqst .Write < OldPageRqstPtr )
1986
1995
XLogCtl -> LogwrtRqst .Write = OldPageRqstPtr ;
1987
- LogwrtResult = XLogCtl -> LogwrtResult ;
1996
+ RefreshXLogWriteResult ( LogwrtResult ) ;
1988
1997
SpinLockRelease (& XLogCtl -> info_lck );
1989
1998
1990
1999
/*
@@ -2005,7 +2014,7 @@ AdvanceXLInsertBuffer(XLogRecPtr upto, TimeLineID tli, bool opportunistic)
2005
2014
2006
2015
LWLockAcquire (WALWriteLock , LW_EXCLUSIVE );
2007
2016
2008
- LogwrtResult = XLogCtl -> LogwrtResult ;
2017
+ RefreshXLogWriteResult ( LogwrtResult ) ;
2009
2018
if (LogwrtResult .Write >= OldPageRqstPtr )
2010
2019
{
2011
2020
/* OK, someone wrote it already */
@@ -2289,7 +2298,7 @@ XLogWrite(XLogwrtRqst WriteRqst, TimeLineID tli, bool flexible)
2289
2298
/*
2290
2299
* Update local LogwrtResult (caller probably did this already, but...)
2291
2300
*/
2292
- LogwrtResult = XLogCtl -> LogwrtResult ;
2301
+ RefreshXLogWriteResult ( LogwrtResult ) ;
2293
2302
2294
2303
/*
2295
2304
* Since successive pages in the xlog cache are consecutively allocated,
@@ -2549,7 +2558,8 @@ XLogWrite(XLogwrtRqst WriteRqst, TimeLineID tli, bool flexible)
2549
2558
*/
2550
2559
{
2551
2560
SpinLockAcquire (& XLogCtl -> info_lck );
2552
- XLogCtl -> LogwrtResult = LogwrtResult ;
2561
+ XLogCtl -> logWriteResult = LogwrtResult .Write ;
2562
+ XLogCtl -> logFlushResult = LogwrtResult .Flush ;
2553
2563
if (XLogCtl -> LogwrtRqst .Write < LogwrtResult .Write )
2554
2564
XLogCtl -> LogwrtRqst .Write = LogwrtResult .Write ;
2555
2565
if (XLogCtl -> LogwrtRqst .Flush < LogwrtResult .Flush )
@@ -2572,7 +2582,7 @@ XLogSetAsyncXactLSN(XLogRecPtr asyncXactLSN)
2572
2582
XLogRecPtr prevAsyncXactLSN ;
2573
2583
2574
2584
SpinLockAcquire (& XLogCtl -> info_lck );
2575
- LogwrtResult = XLogCtl -> LogwrtResult ;
2585
+ RefreshXLogWriteResult ( LogwrtResult ) ;
2576
2586
sleeping = XLogCtl -> WalWriterSleeping ;
2577
2587
prevAsyncXactLSN = XLogCtl -> asyncXactLSN ;
2578
2588
if (XLogCtl -> asyncXactLSN < asyncXactLSN )
@@ -2784,7 +2794,7 @@ XLogFlush(XLogRecPtr record)
2784
2794
SpinLockAcquire (& XLogCtl -> info_lck );
2785
2795
if (WriteRqstPtr < XLogCtl -> LogwrtRqst .Write )
2786
2796
WriteRqstPtr = XLogCtl -> LogwrtRqst .Write ;
2787
- LogwrtResult = XLogCtl -> LogwrtResult ;
2797
+ RefreshXLogWriteResult ( LogwrtResult ) ;
2788
2798
SpinLockRelease (& XLogCtl -> info_lck );
2789
2799
2790
2800
/* done already? */
@@ -2815,7 +2825,7 @@ XLogFlush(XLogRecPtr record)
2815
2825
}
2816
2826
2817
2827
/* Got the lock; recheck whether request is satisfied */
2818
- LogwrtResult = XLogCtl -> LogwrtResult ;
2828
+ RefreshXLogWriteResult ( LogwrtResult ) ;
2819
2829
if (record <= LogwrtResult .Flush )
2820
2830
{
2821
2831
LWLockRelease (WALWriteLock );
@@ -2939,7 +2949,7 @@ XLogBackgroundFlush(void)
2939
2949
2940
2950
/* read LogwrtResult and update local state */
2941
2951
SpinLockAcquire (& XLogCtl -> info_lck );
2942
- LogwrtResult = XLogCtl -> LogwrtResult ;
2952
+ RefreshXLogWriteResult ( LogwrtResult ) ;
2943
2953
WriteRqst = XLogCtl -> LogwrtRqst ;
2944
2954
SpinLockRelease (& XLogCtl -> info_lck );
2945
2955
@@ -3027,7 +3037,7 @@ XLogBackgroundFlush(void)
3027
3037
/* now wait for any in-progress insertions to finish and get write lock */
3028
3038
WaitXLogInsertionsToFinish (WriteRqst .Write );
3029
3039
LWLockAcquire (WALWriteLock , LW_EXCLUSIVE );
3030
- LogwrtResult = XLogCtl -> LogwrtResult ;
3040
+ RefreshXLogWriteResult ( LogwrtResult ) ;
3031
3041
if (WriteRqst .Write > LogwrtResult .Write ||
3032
3042
WriteRqst .Flush > LogwrtResult .Flush )
3033
3043
{
@@ -3116,7 +3126,7 @@ XLogNeedsFlush(XLogRecPtr record)
3116
3126
3117
3127
/* read LogwrtResult and update local state */
3118
3128
SpinLockAcquire (& XLogCtl -> info_lck );
3119
- LogwrtResult = XLogCtl -> LogwrtResult ;
3129
+ RefreshXLogWriteResult ( LogwrtResult ) ;
3120
3130
SpinLockRelease (& XLogCtl -> info_lck );
3121
3131
3122
3132
/* check again */
@@ -5953,7 +5963,8 @@ StartupXLOG(void)
5953
5963
5954
5964
LogwrtResult .Write = LogwrtResult .Flush = EndOfLog ;
5955
5965
5956
- XLogCtl -> LogwrtResult = LogwrtResult ;
5966
+ XLogCtl -> logWriteResult = LogwrtResult .Write ;
5967
+ XLogCtl -> logFlushResult = LogwrtResult .Flush ;
5957
5968
5958
5969
XLogCtl -> LogwrtRqst .Write = EndOfLog ;
5959
5970
XLogCtl -> LogwrtRqst .Flush = EndOfLog ;
@@ -6400,7 +6411,7 @@ GetFlushRecPtr(TimeLineID *insertTLI)
6400
6411
Assert (XLogCtl -> SharedRecoveryState == RECOVERY_STATE_DONE );
6401
6412
6402
6413
SpinLockAcquire (& XLogCtl -> info_lck );
6403
- LogwrtResult = XLogCtl -> LogwrtResult ;
6414
+ RefreshXLogWriteResult ( LogwrtResult ) ;
6404
6415
SpinLockRelease (& XLogCtl -> info_lck );
6405
6416
6406
6417
/*
@@ -9316,7 +9327,7 @@ XLogRecPtr
9316
9327
GetXLogWriteRecPtr (void )
9317
9328
{
9318
9329
SpinLockAcquire (& XLogCtl -> info_lck );
9319
- LogwrtResult = XLogCtl -> LogwrtResult ;
9330
+ RefreshXLogWriteResult ( LogwrtResult ) ;
9320
9331
SpinLockRelease (& XLogCtl -> info_lck );
9321
9332
9322
9333
return LogwrtResult .Write ;
0 commit comments