Skip to content

Commit 766908f

Browse files
committed
age_global_graph: stabilize regression tests
age_global_graph: stabilize regression tests under concurrent xid load Wrap both vertex_stats() context-building phases in a single BEGIN ISOLATION LEVEL REPEATABLE READ; ... COMMIT; transaction so the three calls share one snapshot. This prevents the snapshot-fallback path in is_ggctx_invalid() from purging an already-built graph context when concurrent xid activity (autovacuum, parallel installcheck, replication, shared CI) advances the snapshot between calls, which would otherwise make the targeted delete_global_graphs(name) checks return false instead of the expected true. Read Committed is insufficient because it acquires a fresh snapshot per statement; REPEATABLE READ pins one snapshot for the whole transaction. Also add explicit ORDER BY id to the three direct-SQL label-table SELECTs (_ag_label_vertex x2, _ag_label_edge) that return multiple rows, so their output no longer depends on heap scan order. This is a test-only change (regress/sql/age_global_graph.sql and regress/expected/age_global_graph.out); no extension C code or SQL is modified. All 37 regression tests pass (installcheck) on PostgreSQL 18.3. Co-authored-by: GitHub Copilot <noreply@github.com> modified: regress/expected/age_global_graph.out modified: regress/sql/age_global_graph.sql
1 parent 14732bf commit 766908f

2 files changed

Lines changed: 32 additions & 6 deletions

File tree

