diff options
author | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2010-09-11 15:48:04 +0000 |
---|---|---|
committer | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2010-09-11 15:48:04 +0000 |
commit | 2746e5f21d4dce07ee55c58b2035ff631470577f (patch) | |
tree | 421c208e30bc3ac7cae8c6282a1304595dfaa625 /src/backend/access | |
parent | 81624db39aa7501690aab71a68af689df78b71e8 (diff) | |
download | postgresql-2746e5f21d4dce07ee55c58b2035ff631470577f.tar.gz postgresql-2746e5f21d4dce07ee55c58b2035ff631470577f.zip |
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.
Diffstat (limited to 'src/backend/access')
-rw-r--r-- | src/backend/access/transam/twophase.c | 24 | ||||
-rw-r--r-- | src/backend/access/transam/xact.c | 10 |
2 files changed, 32 insertions, 2 deletions
diff --git a/src/backend/access/transam/twophase.c b/src/backend/access/transam/twophase.c index e3c3bc8dbc4..3a3302e8b80 100644 --- a/src/backend/access/transam/twophase.c +++ b/src/backend/access/transam/twophase.c @@ -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); @@ -2078,6 +2093,13 @@ RecordTransactionAbortPrepared(TransactionId xid, 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. */ diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c index 6015eaab1db..89f17a9d161 100644 --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -10,7 +10,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.298 2010/08/13 20:10:50 rhaas Exp $ + * $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.299 2010/09/11 15:48:04 heikki Exp $ * *------------------------------------------------------------------------- */ @@ -36,6 +36,7 @@ #include "libpq/be-fsstubs.h" #include "miscadmin.h" #include "pgstat.h" +#include "replication/walsender.h" #include "storage/bufmgr.h" #include "storage/fd.h" #include "storage/lmgr.h" @@ -1068,6 +1069,13 @@ 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 */ if (markXidCommitted) |