aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-x[-rw-r--r--]src/backend/access/transam/xlog.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index a95149b9399..de19d2240fc 100644..100755
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -7367,13 +7367,13 @@ RecoveryInProgress(void)
return false;
else
{
- /* use volatile pointer to prevent code rearrangement */
+ /*
+ * use volatile pointer to make sure we make a fresh read of the
+ * shared variable.
+ */
volatile XLogCtlData *xlogctl = XLogCtl;
- /* spinlock is essential on machines with weak memory ordering! */
- SpinLockAcquire(&xlogctl->info_lck);
LocalRecoveryInProgress = xlogctl->SharedRecoveryInProgress;
- SpinLockRelease(&xlogctl->info_lck);
/*
* Initialize TimeLineID and RedoRecPtr when we discover that recovery
@@ -7382,7 +7382,20 @@ RecoveryInProgress(void)
* this, see also LocalSetXLogInsertAllowed.)
*/
if (!LocalRecoveryInProgress)
+ {
+ /*
+ * If we just exited recovery, make sure we read TimeLineID and
+ * RedoRecPtr after SharedRecoveryInProgress (for machines with
+ * weak memory ordering).
+ */
+ pg_memory_barrier();
InitXLOGAccess();
+ }
+ /*
+ * Note: We don't need a memory barrier when we're still in recovery.
+ * We might exit recovery immediately after return, so the caller
+ * can't rely on 'true' meaning that we're still in recovery anyway.
+ */
return LocalRecoveryInProgress;
}