From 86398ad4cc09d6dba79d43650a7d0ba0cdfdc069 Mon Sep 17 00:00:00 2001 From: Amit Kapila Date: Mon, 14 Sep 2020 16:11:02 +0530 Subject: [PATCH v1] Fix initialization of RelationSyncEntry for streaming transactions. In commit 464824323e, for each RelationSyncEntry we maintained the list of xids (streamed_txns) for which we have already sent the schema. This helps us to track when to send the schema to the downstream node for replication of streaming transactions. Before this list got initialized, we were processing invalidation messages which access this list and led to an assertion failure. In passing initialize the list of xids with NIL instead of NULL which is our usual coding practise. --- src/backend/replication/pgoutput/pgoutput.c | 24 ++++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/backend/replication/pgoutput/pgoutput.c b/src/backend/replication/pgoutput/pgoutput.c index c29c088813..c4d8c32624 100644 --- a/src/backend/replication/pgoutput/pgoutput.c +++ b/src/backend/replication/pgoutput/pgoutput.c @@ -956,10 +956,24 @@ get_rel_sync_entry(PGOutputData *data, Oid relid) /* Not found means schema wasn't sent */ if (!found || !entry->replicate_valid) { - List *pubids = GetRelationPublications(relid); + List *pubids; ListCell *lc; Oid publish_as_relid = relid; + /* + * Initialize schema sent information before trying to open/lock any + * relation. We want to avoid processing invalidation messages because + * that can try to access this information. See + * rel_sync_cache_relation_cb. + */ + if (!found) + { + entry->schema_sent = false; + entry->streamed_txns = NIL; + } + + pubids = GetRelationPublications(relid); + /* Reload publications if needed before use. */ if (!publications_valid) { @@ -1054,12 +1068,6 @@ get_rel_sync_entry(PGOutputData *data, Oid relid) entry->replicate_valid = true; } - if (!found) - { - entry->schema_sent = false; - entry->streamed_txns = NULL; - } - return entry; } @@ -1145,7 +1153,7 @@ rel_sync_cache_relation_cb(Datum arg, Oid relid) { entry->schema_sent = false; list_free(entry->streamed_txns); - entry->streamed_txns = NULL; + entry->streamed_txns = NIL; } } -- 2.28.0.windows.1