aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/transam/xact.c
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2014-12-03 11:53:02 -0300
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2014-12-03 11:53:02 -0300
commit73c986adde5d73a5e2555da9b5c8facedb146dcd (patch)
tree29ee4f6c800c3614cfd3316c7026e30e552e12a4 /src/backend/access/transam/xact.c
parent6597ec9be6a9ed50390f73235d6654ec32a0b944 (diff)
downloadpostgresql-73c986adde5d73a5e2555da9b5c8facedb146dcd.tar.gz
postgresql-73c986adde5d73a5e2555da9b5c8facedb146dcd.zip
Keep track of transaction commit timestamps
Transactions can now set their commit timestamp directly as they commit, or an external transaction commit timestamp can be fed from an outside system using the new function TransactionTreeSetCommitTsData(). This data is crash-safe, and truncated at Xid freeze point, same as pg_clog. This module is disabled by default because it causes a performance hit, but can be enabled in postgresql.conf requiring only a server restart. A new test in src/test/modules is included. Catalog version bumped due to the new subdirectory within PGDATA and a couple of new SQL functions. Authors: Álvaro Herrera and Petr Jelínek Reviewed to varying degrees by Michael Paquier, Andres Freund, Robert Haas, Amit Kapila, Fujii Masao, Jaime Casanova, Simon Riggs, Steven Singer, Peter Eisentraut
Diffstat (limited to 'src/backend/access/transam/xact.c')
-rw-r--r--src/backend/access/transam/xact.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c
index 763e9deb6f5..8b2f7140cfc 100644
--- a/src/backend/access/transam/xact.c
+++ b/src/backend/access/transam/xact.c
@@ -20,6 +20,7 @@
#include <time.h>
#include <unistd.h>
+#include "access/commit_ts.h"
#include "access/multixact.h"
#include "access/subtrans.h"
#include "access/transam.h"
@@ -1135,6 +1136,21 @@ RecordTransactionCommit(void)
}
/*
+ * We only need to log the commit timestamp separately if the node
+ * identifier is a valid value; the commit record above already contains
+ * the timestamp info otherwise, and will be used to load it.
+ */
+ if (markXidCommitted)
+ {
+ CommitTsNodeId node_id;
+
+ node_id = CommitTsGetDefaultNodeId();
+ TransactionTreeSetCommitTsData(xid, nchildren, children,
+ xactStopTimestamp,
+ node_id, node_id != InvalidCommitTsNodeId);
+ }
+
+ /*
* Check if we want to commit asynchronously. We can allow the XLOG flush
* to happen asynchronously if synchronous_commit=off, or if the current
* transaction has not performed any WAL-logged operation. The latter
@@ -4644,6 +4660,7 @@ xactGetCommittedChildren(TransactionId **ptr)
*/
static void
xact_redo_commit_internal(TransactionId xid, XLogRecPtr lsn,
+ TimestampTz commit_time,
TransactionId *sub_xids, int nsubxacts,
SharedInvalidationMessage *inval_msgs, int nmsgs,
RelFileNode *xnodes, int nrels,
@@ -4671,6 +4688,10 @@ xact_redo_commit_internal(TransactionId xid, XLogRecPtr lsn,
LWLockRelease(XidGenLock);
}
+ /* Set the transaction commit timestamp and metadata */
+ TransactionTreeSetCommitTsData(xid, nsubxacts, sub_xids,
+ commit_time, InvalidCommitTsNodeId, false);
+
if (standbyState == STANDBY_DISABLED)
{
/*
@@ -4790,7 +4811,8 @@ xact_redo_commit(xl_xact_commit *xlrec,
/* invalidation messages array follows subxids */
inval_msgs = (SharedInvalidationMessage *) &(subxacts[xlrec->nsubxacts]);
- xact_redo_commit_internal(xid, lsn, subxacts, xlrec->nsubxacts,
+ xact_redo_commit_internal(xid, lsn, xlrec->xact_time,
+ subxacts, xlrec->nsubxacts,
inval_msgs, xlrec->nmsgs,
xlrec->xnodes, xlrec->nrels,
xlrec->dbId,
@@ -4805,7 +4827,8 @@ static void
xact_redo_commit_compact(xl_xact_commit_compact *xlrec,
TransactionId xid, XLogRecPtr lsn)
{
- xact_redo_commit_internal(xid, lsn, xlrec->subxacts, xlrec->nsubxacts,
+ xact_redo_commit_internal(xid, lsn, xlrec->xact_time,
+ xlrec->subxacts, xlrec->nsubxacts,
NULL, 0, /* inval msgs */
NULL, 0, /* relfilenodes */
InvalidOid, /* dbId */