mirror of
https://github.com/postgres/postgres.git
synced 2025-11-09 06:21:09 +03:00
Introduce latches. A latch is a boolean variable, with the capability to
wait until it is set. Latches can be used to reliably wait until a signal arrives, which is hard otherwise because signals don't interrupt select() on some platforms, and even when they do, there's race conditions. On Unix, latches use the so called self-pipe trick under the covers to implement the sleep until the latch is set, without race conditions. On Windows, Windows events are used. Use the new latch abstraction to sleep in walsender, so that as soon as a transaction finishes, walsender is woken up to immediately send the WAL to the standby. This reduces the latency between master and standby, which is good. Preliminary work by Fujii Masao. The latch implementation is by me, with helpful comments from many people.
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/access/transam/twophase.c,v 1.63 2010/08/13 20:10:50 rhaas Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/access/transam/twophase.c,v 1.64 2010/09/11 15:48:04 heikki Exp $
|
||||
*
|
||||
* NOTES
|
||||
* Each global transaction is associated with a global transaction
|
||||
@@ -55,6 +55,7 @@
|
||||
#include "miscadmin.h"
|
||||
#include "pg_trace.h"
|
||||
#include "pgstat.h"
|
||||
#include "replication/walsender.h"
|
||||
#include "storage/fd.h"
|
||||
#include "storage/procarray.h"
|
||||
#include "storage/sinvaladt.h"
|
||||
@@ -1025,6 +1026,13 @@ 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))
|
||||
{
|
||||
@@ -2005,6 +2013,13 @@ 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);
|
||||
|
||||
@@ -2077,6 +2092,13 @@ 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.
|
||||
|
||||
Reference in New Issue
Block a user