From ca52be5d9f2c6299b6fe956c286529a4a058ae48 Mon Sep 17 00:00:00 2001 From: Will Donnelly Date: Fri, 28 Feb 2025 12:42:24 -0600 Subject: [PATCH] Revert "source-postgres-batch: Fix XID wraparound behavior" This reverts commit e57acbcb75aed8f74b15ff6cfeeb9ed3e200f981 and un-fixes https://github.com/estuary/connectors/issues/2383 Turns out the particular function we're using here doesn't work on a standby replica, which is...bad. --- .../.snapshots/TestQueryTemplates-XMinFirstQuery | 5 +---- .../.snapshots/TestQueryTemplates-XMinSubsequentQuery | 4 +--- source-postgres-batch/main.go | 9 ++------- 3 files changed, 4 insertions(+), 14 deletions(-) diff --git a/source-postgres-batch/.snapshots/TestQueryTemplates-XMinFirstQuery b/source-postgres-batch/.snapshots/TestQueryTemplates-XMinFirstQuery index 2cd1fdfbc..3ca9f026a 100644 --- a/source-postgres-batch/.snapshots/TestQueryTemplates-XMinFirstQuery +++ b/source-postgres-batch/.snapshots/TestQueryTemplates-XMinFirstQuery @@ -1,4 +1 @@ -SELECT xmin AS txid, * FROM "test"."foobar" - WHERE xmin::text::bigint >= 3 - AND (((txid_current() - xmin::text::bigint)<<32)>>32) >= 0 - ORDER BY xmin::text::bigint; +SELECT xmin AS txid, * FROM "test"."foobar" ORDER BY xmin::text::bigint; diff --git a/source-postgres-batch/.snapshots/TestQueryTemplates-XMinSubsequentQuery b/source-postgres-batch/.snapshots/TestQueryTemplates-XMinSubsequentQuery index 4c14f032a..4ebb510fb 100644 --- a/source-postgres-batch/.snapshots/TestQueryTemplates-XMinSubsequentQuery +++ b/source-postgres-batch/.snapshots/TestQueryTemplates-XMinSubsequentQuery @@ -1,5 +1,3 @@ SELECT xmin AS txid, * FROM "test"."foobar" - WHERE xmin::text::bigint >= 3 - AND (((txid_current() - xmin::text::bigint)<<32)>>32) >= 0 - AND (((xmin::text::bigint - $1::bigint)<<32)>>32) > 0 + WHERE (((xmin::text::bigint - $1::bigint)<<32)>>32) > 0 AND xmin::text::bigint >= 3 ORDER BY (((xmin::text::bigint - $1::bigint)<<32)>>32); diff --git a/source-postgres-batch/main.go b/source-postgres-batch/main.go index 3cbd049ef..fbebe5640 100644 --- a/source-postgres-batch/main.go +++ b/source-postgres-batch/main.go @@ -168,15 +168,10 @@ func selectQueryTemplate(res *Resource) (string, error) { // the XID epoch wraps around. If this assumption is violated it would in principle be doable // to `SELECT txid_current() as polled_txid, ...` and use "polled_txid" as the cursor value. const tableQueryTemplateXMIN = `{{if .IsFirstQuery -}} - SELECT xmin AS txid, * FROM {{quoteTableName .SchemaName .TableName}} - WHERE xmin::text::bigint >= 3 - AND (((txid_current() - xmin::text::bigint)<<32)>>32) >= 0 - ORDER BY xmin::text::bigint; + SELECT xmin AS txid, * FROM {{quoteTableName .SchemaName .TableName}} ORDER BY xmin::text::bigint; {{- else -}} SELECT xmin AS txid, * FROM {{quoteTableName .SchemaName .TableName}} - WHERE xmin::text::bigint >= 3 - AND (((txid_current() - xmin::text::bigint)<<32)>>32) >= 0 - AND (((xmin::text::bigint - $1::bigint)<<32)>>32) > 0 + WHERE (((xmin::text::bigint - $1::bigint)<<32)>>32) > 0 AND xmin::text::bigint >= 3 ORDER BY (((xmin::text::bigint - $1::bigint)<<32)>>32); {{- end}}`