summaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
authorAlvaro Herrera2022-07-04 12:52:12 +0000
committerAlvaro Herrera2022-07-04 12:52:12 +0000
commitf10a025cfe97c1a341f636368e67af5ca644c5d8 (patch)
tree54e24a8088feaec1b65fba755a7329f18a5f0687 /src/backend
parent55f4802785f66a584c05dca40e5d9b25491674b2 (diff)
Implement List support for TransactionId
Use it for RelationSyncEntry->streamed_txns, which is currently using an integer list. The API support is not complete, not because it is hard to write but because it's unclear that it's worth the code space, there being so little use of XID lists. Discussion: https://postgr.es/m/[email protected] Reviewed-by: Amit Kapila <[email protected]>
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/nodes/list.c42
-rw-r--r--src/backend/nodes/outfuncs.c4
-rw-r--r--src/backend/replication/pgoutput/pgoutput.c14
3 files changed, 48 insertions, 12 deletions
diff --git a/src/backend/nodes/list.c b/src/backend/nodes/list.c
index f843f861ef8..9d8f4fd5c7c 100644
--- a/src/backend/nodes/list.c
+++ b/src/backend/nodes/list.c
@@ -54,6 +54,7 @@
#define IsPointerList(l) ((l) == NIL || IsA((l), List))
#define IsIntegerList(l) ((l) == NIL || IsA((l), IntList))
#define IsOidList(l) ((l) == NIL || IsA((l), OidList))
+#define IsXidList(l) ((l) == NIL || IsA((l), XidList))
#ifdef USE_ASSERT_CHECKING
/*
@@ -71,7 +72,8 @@ check_list_invariants(const List *list)
Assert(list->type == T_List ||
list->type == T_IntList ||
- list->type == T_OidList);
+ list->type == T_OidList ||
+ list->type == T_XidList);
}
#else
#define check_list_invariants(l) ((void) 0)
@@ -384,6 +386,24 @@ lappend_oid(List *list, Oid datum)
}
/*
+ * Append a TransactionId to the specified list. See lappend()
+ */
+List *
+lappend_xid(List *list, TransactionId datum)
+{
+ Assert(IsXidList(list));
+
+ if (list == NIL)
+ list = new_list(T_XidList, 1);
+ else
+ new_tail_cell(list);
+
+ llast_xid(list) = datum;
+ check_list_invariants(list);
+ return list;
+}
+
+/*
* Make room for a new cell at position 'pos' (measured from 0).
* The data in the cell is left undefined, and must be filled in by the
* caller. 'list' is assumed to be non-NIL, and 'pos' must be a valid
@@ -715,6 +735,26 @@ list_member_oid(const List *list, Oid datum)
}
/*
+ * Return true iff the TransactionId 'datum' is a member of the list.
+ */
+bool
+list_member_xid(const List *list, TransactionId datum)
+{
+ const ListCell *cell;
+
+ Assert(IsXidList(list));
+ check_list_invariants(list);
+
+ foreach(cell, list)
+ {
+ if (lfirst_oid(cell) == datum)
+ return true;
+ }
+
+ return false;
+}
+
+/*
* Delete the n'th cell (counting from 0) in list.
*
* The List is pfree'd if this was the last member.
diff --git a/src/backend/nodes/outfuncs.c b/src/backend/nodes/outfuncs.c
index ce129155925..4315c530804 100644
--- a/src/backend/nodes/outfuncs.c
+++ b/src/backend/nodes/outfuncs.c
@@ -221,6 +221,8 @@ _outList(StringInfo str, const List *node)
appendStringInfoChar(str, 'i');
else if (IsA(node, OidList))
appendStringInfoChar(str, 'o');
+ else if (IsA(node, XidList))
+ appendStringInfoChar(str, 'x');
foreach(lc, node)
{
@@ -239,6 +241,8 @@ _outList(StringInfo str, const List *node)
appendStringInfo(str, " %d", lfirst_int(lc));
else if (IsA(node, OidList))
appendStringInfo(str, " %u", lfirst_oid(lc));
+ else if (IsA(node, XidList))
+ appendStringInfo(str, " %u", lfirst_xid(lc));
else
elog(ERROR, "unrecognized list node type: %d",
(int) node->type);
diff --git a/src/backend/replication/pgoutput/pgoutput.c b/src/backend/replication/pgoutput/pgoutput.c
index 8deae571433..2cbca4a0870 100644
--- a/src/backend/replication/pgoutput/pgoutput.c
+++ b/src/backend/replication/pgoutput/pgoutput.c
@@ -1923,15 +1923,7 @@ init_rel_sync_cache(MemoryContext cachectx)
static bool
get_schema_sent_in_streamed_txn(RelationSyncEntry *entry, TransactionId xid)
{
- ListCell *lc;
-
- foreach(lc, entry->streamed_txns)
- {
- if (xid == (uint32) lfirst_int(lc))
- return true;
- }
-
- return false;
+ return list_member_xid(entry->streamed_txns, xid);
}
/*
@@ -1945,7 +1937,7 @@ set_schema_sent_in_streamed_txn(RelationSyncEntry *entry, TransactionId xid)
oldctx = MemoryContextSwitchTo(CacheMemoryContext);
- entry->streamed_txns = lappend_int(entry->streamed_txns, xid);
+ entry->streamed_txns = lappend_xid(entry->streamed_txns, xid);
MemoryContextSwitchTo(oldctx);
}
@@ -2248,7 +2240,7 @@ cleanup_rel_sync_cache(TransactionId xid, bool is_commit)
*/
foreach(lc, entry->streamed_txns)
{
- if (xid == (uint32) lfirst_int(lc))
+ if (xid == lfirst_xid(lc))
{
if (is_commit)
entry->schema_sent = true;