regress/expected/age_global_graph.out

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ SELECT * FROM cypher('ag_graph_3', $$ CREATE (v:vertex3) RETURN v $$) AS (v agt
4444
(1 row)
4545

4646
-- load contexts using the vertex_stats command
47+
-- Build all three graph contexts under one snapshot. The vertex_stats()
48+
-- calls are wrapped in a single REPEATABLE READ transaction so they share
49+
-- one snapshot; this keeps the snapshot-fallback path in is_ggctx_invalid()
50+
-- from purging an already-built context when concurrent xid activity
51+
-- (autovacuum, parallel installcheck, replication) advances the snapshot
52+
-- between calls. Read Committed is insufficient: it takes a fresh snapshot
53+
-- per statement.
54+
BEGIN ISOLATION LEVEL REPEATABLE READ;
4755
SELECT * FROM cypher('ag_graph_3', $$ MATCH (u) RETURN vertex_stats(u) ORDER BY id(u) $$) AS (result agtype);
4856
result
4957
-----------------------------------------------------------------------------------------------
@@ -62,6 +70,7 @@ SELECT * FROM cypher('ag_graph_1', $$ MATCH (u) RETURN vertex_stats(u) ORDER BY
6270
{"id": 844424930131969, "label": "vertex1", "in_degree": 0, "out_degree": 0, "self_loops": 0}
6371
(1 row)
6472

73+
COMMIT;
6574
--- loading undefined contexts
6675
--- should throw exception - graph "ag_graph_4" does not exist
6776
SELECT * FROM cypher('ag_graph_4', $$ MATCH (u) RETURN vertex_stats(u) ORDER BY id(u) $$) AS (result agtype);
@@ -130,6 +139,9 @@ LINE 1: SELECT * FROM cypher('ag_graph_4', $$ RETURN delete_global_g...
130139
-- delete_GRAPH_global_contexts
131140
--
132141
-- load contexts again
142+
-- Same REPEATABLE READ wrap as the first build phase above, for the same
143+
-- snapshot-stability reason.
144+
BEGIN ISOLATION LEVEL REPEATABLE READ;
133145
SELECT * FROM cypher('ag_graph_3', $$ MATCH (u) RETURN vertex_stats(u) ORDER BY id(u) $$) AS (result agtype);
134146
result
135147
-----------------------------------------------------------------------------------------------
@@ -148,6 +160,7 @@ SELECT * FROM cypher('ag_graph_1', $$ MATCH (u) RETURN vertex_stats(u) ORDER BY
148160
{"id": 844424930131969, "label": "vertex1", "in_degree": 0, "out_degree": 0, "self_loops": 0}
149161
(1 row)
150162

163+
COMMIT;
151164
-- delete all graph contexts
152165
-- should return true
153166
SELECT * FROM cypher('ag_graph_1', $$ RETURN delete_global_graphs(NULL) $$) AS (result agtype);
@@ -306,7 +319,7 @@ SELECT * FROM cypher('ag_graph_1', $$ RETURN graph_stats('ag_graph_1') $$) AS (r
306319
(1 row)
307320

308321
-- remove some vertices
309-
SELECT * FROM ag_graph_1._ag_label_vertex;
322+
SELECT * FROM ag_graph_1._ag_label_vertex ORDER BY id;
310323
id | properties
311324
-----------------+--------------------------------------
312325
281474976710657 | {}
@@ -325,7 +338,7 @@ SELECT * FROM ag_graph_1._ag_label_vertex;
325338
DELETE FROM ag_graph_1._ag_label_vertex WHERE id::text = '281474976710661';
326339
DELETE FROM ag_graph_1._ag_label_vertex WHERE id::text = '281474976710662';
327340
DELETE FROM ag_graph_1._ag_label_vertex WHERE id::text = '281474976710664';
328-
SELECT * FROM ag_graph_1._ag_label_vertex;
341+
SELECT * FROM ag_graph_1._ag_label_vertex ORDER BY id;
329342
id | properties
330343
-----------------+--------------------------------------
331344
281474976710657 | {}
@@ -338,7 +351,7 @@ SELECT * FROM ag_graph_1._ag_label_vertex;
338351
844424930131969 | {}
339352
(8 rows)
340353

341-
SELECT * FROM ag_graph_1._ag_label_edge;
354+
SELECT * FROM ag_graph_1._ag_label_edge ORDER BY id;
342355
id | start_id | end_id | properties
343356
------------------+-----------------+-----------------+------------
344357
1125899906842625 | 281474976710659 | 281474976710660 | {}

regress/sql/age_global_graph.sql

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,18 @@ SELECT * FROM create_graph('ag_graph_3');
1616
SELECT * FROM cypher('ag_graph_3', $$ CREATE (v:vertex3) RETURN v $$) AS (v agtype);
1717

1818
-- load contexts using the vertex_stats command
19+
-- Build all three graph contexts under one snapshot. The vertex_stats()
20+
-- calls are wrapped in a single REPEATABLE READ transaction so they share
21+
-- one snapshot; this keeps the snapshot-fallback path in is_ggctx_invalid()
22+
-- from purging an already-built context when concurrent xid activity
23+
-- (autovacuum, parallel installcheck, replication) advances the snapshot
24+
-- between calls. Read Committed is insufficient: it takes a fresh snapshot
25+
-- per statement.
26+
BEGIN ISOLATION LEVEL REPEATABLE READ;
1927
SELECT * FROM cypher('ag_graph_3', $$ MATCH (u) RETURN vertex_stats(u) ORDER BY id(u) $$) AS (result agtype);
2028
SELECT * FROM cypher('ag_graph_2', $$ MATCH (u) RETURN vertex_stats(u) ORDER BY id(u) $$) AS (result agtype);
2129
SELECT * FROM cypher('ag_graph_1', $$ MATCH (u) RETURN vertex_stats(u) ORDER BY id(u) $$) AS (result agtype);
30+
COMMIT;
2231

2332
--- loading undefined contexts
2433
--- should throw exception - graph "ag_graph_4" does not exist
@@ -55,9 +64,13 @@ SELECT * FROM cypher('ag_graph_4', $$ RETURN delete_global_graphs('ag_graph_4')
5564
--
5665

5766
-- load contexts again
67+
-- Same REPEATABLE READ wrap as the first build phase above, for the same
68+
-- snapshot-stability reason.
69+
BEGIN ISOLATION LEVEL REPEATABLE READ;
5870
SELECT * FROM cypher('ag_graph_3', $$ MATCH (u) RETURN vertex_stats(u) ORDER BY id(u) $$) AS (result agtype);
5971
SELECT * FROM cypher('ag_graph_2', $$ MATCH (u) RETURN vertex_stats(u) ORDER BY id(u) $$) AS (result agtype);
6072
SELECT * FROM cypher('ag_graph_1', $$ MATCH (u) RETURN vertex_stats(u) ORDER BY id(u) $$) AS (result agtype);
73+
COMMIT;
6174

6275
-- delete all graph contexts
6376
-- should return true
@@ -115,12 +128,12 @@ SELECT * FROM cypher('ag_graph_1', $$ MATCH (u)-[e]->(v) RETURN u, e, v ORDER BY
115128
-- what is there now?
116129
SELECT * FROM cypher('ag_graph_1', $$ RETURN graph_stats('ag_graph_1') $$) AS (result agtype);
117130
-- remove some vertices
118-
SELECT * FROM ag_graph_1._ag_label_vertex;
131+
SELECT * FROM ag_graph_1._ag_label_vertex ORDER BY id;
119132
DELETE FROM ag_graph_1._ag_label_vertex WHERE id::text = '281474976710661';
120133
DELETE FROM ag_graph_1._ag_label_vertex WHERE id::text = '281474976710662';
121134
DELETE FROM ag_graph_1._ag_label_vertex WHERE id::text = '281474976710664';
122-
SELECT * FROM ag_graph_1._ag_label_vertex;
123-
SELECT * FROM ag_graph_1._ag_label_edge;
135+
SELECT * FROM ag_graph_1._ag_label_vertex ORDER BY id;
136+
SELECT * FROM ag_graph_1._ag_label_edge ORDER BY id;
124137
-- The graph_stats query below will produce warnings for the dangling edges
125138
-- created by the DELETE commands above. The warnings appear in nondeterministic
126139
-- order because they come from iterating edge label tables (knows, stalks),

0 commit comments

Comments
 (0)