Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gOo3H-00046S-Nb for pgsql-hackers@arkaria.postgresql.org; Mon, 19 Nov 2018 18:13:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gOo3E-00066A-17 for pgsql-hackers@arkaria.postgresql.org; Mon, 19 Nov 2018 18:13:36 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gOo3D-000663-Ms for pgsql-hackers@lists.postgresql.org; Mon, 19 Nov 2018 18:13:35 +0000 Received: from mout.gmx.net ([212.227.15.18]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gOo35-000332-Qu for pgsql-hackers@postgresql.org; Mon, 19 Nov 2018 18:13:34 +0000 Received: from nighthawk.chemicalconnection.dyndns.org ([88.217.108.32]) by mail.gmx.com (mrgmx001 [212.227.17.190]) with ESMTPSA (Nemesis) id 0MGj8j-1gBpTC1fEn-00DbAE; Mon, 19 Nov 2018 19:13:11 +0100 Received: from mbanck by nighthawk.chemicalconnection.dyndns.org with local (Exim 4.84_2) (envelope-from ) id 1gOo11-00004y-J9; Mon, 19 Nov 2018 19:11:19 +0100 Date: Mon, 19 Nov 2018 19:11:19 +0100 From: Michael Banck To: Michael Paquier Cc: Andrew Dunstan , Andres Freund , Postgres hackers , Daniel Gustafsson , Magnus Hagander Subject: Re: pgsql: Add TAP tests for pg_verify_checksums Message-ID: <20181119181119.GC23740@nighthawk.caipicrew.dd-dns.de> References: <20181012015319.ezsb2cxb52ulbqgx@alap3.anarazel.de> <20181012020758.GB30064@paquier.xyz> <20181012024118.q3jwio7gf52nsrmm@alap3.anarazel.de> <20181012031158.GD30064@paquier.xyz> <20181012060543.GE30064@paquier.xyz> <20181012101447.GA13287@nighthawk.caipicrew.dd-dns.de> <20181013083040.GF30064@paquier.xyz> <1bce17ea-08f7-c480-fe69-a5f6467b461f@2ndQuadrant.com> <20181014015902.GI30064@paquier.xyz> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="mojUlQ0s9EVzWg2t" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20181014015902.GI30064@paquier.xyz> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: X-Provags-ID: V03:K1:YMtkUmTTPV/jPFsVHR056fGcqbQ13Ez2znaJcPDqt531PsoIsFm Y1mCi+w+3Nt4D8dktf8LX0V2Y/nMbdpQvJ6z9M0j4iFbO6lC3Sh5D3ZsAE1vK+BZBhuaO5i xC/2EE6UxJse3eHR4WihfrNGsHvGHbS9ojPHTudQ+/PqNjT+8dEWSFgFXlO1TqwM73QU/OG 6qZtngiDluGIQxzH88Qgw== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V01:K0:0CeWSztfvNg=:aHthG17YjtbvERnJmXBpOg 7VPtVnAigRsyACqnVuCACIwKY2P/3jN8pmPuQE5VqiFpFAMIPLPxWmIYSIDxoZaQNug/UvFms DxW4KeNrGD14wlF7XtlKUOXVFYUTfkDoN1C1JW5UCt02Ff6yFeTnOZ1YhoXeejTj62ooLrsUP ActAe2mR2GZH50Wp/y/TX13s15T+4KY+zF6e/hA0fYqq0hfQG6NcCUaTqbYOiDTb8AGIGJIt7 ORj+WD7fCclJmaBQbh5FEvROa4mfsqVBMIABdT3ar++f28B5m0Q1EE8EzL5uzDTdfGA/81kHw UVT52ldHFxAWc1hWgt1qRVfxz73tECeQAExiWhk1xnFJl9v1ffqOFv0eSzKZ9nwkbaF5AI0CZ tK97+Q5qIjWRxUpSNw9q792ORRBhcA/Hm4GroXdyc/+kCZeggTtXsg6ErVlMgaMI5Y8/RwRww pqPJQHXzd2CdoVOiHkoNW7T8TUjxji1LEL9FNF8s2nNEY93gPG5NXHlgtLBLJo4mkH3NlaVCw X2lbKxqzKNA9W8HsYrMWiPkTldJcYGPm3AX5SseAD6fi/WU4v53XXIAOGUHLiA+qF3GPIYf/V CTGbKHmaogefphZFZ1CEUc4wXrBhlgcAQonx5oKgqbBJ13q/L/nB6SKJf4zyNWdRV0vOU4rCU /cQeZs11VcIgRrVGjzbnbtx2s/rPXqi2RVjfPXCGzS3yg96w66P7Bhqhni5HvmUz6qQhjW3Lj aYhvNgbNp05Kt3/+yRipuxlKS6eyzPwUOJTIRzp20QgS+CeUKMRJ0CDG76LxbzYSxQy/MAeTc b9Loaelwa/i9SwHBoHxT6FoSmIOtvmYemZspkG4l68ZyT0n+XfX0NWTt+rlE2lTOlwdvpgBq6 hZ6060EjWmNSlW1yGmqzXQN9XoYZkYFnSr1S4hyzI= List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --mojUlQ0s9EVzWg2t Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit Hi, On Sun, Oct 14, 2018 at 10:59:02AM +0900, Michael Paquier wrote: > On Sat, Oct 13, 2018 at 05:53:00PM -0400, Andrew Dunstan wrote: > > It occurred to me that a pretty simple fix could just be to blacklist > > everything that didn't start with a digit. The whitelist approach is > > probably preferable... depends how urgent we see this as. > > Yeah, possibly, still that's not a correct long-term fix. So attached > is what I think we should do for HEAD and REL_11_STABLE with an approach > using a whitelist. I have added positive and negative tests on top of > the existing TAP tests, as suggested by Michael B, and I made the code > use relpath.h to make sure that we don't miss any fork types. I was looking at extending the testsuite for the online checksum verification feature as requested by Fabien, and it seems some of the additional tests are not working as intended: > diff --git a/src/bin/pg_verify_checksums/t/002_actions.pl b/src/bin/pg_verify_checksums/t/002_actions.pl > index dc29da09af..33408ced89 100644 > --- a/src/bin/pg_verify_checksums/t/002_actions.pl > +++ b/src/bin/pg_verify_checksums/t/002_actions.pl [...] > +append_to_file "$pgdata/global/99999_vm.123", ""; > + > # Checksums pass on a newly-created cluster > command_ok(['pg_verify_checksums', '-D', $pgdata], > "succeeds with offline cluster"); > @@ -67,3 +89,30 @@ $node->command_checks_all([ 'pg_verify_checksums', '-D', $pgdata, '-r', > [qr/Bad checksums:.*1/], > [qr/checksum verification failed/], > 'fails for corrupted data on single relfilenode'); > + > +# Utility routine to check that pg_verify_checksums is correctly > +# able to detect correctly-shaped relation files with some data. > +sub fail_corrupt > +{ > + my $node = shift; > + my $file = shift; > + my $pgdata = $node->data_dir; > + > + # Create the file with some data in it. > + append_to_file "$pgdata/global/$file", "foo"; > + > + $node->command_checks_all([ 'pg_verify_checksums', '-D', $pgdata], > + 1, > + [qr/^$/], > + [qr/could not read block/], > + "fails for corrupted data in $file"); > +} > + > +fail_corrupt($node, "99999"); > +fail_corrupt($node, "99999.123"); > +fail_corrupt($node, "99999_fsm"); > +fail_corrupt($node, "99999_init"); > +fail_corrupt($node, "99999_vm"); > +fail_corrupt($node, "99999_init.123"); > +fail_corrupt($node, "99999_fsm.123"); > +fail_corrupt($node, "99999_vm.123"); First off, I think those fail_corrupt files should have different filenames than the empty ones above (I left `99999_vm.123' as an example of a duplicated file). Second, and this is more severe, the subroutine never removes those files so in practise, we are checking the first (or possibly some randon other) file instead of the one we think we are looking at (or at least what I think the intention is). This can be shown if you expand the regexp from `qr/could not read block/' to `qr/could not read block 0 in file.*$file\":/': |t/002_actions.pl .. 6/38 |# Failed test 'fails for corrupted data in 99999.123 stderr /(?^:could |# not read block 0 in file.*99999.123\":)/' |# at t/002_actions.pl line 109. |# 'pg_verify_checksums: could not read block 0 in file |# "[...]src/bin/pg_verify_checksums/tmp_check/t_002_actions_node_checksum_data/pgdata/global/99999": |# read 3 of 8192 |# ' |# doesn't match '(?^:could not read block 0 in file.*99999.123\":)' So either we remove or truncate the files again after $node->command_checks_all(), or the tests use the relfilenode feature. However, in the latter case we would have to use a different main relfilenode ID for each subtest, as otherwise pg_verify_checksums would again fail on the first file it scans. So I am proposing something like the attached. Michael -- Michael Banck Projektleiter / Senior Berater Tel.: +49 2166 9901-171 Fax: +49 2166 9901-100 Email: michael.banck@credativ.de credativ GmbH, HRB Mönchengladbach 12080 USt-ID-Nummer: DE204566209 Trompeterallee 108, 41189 Mönchengladbach Geschäftsführung: Dr. Michael Meskes, Jörg Folz, Sascha Heuer Unser Umgang mit personenbezogenen Daten unterliegt folgenden Bestimmungen: https://www.credativ.de/datenschutz --mojUlQ0s9EVzWg2t Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="pg_verify_checksums_tap_tests.patch" diff --git a/src/bin/pg_verify_checksums/t/002_actions.pl b/src/bin/pg_verify_checksums/t/002_actions.pl index 91adc7fef1..96fbd96e4f 100644 --- a/src/bin/pg_verify_checksums/t/002_actions.pl +++ b/src/bin/pg_verify_checksums/t/002_actions.pl @@ -100,16 +100,17 @@ $node->command_checks_all([ 'pg_verify_checksums', '-D', $pgdata, '-r', sub fail_corrupt { my $node = shift; + my $relfilenode = shift; my $file = shift; my $pgdata = $node->data_dir; # Create the file with some dummy data in it. append_to_file "$pgdata/global/$file", "foo"; - $node->command_checks_all([ 'pg_verify_checksums', '-D', $pgdata], + $node->command_checks_all([ 'pg_verify_checksums', '-D', $pgdata, '-r', $relfilenode], 1, [qr/^$/], - [qr/could not read block/], + [qr/could not read block 0 in file.*$file\":/], "fails for corrupted data in $file"); return; @@ -117,11 +118,11 @@ sub fail_corrupt # Authorized relation files filled with corrupted data cause the # checksum checks to fail. -fail_corrupt($node, "99999"); -fail_corrupt($node, "99999.123"); -fail_corrupt($node, "99999_fsm"); -fail_corrupt($node, "99999_init"); -fail_corrupt($node, "99999_vm"); -fail_corrupt($node, "99999_init.123"); -fail_corrupt($node, "99999_fsm.123"); -fail_corrupt($node, "99999_vm.123"); +fail_corrupt($node, "99990", "99990"); +fail_corrupt($node, "99991", "99991.123"); +fail_corrupt($node, "99992", "99992_fsm"); +fail_corrupt($node, "99993", "99993_init"); +fail_corrupt($node, "99994", "99994_vm"); +fail_corrupt($node, "99995", "99995_init.123"); +fail_corrupt($node, "99996", "99996_fsm.123"); +fail_corrupt($node, "99997", "99997_vm.123"); --mojUlQ0s9EVzWg2t--