Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita49927f

Browse files
pg_logicalinspect: Stabilize isolation tests.
The previous isolation tests did not account for the possibility thatthe background writer or the checkpointer could write a RUNNING_XACTSrecord, which could cause logical decoding to produce more logicalsnapshots than expected.This commit modifies the isolation tests to verify that at least onelogical snapshot contains the expected number of committed or ongoingcatalog-change transactions.Per buildfarm member skink.Reported-by: Andres Freund <andres@anarazel.de>Author: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com>Discussion:https://postgr.es/m/5qbxud4pvnvmtuoi7weiizm5hmumxaeohx4vztfhrwlfhyz6rj@buh4435mllwo
1 parent8b1b342 commita49927f

File tree

2 files changed

+30
-38
lines changed

2 files changed

+30
-38
lines changed
Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Parsed test spec with 2 sessions
22

3-
starting permutation: s0_init s0_begin s0_savepoint s0_truncates1_checkpoint s1_get_changes s0_commit s0_begin s0_inserts1_checkpoint s1_get_changess0_commit s1_get_changes s1_get_logical_snapshot_info s1_get_logical_snapshot_meta
3+
starting permutation: s0_init s0_begin s0_savepoint s0_truncates1_create_tables1_checkpoint s1_get_changess1_check_snapshot_info s1_check_snapshot_meta s0_commit
44
step s0_init: SELECT 'init' FROM pg_create_logical_replication_slot('isolation_slot', 'test_decoding');
55
?column?
66
--------
@@ -10,43 +10,23 @@ init
1010
step s0_begin: BEGIN;
1111
step s0_savepoint: SAVEPOINT sp1;
1212
step s0_truncate: TRUNCATE tbl1;
13+
step s1_create_table: CREATE TABLE tbl2 (val1 integer, val2 integer);
1314
step s1_checkpoint: CHECKPOINT;
1415
step s1_get_changes: SELECT data FROM pg_logical_slot_get_changes('isolation_slot', NULL, NULL, 'skip-empty-xacts', '1', 'include-xids', '0');
1516
data
1617
----
1718
(0 rows)
1819

19-
step s0_commit: COMMIT;
20-
step s0_begin: BEGIN;
21-
step s0_insert: INSERT INTO tbl1 VALUES (1);
22-
step s1_checkpoint: CHECKPOINT;
23-
step s1_get_changes: SELECT data FROM pg_logical_slot_get_changes('isolation_slot', NULL, NULL, 'skip-empty-xacts', '1', 'include-xids', '0');
24-
data
25-
---------------------------------------
26-
BEGIN
27-
table public.tbl1: TRUNCATE: (no-flags)
28-
COMMIT
29-
(3 rows)
30-
31-
step s0_commit: COMMIT;
32-
step s1_get_changes: SELECT data FROM pg_logical_slot_get_changes('isolation_slot', NULL, NULL, 'skip-empty-xacts', '1', 'include-xids', '0');
33-
data
34-
-------------------------------------------------------------
35-
BEGIN
36-
table public.tbl1: INSERT: val1[integer]:1 val2[integer]:null
37-
COMMIT
38-
(3 rows)
39-
40-
step s1_get_logical_snapshot_info: SELECT info.state, info.catchange_count, array_length(info.catchange_xip,1) AS catchange_array_length, info.committed_count, array_length(info.committed_xip,1) AS committed_array_length FROM pg_ls_logicalsnapdir(), pg_get_logical_snapshot_info(name) AS info ORDER BY 2;
41-
state |catchange_count|catchange_array_length|committed_count|committed_array_length
42-
----------+---------------+----------------------+---------------+----------------------
43-
consistent| 0| | 2| 2
44-
consistent| 2| 2| 0|
45-
(2 rows)
20+
step s1_check_snapshot_info: SELECT count(*) > 0 as has_info FROM pg_ls_logicalsnapdir(), pg_get_logical_snapshot_info(name) AS info where info.catchange_count >= 2 and array_length(info.catchange_xip,1) >= 2 and info.committed_count >= 1 and array_length(info.committed_xip,1) >= 1;
21+
has_info
22+
--------
23+
t
24+
(1 row)
4625

