Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tpnV5-00CHEV-SG for pgsql-hackers@arkaria.postgresql.org; Wed, 05 Mar 2025 12:05:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tpnV4-009E4i-H2 for pgsql-hackers@arkaria.postgresql.org; Wed, 05 Mar 2025 12:05:22 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tpnV4-009E2j-2t for pgsql-hackers@lists.postgresql.org; Wed, 05 Mar 2025 12:05:22 +0000 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tpnV1-0016FL-34 for pgsql-hackers@lists.postgresql.org; Wed, 05 Mar 2025 12:05:21 +0000 Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-390f5556579so2928364f8f.1 for ; Wed, 05 Mar 2025 04:05:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741176319; x=1741781119; darn=lists.postgresql.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=+TrMWdJCz3o3aIBhnIsE/Fen1KQPISJZsRqL+aDzRV8=; b=Ruj4cAR03jsjZoVl+ZtcX5Pl9z23Qxjwwqhw4/0aQU3peS9ednIa5a6YzeiFCMoOPl z76MoIYQoq/Laa/KOfqoGN9/+nQSCPauVUZTQs3lFs070Z2/p6/W/YAL6QH+p5be9F3R g8LEFYA+TFsj2SMCI7qgFQxowRT31jIV4pQD+hTD5RYvVx9Z7J+3CUpxUkWODZam2XbU FtI7xaLoDY9/ut/JunLijjf52ahHRBGH+yRhm7wUxbEcgaKOx2vHawbohctdXDB7KcF4 5j/4VedkA632m7bZSX5nZWDlWWMCdmKDASUspZWVhY2zwIOXTMoytz8/DdJsO3QZ6cw3 a+Qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741176319; x=1741781119; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=+TrMWdJCz3o3aIBhnIsE/Fen1KQPISJZsRqL+aDzRV8=; b=eWDjQS3Dx275DZJr2DbMLXMZXrmMSxUhjEKcbITaDKeLJsfU9eSv92UpAVV6ef4EBM h25B9ob5kNsvd0IoAADtgkXqHPdwwlu4eUqNqGuBMAH4GPFzV6/UqUvINHfRMRLoig9C YN31U1AyukHgpnLXZ4yMMpZCGrKp/hQnzZ1Ip1SVarp5IpoJD3QUPrRky+2G8AqbrKXz BkCHA+Hk5XE9le0qM8o8IwBHMtf+G5GQaT1/7XhM143XQ5iKS2PVpsepnKbc9ew2w4PX ah2sSCPmkRdCb4JT/XMlY8xqBxLF8wU0l/Yomfj0DzVxlYsinwo8kKd51GwbEIC650c7 Z9DA== X-Forwarded-Encrypted: i=1; AJvYcCXTXkH7sfXH1r+D5dxIff+7u27xU2D9ZCqO349iwgIo4JMw3NTAnJoW45eNnKGDLobnhxn5gAafnsbVGjUV@lists.postgresql.org X-Gm-Message-State: AOJu0YywoJ2wIP8CUvkGtQt9+M7qqC3Znr7jrfGU0sEf67aARiZnFars JOfIMjBAX7HBb5k/GLvSjJ7E10jqsmm8sWx9/U4bgoObKNG4r+BP X-Gm-Gg: ASbGncvTd3fryKAsqG11Ut5Kqq3E85HlX4odURPEIoABGJrIV3zhypcxTYUDHwRvKro csEQPV/NYCmEPlI6jGVEjrq0wp1S4GR2oe6/GMZGR9zk5LLmrlzgwORz4CPvLT7MXtsNurCepHN laZtnOVTIBl1r48AqLevRmv/1VaIsV9zHc1hZ1rTALWLvHFZL4a0eE2I9J690BvlKRJZfFFpdQ+ 1r7jvFFWoOzQ3evZh2NN67x2mvz+sczt6ZSdsf+eFjlnS0VTGpu4NjZr9Bu5gpvj+uMpHaeKFDm IJWNV9U2LzOllSk/pUjNavwqoHrLmlUf7NpsP4oqGfIm/SYMuoSEBSJ5iSAgZPlhlDihkDpdlDx PHBEEX+6p2VX88L+N2X0zxdqczj0d3BR2mwIrD1gY0TcE++tlVOj8jx6EoPS3+03mHm3b0Gd4s0 95 X-Google-Smtp-Source: AGHT+IFrtnuEzwkfy1yodv83uAJQ4Ol8wHybwx73uT604RSdJr5OtAbbOKMkAA3xP1BnKRPwUpj7BQ== X-Received: by 2002:a05:6000:1f88:b0:390:ed04:a676 with SMTP id ffacd0b85a97d-3911f7491a1mr1778112f8f.22.1741176318459; Wed, 05 Mar 2025 04:05:18 -0800 (PST) Received: from ip-10-97-1-34.eu-west-3.compute.internal (ec2-15-237-181-182.eu-west-3.compute.amazonaws.com. [15.237.181.182]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3912563f973sm755075f8f.84.2025.03.05.04.05.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Mar 2025 04:05:17 -0800 (PST) Date: Wed, 5 Mar 2025 12:05:16 +0000 From: Bertrand Drouvot To: Amit Kapila Cc: Masahiko Sawada , Andres Freund , Peter Smith , Peter Eisentraut , shveta malik , Bharath Rupireddy , pgsql-hackers@lists.postgresql.org Subject: Re: Add contrib/pg_logicalsnapinspect Message-ID: References: <5qbxud4pvnvmtuoi7weiizm5hmumxaeohx4vztfhrwlfhyz6rj@buh4435mllwo> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="wIhah5S3tYpa8EFa" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --wIhah5S3tYpa8EFa Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit Hi, On Wed, Mar 05, 2025 at 02:42:15PM +0530, Amit Kapila wrote: > On Wed, Mar 5, 2025 at 12:47 PM Bertrand Drouvot > wrote: > > > > Agree, PFA a patch doing so. > > > > It would be better if you could add a few comments atop the > permutation line to explain the working of the test. yeah makes sense. Done in the attached, and bonus point I realized that the test could be simplified (so, removing useless steps in passing). Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com --wIhah5S3tYpa8EFa Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0001-Modify-pg_logicalinspect-isolation-test.patch" From 6154e847e4e5c2c7eb816d4302a4704d5a690954 Mon Sep 17 00:00:00 2001 From: Bertrand Drouvot Date: Wed, 5 Mar 2025 07:06:58 +0000 Subject: [PATCH v2] Modify pg_logicalinspect isolation test The previous version was relying on the fact that the test produces exactly 2 snapshots on disk, while in fact it can produce more. Changing the test knowing that at least 2 snapshots are generated. In passing, removing useless steps and adding some comments. Per buildfarm member skink. --- .../expected/logical_inspect.out | 36 ++++++++----------- .../specs/logical_inspect.spec | 11 +++--- 2 files changed, 22 insertions(+), 25 deletions(-) 58.4% contrib/pg_logicalinspect/expected/ 41.5% contrib/pg_logicalinspect/specs/ diff --git a/contrib/pg_logicalinspect/expected/logical_inspect.out b/contrib/pg_logicalinspect/expected/logical_inspect.out index d95efa4d1e5..b7d01dbb68b 100644 --- a/contrib/pg_logicalinspect/expected/logical_inspect.out +++ b/contrib/pg_logicalinspect/expected/logical_inspect.out @@ -1,6 +1,6 @@ Parsed test spec with 2 sessions -starting 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 +starting permutation: s0_init s0_begin s0_savepoint s0_truncate s1_checkpoint s1_get_changes s0_commit s1_checkpoint s1_get_changes s1_get_logical_snapshot_info_catchange s1_get_logical_snapshot_info_committed s1_get_logical_snapshot_meta step s0_init: SELECT 'init' FROM pg_create_logical_replication_slot('isolation_slot', 'test_decoding'); ?column? -------- @@ -17,8 +17,6 @@ data (0 rows) step s0_commit: COMMIT; -step s0_begin: BEGIN; -step s0_insert: INSERT INTO tbl1 VALUES (1); step s1_checkpoint: CHECKPOINT; step s1_get_changes: SELECT data FROM pg_logical_slot_get_changes('isolation_slot', NULL, NULL, 'skip-empty-xacts', '1', 'include-xids', '0'); data @@ -28,25 +26,21 @@ table public.tbl1: TRUNCATE: (no-flags) COMMIT (3 rows) -step s0_commit: COMMIT; -step s1_get_changes: SELECT data FROM pg_logical_slot_get_changes('isolation_slot', NULL, NULL, 'skip-empty-xacts', '1', 'include-xids', '0'); -data -------------------------------------------------------------- -BEGIN -table public.tbl1: INSERT: val1[integer]:1 val2[integer]:null -COMMIT -(3 rows) +step s1_get_logical_snapshot_info_catchange: SELECT count(*) > 0 as has_catchange 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 = 0; +has_catchange +------------- +t +(1 row) -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; -state |catchange_count|catchange_array_length|committed_count|committed_array_length -----------+---------------+----------------------+---------------+---------------------- -consistent| 0| | 2| 2 -consistent| 2| 2| 0| -(2 rows) +step s1_get_logical_snapshot_info_committed: SELECT count(*) > 0 as has_committed FROM pg_ls_logicalsnapdir(), pg_get_logical_snapshot_info(name) AS info where info.committed_count = 2 and array_length(info.committed_xip,1) = 2 and info.catchange_count = 0; +has_committed +------------- +t +(1 row) -step s1_get_logical_snapshot_meta: SELECT COUNT(meta.*) from pg_ls_logicalsnapdir(), pg_get_logical_snapshot_meta(name) as meta; -count ------ - 2 +step s1_get_logical_snapshot_meta: SELECT COUNT(meta.*) > 1 AS has_meta from pg_ls_logicalsnapdir(), pg_get_logical_snapshot_meta(name) as meta; +has_meta +-------- +t (1 row) diff --git a/contrib/pg_logicalinspect/specs/logical_inspect.spec b/contrib/pg_logicalinspect/specs/logical_inspect.spec index 9851a6c18e4..631daf5db6c 100644 --- a/contrib/pg_logicalinspect/specs/logical_inspect.spec +++ b/contrib/pg_logicalinspect/specs/logical_inspect.spec @@ -21,14 +21,17 @@ step "s0_init" { SELECT 'init' FROM pg_create_logical_replication_slot('isolatio step "s0_begin" { BEGIN; } step "s0_savepoint" { SAVEPOINT sp1; } step "s0_truncate" { TRUNCATE tbl1; } -step "s0_insert" { INSERT INTO tbl1 VALUES (1); } step "s0_commit" { COMMIT; } session "s1" setup { SET synchronous_commit=on; } step "s1_checkpoint" { CHECKPOINT; } step "s1_get_changes" { SELECT data FROM pg_logical_slot_get_changes('isolation_slot', NULL, NULL, 'skip-empty-xacts', '1', 'include-xids', '0'); } -step "s1_get_logical_snapshot_meta" { SELECT COUNT(meta.*) from pg_ls_logicalsnapdir(), pg_get_logical_snapshot_meta(name) as meta;} -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; } +step "s1_get_logical_snapshot_meta" { SELECT COUNT(meta.*) > 1 AS has_meta from pg_ls_logicalsnapdir(), pg_get_logical_snapshot_meta(name) as meta; } +step "s1_get_logical_snapshot_info_catchange" { SELECT count(*) > 0 as has_catchange 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 = 0; } +step "s1_get_logical_snapshot_info_committed" { SELECT count(*) > 0 as has_committed FROM pg_ls_logicalsnapdir(), pg_get_logical_snapshot_info(name) AS info where info.committed_count = 2 and array_length(info.committed_xip,1) = 2 and info.catchange_count = 0; } -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" +# The first get_changes produces (at least) one snapshot that contains 2 catchanges +# (the truncate and its parent transaction). The second get_changes produces one +# snapshot that contains the 2 transactions above as committed. +permutation "s0_init" "s0_begin" "s0_savepoint" "s0_truncate" "s1_checkpoint" "s1_get_changes" "s0_commit" "s1_checkpoint" "s1_get_changes" "s1_get_logical_snapshot_info_catchange" "s1_get_logical_snapshot_info_committed" "s1_get_logical_snapshot_meta" -- 2.34.1 --wIhah5S3tYpa8EFa--