Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f10a025

Browse files
committed
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/202205130830.g5ntonhztspb@alvherre.pgsql Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
1 parent 55f4802 commit f10a025

File tree

5 files changed

+70
-12
lines changed

5 files changed

+70
-12
lines changed

src/backend/nodes/list.c

+41-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#define IsPointerList(l) ((l) == NIL || IsA((l), List))
5555
#define IsIntegerList(l) ((l) == NIL || IsA((l), IntList))
5656
#define IsOidList(l) ((l) == NIL || IsA((l), OidList))
57+
#define IsXidList(l) ((l) == NIL || IsA((l), XidList))
5758

5859
#ifdef USE_ASSERT_CHECKING
5960
/*
@@ -71,7 +72,8 @@ check_list_invariants(const List *list)
7172

7273
Assert(list->type == T_List ||
7374
list->type == T_IntList ||
74-
list->type == T_OidList);
75+
list->type == T_OidList ||
76+
list->type == T_XidList);
7577
}
7678
#else
7779
#define check_list_invariants(l) ((void) 0)
@@ -383,6 +385,24 @@ lappend_oid(List *list, Oid datum)
383385
return list;
384386
}
385387

388+
/*
389+
* Append a TransactionId to the specified list. See lappend()
390+
*/
391+
List *
392+
lappend_xid(List *list, TransactionId datum)
393+
{
394+
Assert(IsXidList(list));
395+
396+
if (list == NIL)
397+
list = new_list(T_XidList, 1);
398+
else
399+
new_tail_cell(list);
400+
401+
llast_xid(list) = datum;
402+
check_list_invariants(list);
403+
return list;
404+
}
405+
386406
/*
387407
* Make room for a new cell at position 'pos' (measured from 0).
388408
* The data in the cell is left undefined, and must be filled in by the
@@ -714,6 +734,26 @@ list_member_oid(const List *list, Oid datum)
714734
return false;
715735
}
716736

737+
/*
738+
* Return true iff the TransactionId 'datum' is a member of the list.
739+
*/
740+
bool
741+
list_member_xid(const List *list, TransactionId datum)
742+
{
743+
const ListCell *cell;
744+
745+
Assert(IsXidList(list));
746+
check_list_invariants(list);
747+
748+
foreach(cell, list)
749+
{
750+
if (lfirst_oid(cell) == datum)
751+
return true;
752+
}
753+
754+
return false;
755+
}
756+
717757
/*
718758
* Delete the n'th cell (counting from 0) in list.
719759
*

src/backend/nodes/outfuncs.c

+4
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ _outList(StringInfo str, const List *node)
221221
appendStringInfoChar(str, 'i');
222222
else if (IsA(node, OidList))
223223
appendStringInfoChar(str, 'o');
224+
else if (IsA(node, XidList))
225+
appendStringInfoChar(str, 'x');
224226

225227
foreach(lc, node)
226228
{
@@ -239,6 +241,8 @@ _outList(StringInfo str, const List *node)
239241
appendStringInfo(str, " %d", lfirst_int(lc));
240242
else if (IsA(node, OidList))
241243
appendStringInfo(str, " %u", lfirst_oid(lc));
244+
else if (IsA(node, XidList))
245+
appendStringInfo(str, " %u", lfirst_xid(lc));
242246
else
243247
elog(ERROR, "unrecognized list node type: %d",
244248
(int) node->type);

src/backend/replication/pgoutput/pgoutput.c

+3-11
Original file line numberDiff line numberDiff line change
@@ -1923,15 +1923,7 @@ init_rel_sync_cache(MemoryContext cachectx)
19231923
static bool
19241924
get_schema_sent_in_streamed_txn(RelationSyncEntry *entry, TransactionId xid)
19251925
{
1926-
ListCell *lc;
1927-
1928-
foreach(lc, entry->streamed_txns)
1929-
{
1930-
if (xid == (uint32) lfirst_int(lc))
1931-
return true;
1932-
}
1933-
1934-
return false;
1926+
return list_member_xid(entry->streamed_txns, xid);
19351927
}
19361928

19371929
/*
@@ -1945,7 +1937,7 @@ set_schema_sent_in_streamed_txn(RelationSyncEntry *entry, TransactionId xid)
19451937

19461938
oldctx = MemoryContextSwitchTo(CacheMemoryContext);
19471939

1948-
entry->streamed_txns = lappend_int(entry->streamed_txns, xid);
1940+
entry->streamed_txns = lappend_xid(entry->streamed_txns, xid);
19491941

19501942
MemoryContextSwitchTo(oldctx);
19511943
}
@@ -2248,7 +2240,7 @@ cleanup_rel_sync_cache(TransactionId xid, bool is_commit)
22482240
*/
22492241
foreach(lc, entry->streamed_txns)
22502242
{
2251-
if (xid == (uint32) lfirst_int(lc))
2243+
if (xid == lfirst_xid(lc))
22522244
{
22532245
if (is_commit)
22542246
entry->schema_sent = true;

src/include/nodes/nodes.h

+1
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ typedef enum NodeTag
317317
T_List,
318318
T_IntList,
319319
T_OidList,
320+
T_XidList,
320321

321322
/*
322323
* TAGS FOR EXTENSIBLE NODES (extensible.h)

src/include/nodes/pg_list.h

+21
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ typedef union ListCell
4545
void *ptr_value;
4646
int int_value;
4747
Oid oid_value;
48+
TransactionId xid_value;
4849
} ListCell;
4950

5051
typedef struct List
@@ -169,6 +170,7 @@ list_length(const List *l)
169170
#define lfirst(lc) ((lc)->ptr_value)
170171
#define lfirst_int(lc) ((lc)->int_value)
171172
#define lfirst_oid(lc) ((lc)->oid_value)
173+
#define lfirst_xid(lc) ((lc)->xid_value)
172174
#define lfirst_node(type,lc) castNode(type, lfirst(lc))
173175

174176
#define linitial(l) lfirst(list_nth_cell(l, 0))
@@ -194,6 +196,7 @@ list_length(const List *l)
194196
#define llast(l) lfirst(list_last_cell(l))
195197
#define llast_int(l) lfirst_int(list_last_cell(l))
196198
#define llast_oid(l) lfirst_oid(list_last_cell(l))
199+
#define llast_xid(l) lfirst_xid(list_last_cell(l))
197200
#define llast_node(type,l) castNode(type, llast(l))
198201

199202
/*
@@ -202,6 +205,7 @@ list_length(const List *l)
202205
#define list_make_ptr_cell(v) ((ListCell) {.ptr_value = (v)})
203206
#define list_make_int_cell(v) ((ListCell) {.int_value = (v)})
204207
#define list_make_oid_cell(v) ((ListCell) {.oid_value = (v)})
208+
#define list_make_xid_cell(v) ((ListCell) {.xid_value = (v)})
205209

206210
#define list_make1(x1) \
207211
list_make1_impl(T_List, list_make_ptr_cell(x1))
@@ -248,6 +252,21 @@ list_length(const List *l)
248252
list_make_oid_cell(x3), list_make_oid_cell(x4), \
249253
list_make_oid_cell(x5))
250254

255+
#define list_make1_xid(x1) \
256+
list_make1_impl(T_XidList, list_make_xid_cell(x1))
257+
#define list_make2_xid(x1,x2) \
258+
list_make2_impl(T_XidList, list_make_xid_cell(x1), list_make_xid_cell(x2))
259+
#define list_make3_xid(x1,x2,x3) \
260+
list_make3_impl(T_XidList, list_make_xid_cell(x1), list_make_xid_cell(x2), \
261+
list_make_xid_cell(x3))
262+
#define list_make4_xid(x1,x2,x3,x4) \
263+
list_make4_impl(T_XidList, list_make_xid_cell(x1), list_make_xid_cell(x2), \
264+
list_make_xid_cell(x3), list_make_xid_cell(x4))
265+
#define list_make5_xid(x1,x2,x3,x4,x5) \
266+
list_make5_impl(T_XidList, list_make_xid_cell(x1), list_make_xid_cell(x2), \
267+
list_make_xid_cell(x3), list_make_xid_cell(x4), \
268+
list_make_xid_cell(x5))
269+
251270
/*
252271
* Locate the n'th cell (counting from 0) of the list.
253272
* It is an assertion failure if there is no such cell.
@@ -539,6 +558,7 @@ extern List *list_make5_impl(NodeTag t, ListCell datum1, ListCell datum2,
539558
extern pg_nodiscard List *lappend(List *list, void *datum);
540559
extern pg_nodiscard List *lappend_int(List *list, int datum);
541560
extern pg_nodiscard List *lappend_oid(List *list, Oid datum);
561+
extern pg_nodiscard List *lappend_xid(List *list, TransactionId datum);
542562

543563
extern pg_nodiscard List *list_insert_nth(List *list, int pos, void *datum);
544564
extern pg_nodiscard List *list_insert_nth_int(List *list, int pos, int datum);
@@ -557,6 +577,7 @@ extern bool list_member(const List *list, const void *datum);
557577
extern bool list_member_ptr(const List *list, const void *datum);
558578
extern bool list_member_int(const List *list, int datum);
559579
extern bool list_member_oid(const List *list, Oid datum);
580+
extern bool list_member_xid(const List *list, TransactionId datum);
560581

561582
extern pg_nodiscard List *list_delete(List *list, void *datum);
562583
extern pg_nodiscard List *list_delete_ptr(List *list, void *datum);

0 commit comments

Comments
 (0)