47-
steps1_get_logical_snapshot_meta: SELECTCOUNT(meta.*) from pg_ls_logicalsnapdir(), pg_get_logical_snapshot_meta(name) as meta;
48-
count
49-
-----
50-
2
26+
steps1_check_snapshot_meta: SELECTcount(meta.*) > 0 AS has_meta from pg_ls_logicalsnapdir(), pg_get_logical_snapshot_meta(name) as meta;
27+
has_meta
28+
--------
29+
t
5130
(1 row)
5231

32+
step s0_commit: COMMIT;
Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
# Test the pg_logicalinspect functions: that needs some permutation to
2-
# ensure that we are creatingmultiple logical snapshots and thatone of them
3-
#contains ongoing catalogs changes.
2+
# ensure that we are creatingat least one snapshot thatcontains ongoing and
3+
#committed catalogs changes.
44
setup
55
{
66
DROPTABLEIFEXISTStbl1;
7+
DROPTABLEIFEXISTStbl2;
78
CREATETABLEtbl1 (val1integer,val2integer);
89
CREATEEXTENSIONpg_logicalinspect;
910
}
1011

1112
teardown
1213
{
1314
DROPTABLEtbl1;
15+
DROPTABLEtbl2;
1416
SELECT'stop'FROMpg_drop_replication_slot('isolation_slot');
1517
DROPEXTENSIONpg_logicalinspect;
1618
}
@@ -21,14 +23,24 @@ step "s0_init" { SELECT 'init' FROM pg_create_logical_replication_slot('isolatio
2123
step"s0_begin" {BEGIN; }
2224
step"s0_savepoint" {SAVEPOINTsp1; }
2325
step"s0_truncate" {TRUNCATEtbl1; }
24-
step"s0_insert" {INSERTINTOtbl1VALUES (1); }
2526
step"s0_commit" {COMMIT; }
2627

2728
session"s1"
2829
setup {SETsynchronous_commit=on; }
2930
step"s1_checkpoint" {CHECKPOINT; }
31+
step"s1_create_table" {CREATETABLEtbl2 (val1integer,val2integer); }
3032
step"s1_get_changes" {SELECTdataFROMpg_logical_slot_get_changes('isolation_slot',NULL,NULL,'skip-empty-xacts','1','include-xids','0'); }
31-
step"s1_get_logical_snapshot_meta" {SELECTCOUNT(meta.*)frompg_ls_logicalsnapdir(),pg_get_logical_snapshot_meta(name)asmeta;}
32-
step"s1_get_logical_snapshot_info" {SELECTinfo.state,info.catchange_count,array_length(info.catchange_xip,1)AScatchange_array_length,info.committed_count,array_length(info.committed_xip,1)AScommitted_array_lengthFROMpg_ls_logicalsnapdir(),pg_get_logical_snapshot_info(name)ASinfoORDERBY2; }
33+
step"s1_check_snapshot_meta" {SELECTcount(meta.*)>0AShas_metafrompg_ls_logicalsnapdir(),pg_get_logical_snapshot_meta(name)asmeta;}
34+
step"s1_check_snapshot_info" {SELECTcount(*)>0ashas_infoFROMpg_ls_logicalsnapdir(),pg_get_logical_snapshot_info(name)ASinfowhereinfo.catchange_count>=2andarray_length(info.catchange_xip,1)>=2andinfo.committed_count>=1andarray_length(info.committed_xip,1)>=1; }
3335

34-
permutation"s0_init""s0_begin""s0_savepoint""s0_truncate""s1_checkpoint""s1_get_changes""s0_commit""s0_begin""s0_insert""s1_checkpoint""s1_get_changes""s0_commit""s1_get_changes""s1_get_logical_snapshot_info""s1_get_logical_snapshot_meta"
36+
37+
# Both s0 and s1 execute catalog-change transactions. When "s1_get_changes" is
38+
# executed, s0's transaction is still in progress, while s1's transaction has
39+
# already completed. Consequently, the logical decoding produces a snapshot at
40+
# the point where a RUNNING_XACTS record is generated by "s1_checkpoint".
41+
# This snapshot contains both two ongoing catalog-change transactions (from s0's
42+
# top-level and sub transactions) and one completed transaction (from s1).
43+
# "s1_check_snapshot_info" verifies whether the logical snapshot contains at
44+
# least the expected number of transactions, accounting for potential
45+
# additional catalog changes that may occur due to concurrent autoanalyze.
46+
permutation"s0_init""s0_begin""s0_savepoint""s0_truncate""s1_create_table""s1_checkpoint""s1_get_changes""s1_check_snapshot_info""s1_check_snapshot_meta""s0_commit"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp