0001-Mark-snapshot-consistent-when-all-running-txes-have.patch
application/x-patch
Filename: 0001-Mark-snapshot-consistent-when-all-running-txes-have.patch
Type: application/x-patch
Part: 0
Message:
snapbuild woes
Patch
Format: format-patch
Series: patch 0001
Subject: Mark snapshot consistent when all running txes have finished.
| File | + | − |
|---|---|---|
| src/backend/replication/logical/snapbuild.c | 21 | 8 |
From 67e902eef33da9e241c079eaed9ab12a88616296 Mon Sep 17 00:00:00 2001
From: Petr Jelinek <pjmodos@pjmodos.net>
Date: Sat, 10 Dec 2016 21:56:44 +0100
Subject: [PATCH 1/2] Mark snapshot consistent when all running txes have
finished.
---
src/backend/replication/logical/snapbuild.c | 29 +++++++++++++++++++++--------
1 file changed, 21 insertions(+), 8 deletions(-)
diff --git a/src/backend/replication/logical/snapbuild.c b/src/backend/replication/logical/snapbuild.c
index 8b59fc5..5836d52 100644
--- a/src/backend/replication/logical/snapbuild.c
+++ b/src/backend/replication/logical/snapbuild.c
@@ -1213,9 +1213,11 @@ SnapBuildFindSnapshot(SnapBuild *builder, XLogRecPtr lsn, xl_running_xacts *runn
* Build catalog decoding snapshot incrementally using information about
* the currently running transactions. There are several ways to do that:
*
- * a) There were no running transactions when the xl_running_xacts record
- * was inserted, jump to CONSISTENT immediately. We might find such a
- * state we were waiting for b) and c).
+ * a) Either there were no running transactions when the xl_running_xacts
+ * record was inserted (we might find this while waiting for b) or c))
+ * or the running transactions we've been tracking have all finished
+ * by the time the xl_running_xacts was inserted. We can jump to
+ * CONSISTENT immediately.
*
* b) Wait for all toplevel transactions that were running to end. We
* simply track the number of in-progress toplevel transactions and
@@ -1251,13 +1253,18 @@ SnapBuildFindSnapshot(SnapBuild *builder, XLogRecPtr lsn, xl_running_xacts *runn
}
/*
- * a) No transaction were running, we can jump to consistent.
+ * a) Either no transaction were running or we've been tracking running
+ * transactions and the new snapshot has them all finished, we can
+ * jump to consistent.
*
- * NB: We might have already started to incrementally assemble a snapshot,
- * so we need to be careful to deal with that.
+ * NB: Since we might have already started to incrementally assemble a
+ * snapshot, we need to be careful to deal with that.
*/
- if (running->xcnt == 0)
+ if (running->xcnt == 0 ||
+ (builder->running.xcnt > 0 &&
+ running->oldestRunningXid > builder->running.xmax))
{
+
if (builder->start_decoding_at == InvalidXLogRecPtr ||
builder->start_decoding_at <= lsn)
/* can decode everything after this */
@@ -1278,10 +1285,16 @@ SnapBuildFindSnapshot(SnapBuild *builder, XLogRecPtr lsn, xl_running_xacts *runn
builder->state = SNAPBUILD_CONSISTENT;
+ /*
+ * Give different log detail based on actual state for easier
+ * debugging.
+ */
ereport(LOG,
(errmsg("logical decoding found consistent point at %X/%X",
(uint32) (lsn >> 32), (uint32) lsn),
- errdetail("There are no running transactions.")));
+ errdetail(running->xcnt == 0 ?
+ "There are no running transactions." :
+ "All running transactions have finished.")));
return false;
}
--
2.7.4