mirror of
https://github.com/postgres/postgres.git
synced 2025-07-14 08:21:07 +03:00
Make walsender more responsive.
Per testing by Andres Freund, this improves replication performance and reduces replication latency and latency jitter. I was a bit concerned about moving more work into XLogInsert, but testing seems to show that it's not a problem in practice. Along the way, improve comments for WaitLatchOrSocket. Andres Freund. Review and stylistic cleanup by me.
This commit is contained in:
@ -1042,13 +1042,6 @@ EndPrepare(GlobalTransaction gxact)
|
||||
|
||||
/* If we crash now, we have prepared: WAL replay will fix things */
|
||||
|
||||
/*
|
||||
* Wake up all walsenders to send WAL up to the PREPARE record immediately
|
||||
* if replication is enabled
|
||||
*/
|
||||
if (max_wal_senders > 0)
|
||||
WalSndWakeup();
|
||||
|
||||
/* write correct CRC and close file */
|
||||
if ((write(fd, &statefile_crc, sizeof(pg_crc32))) != sizeof(pg_crc32))
|
||||
{
|
||||
@ -2045,13 +2038,6 @@ RecordTransactionCommitPrepared(TransactionId xid,
|
||||
/* Flush XLOG to disk */
|
||||
XLogFlush(recptr);
|
||||
|
||||
/*
|
||||
* Wake up all walsenders to send WAL up to the COMMIT PREPARED record
|
||||
* immediately if replication is enabled
|
||||
*/
|
||||
if (max_wal_senders > 0)
|
||||
WalSndWakeup();
|
||||
|
||||
/* Mark the transaction committed in pg_clog */
|
||||
TransactionIdCommitTree(xid, nchildren, children);
|
||||
|
||||
@ -2132,13 +2118,6 @@ RecordTransactionAbortPrepared(TransactionId xid,
|
||||
/* Always flush, since we're about to remove the 2PC state file */
|
||||
XLogFlush(recptr);
|
||||
|
||||
/*
|
||||
* Wake up all walsenders to send WAL up to the ABORT PREPARED record
|
||||
* immediately if replication is enabled
|
||||
*/
|
||||
if (max_wal_senders > 0)
|
||||
WalSndWakeup();
|
||||
|
||||
/*
|
||||
* Mark the transaction aborted in clog. This is not absolutely necessary
|
||||
* but we may as well do it while we are here.
|
||||
|
@ -1141,13 +1141,6 @@ RecordTransactionCommit(void)
|
||||
|
||||
XLogFlush(XactLastRecEnd);
|
||||
|
||||
/*
|
||||
* Wake up all walsenders to send WAL up to the COMMIT record
|
||||
* immediately if replication is enabled
|
||||
*/
|
||||
if (max_wal_senders > 0)
|
||||
WalSndWakeup();
|
||||
|
||||
/*
|
||||
* Now we may update the CLOG, if we wrote a COMMIT record above
|
||||
*/
|
||||
|
@ -1025,6 +1025,8 @@ begin:;
|
||||
|
||||
END_CRIT_SECTION();
|
||||
|
||||
/* wakeup the WalSnd now that we released the WALWriteLock */
|
||||
WalSndWakeupProcessRequests();
|
||||
return RecPtr;
|
||||
}
|
||||
|
||||
@ -1208,6 +1210,9 @@ begin:;
|
||||
|
||||
END_CRIT_SECTION();
|
||||
|
||||
/* wakeup the WalSnd now that we outside contented locks */
|
||||
WalSndWakeupProcessRequests();
|
||||
|
||||
return RecPtr;
|
||||
}
|
||||
|
||||
@ -1792,6 +1797,10 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible, bool xlog_switch)
|
||||
if (finishing_seg || (xlog_switch && last_iteration))
|
||||
{
|
||||
issue_xlog_fsync(openLogFile, openLogSegNo);
|
||||
|
||||
/* signal that we need to wakeup WalSnd later */
|
||||
WalSndWakeupRequest();
|
||||
|
||||
LogwrtResult.Flush = LogwrtResult.Write; /* end of page */
|
||||
|
||||
if (XLogArchivingActive())
|
||||
@ -1854,7 +1863,11 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible, bool xlog_switch)
|
||||
openLogFile = XLogFileOpen(openLogSegNo);
|
||||
openLogOff = 0;
|
||||
}
|
||||
|
||||
issue_xlog_fsync(openLogFile, openLogSegNo);
|
||||
|
||||
/* signal that we need to wakeup WalSnd later */
|
||||
WalSndWakeupRequest();
|
||||
}
|
||||
LogwrtResult.Flush = LogwrtResult.Write;
|
||||
}
|
||||
@ -2120,6 +2133,9 @@ XLogFlush(XLogRecPtr record)
|
||||
|
||||
END_CRIT_SECTION();
|
||||
|
||||
/* wakeup the WalSnd now that we released the WALWriteLock */
|
||||
WalSndWakeupProcessRequests();
|
||||
|
||||
/*
|
||||
* If we still haven't flushed to the request point then we have a
|
||||
* problem; most likely, the requested flush point is past end of XLOG.
|
||||
@ -2245,13 +2261,8 @@ XLogBackgroundFlush(void)
|
||||
|
||||
END_CRIT_SECTION();
|
||||
|
||||
/*
|
||||
* If we wrote something then we have something to send to standbys also,
|
||||
* otherwise the replication delay become around 7s with just async
|
||||
* commit.
|
||||
*/
|
||||
if (wrote_something)
|
||||
WalSndWakeup();
|
||||
/* wakeup the WalSnd now that we released the WALWriteLock */
|
||||
WalSndWakeupProcessRequests();
|
||||
|
||||
return wrote_something;
|
||||
}
|
||||
|
Reference in New Issue
Block a user