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 1rKiby-004AhP-0B for pgsql-hackers@arkaria.postgresql.org; Tue, 02 Jan 2024 17:31:30 +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 1rKibv-0004Ce-AW for pgsql-hackers@arkaria.postgresql.org; Tue, 02 Jan 2024 17:31:27 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rKibu-0004CV-Vl for pgsql-hackers@lists.postgresql.org; Tue, 02 Jan 2024 17:31:27 +0000 Received: from mail-io1-xd31.google.com ([2607:f8b0:4864:20::d31]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rKibs-00FBnk-6O for pgsql-hackers@postgresql.org; Tue, 02 Jan 2024 17:31:26 +0000 Received: by mail-io1-xd31.google.com with SMTP id ca18e2360f4ac-7baa8da5692so414145139f.0 for ; Tue, 02 Jan 2024 09:31:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704216682; x=1704821482; darn=postgresql.org; h=content-transfer-encoding:content-disposition:mime-version :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=sbAZau+s2F2O+GGco46SW8EmUChNic0tXs/KHE0QdrE=; b=M/UzldwG9X3oP+rRjhe9dCENxfCZLKAjEuMXDoiJ9K1zaJoPSZQjkV/b0ktcz9oOkw f2XSYsawpWZbInLpT0K7wxrKT/SxDCJDpNexF/ziC1OrxLzyPaCVDXwLYfmD9Mmu1tkb nADKvplIKHeyTPKK+5+R0QzEKbLMtVqY3z05GELbafSkdmPfYHrESi21f4vc2ArBXtRY W9R3SoYwlhE4OoCXLsBe2fYvz9klNwFNXqdeKtiiwjjeFU/rQf5sDV86UMKwiKWhCobJ zpM1vcJJEAFgt7DwGPaSZbAgDY3jh3GiX0OTXENrTdCnxBwhL90gKqCa2CCjcXqDuYaY aEJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704216682; x=1704821482; h=content-transfer-encoding:content-disposition:mime-version :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sbAZau+s2F2O+GGco46SW8EmUChNic0tXs/KHE0QdrE=; b=cWCsEb5WqP9CNRdOcnPqB6ffzJKWyV2TpBLQ0UNWjvl1WGj5qEwQsKb1EVloe9Tj7C bmFoNztQnM0MPCM2N0t2moGbige2Kmvnhkpm6Y3SLBYPtlOgaS2YdkHgHlKv6z/y2HIQ APAoZLdMIvK6N3aywHDIstU3ShtIahN1fdShRYttYoHjbqsWUGXFP2c35oE8/BT0c9W0 N6XVO3WSUij6mD69/cQ3K38vcjlgI0BCOlzjYuypbcqc4lMraFEuqST1ANMvfsKQUuNX r52N8o4ChyQ+ZeIRLbLuadpgg5wYzWQEU/BTkM25U1xr9OL9iOvz0ySc9dblviSyceG1 IPzg== X-Gm-Message-State: AOJu0YzXYU23S0EpRB+LIwC4Bm2SQcUE2Z48O2iNj77q9q+CL8Zk2ZbP 4Wk99ZtbfSPmnCvXOHF/P24= X-Google-Smtp-Source: AGHT+IE71UG/ZJ0j+0ZiOXquqHBVKwvrKIWhdEl88JkL0yEQ1/KKFbaE592RSHLHJ4Htgw6vZqUDjg== X-Received: by 2002:a5d:8551:0:b0:7bb:b3ce:c20e with SMTP id b17-20020a5d8551000000b007bbb3cec20emr2034582ios.14.1704216682402; Tue, 02 Jan 2024 09:31:22 -0800 (PST) Received: from nathanxps13 (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id e8-20020a02a788000000b004691dc8a3d5sm6772591jaj.58.2024.01.02.09.31.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 09:31:21 -0800 (PST) Date: Tue, 2 Jan 2024 11:31:20 -0600 From: Nathan Bossart To: Robert Haas Cc: "pgsql-hackers@postgresql.org" , Michael Paquier Subject: verify predefined LWLocks have entries in wait_event_names.txt Message-ID: <20240102173120.GA1061678@nathanxps13> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="huq684BweRXVnRxX" Content-Disposition: inline Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --huq684BweRXVnRxX Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit (new thread) On Tue, Jan 02, 2024 at 10:34:11AM -0500, Robert Haas wrote: > On Wed, Dec 27, 2023 at 10:36 AM Nathan Bossart > wrote: >> Thanks! I also noticed that WALSummarizerLock probably needs a mention in >> wait_event_names.txt. > > Fixed. I think we're supposed to omit the "Lock" suffix in wait_event_names.txt. > It seems like it would be good if there were an automated cross-check > between lwlocknames.txt and wait_event_names.txt. +1. Here's a hastily-thrown-together patch for that. I basically copied 003_check_guc.pl and adjusted it for this purpose. This test only checks that everything in lwlocknames.txt has a matching entry in wait_event_names.txt. It doesn't check that everything in the predefined LWLock section of wait_event_names.txt has an entry in lwlocknames.txt. AFAICT that would be a little more difficult because you can't distinguish between the two in pg_wait_events. Even with this test, I worry that we could easily forget to add entries in wait_event_names.txt for the non-predefined locks, but I don't presently have a proposal for how to prevent that. -- Nathan Bossart Amazon Web Services: https://aws.amazon.com --huq684BweRXVnRxX Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v1-0001-verify-wait-events-for-all-lwlocks.patch" From 5031b55d8e1095ca919fe9a088ec0539b28984fc Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Tue, 2 Jan 2024 11:19:20 -0600 Subject: [PATCH v1 1/1] verify wait events for all lwlocks --- .../utils/activity/wait_event_names.txt | 2 +- src/test/modules/test_misc/meson.build | 1 + .../modules/test_misc/t/005_check_lwlock.pl | 51 +++++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 src/test/modules/test_misc/t/005_check_lwlock.pl diff --git a/src/backend/utils/activity/wait_event_names.txt b/src/backend/utils/activity/wait_event_names.txt index d876f8a667..f61ec3e59d 100644 --- a/src/backend/utils/activity/wait_event_names.txt +++ b/src/backend/utils/activity/wait_event_names.txt @@ -324,7 +324,7 @@ XactTruncation "Waiting to execute pg_xact_status or update WrapLimitsVacuum "Waiting to update limits on transaction id and multixact consumption." NotifyQueueTail "Waiting to update limit on NOTIFY message storage." WaitEventExtension "Waiting to read or update custom wait events information for extensions." -WALSummarizerLock "Waiting to read or update WAL summarization state." +WALSummarizer "Waiting to read or update WAL summarization state." XactBuffer "Waiting for I/O on a transaction status SLRU buffer." CommitTsBuffer "Waiting for I/O on a commit timestamp SLRU buffer." diff --git a/src/test/modules/test_misc/meson.build b/src/test/modules/test_misc/meson.build index 911084ac0f..13bc6cb423 100644 --- a/src/test/modules/test_misc/meson.build +++ b/src/test/modules/test_misc/meson.build @@ -10,6 +10,7 @@ tests += { 't/002_tablespace.pl', 't/003_check_guc.pl', 't/004_io_direct.pl', + 't/005_check_lwlock.pl', ], }, } diff --git a/src/test/modules/test_misc/t/005_check_lwlock.pl b/src/test/modules/test_misc/t/005_check_lwlock.pl new file mode 100644 index 0000000000..aff83e879e --- /dev/null +++ b/src/test/modules/test_misc/t/005_check_lwlock.pl @@ -0,0 +1,51 @@ +# Tests to cross-check the consistency of pg_wait_events with lwlocknames.h. + +use strict; +use warnings FATAL => 'all'; +use PostgreSQL::Test::Cluster; +use PostgreSQL::Test::Utils; +use Test::More; + +my $node = PostgreSQL::Test::Cluster->new('main'); +$node->init; +$node->start; + +# Grab the names of all the LWLocks from pg_wait_events. +my $all_lwlocks = $node->safe_psql( + 'postgres', + "SELECT name FROM pg_wait_events WHERE type = 'LWLock'"); +my @all_lwlocks_array = split("\n", $all_lwlocks); + +# Find the location of lwlocknames.h. +my $include_dir = $node->config_data('--includedir'); +my $lwlocknames_file = "$include_dir/server/storage/lwlocknames.h"; + +# Read the list of locks from lwlocknames.h. +my $num_tests = 0; +my @lwlocks_found; +open(my $contents, '<', $lwlocknames_file) + || die "Could not open $lwlocknames_file: $!"; +while (my $line = <$contents>) +{ + if ($line =~ m/^#define ([a-zA-Z]+)Lock .*/) + { + push @lwlocks_found, $1; + } +} +close $contents; + +# Cross-check that all the locks found in lwlocknames.h have matching entries +# in pg_wait_events. +my %all_lwlocks_hash = map { $_ => 1 } @all_lwlocks_array; +my @missing_from_wait_events = grep(!$all_lwlocks_hash{$_}, @lwlocks_found); +is(scalar(@missing_from_wait_events), + 0, "no LWLocks missing from pg_wait_events"); + +foreach my $lwlock (@missing_from_wait_events) +{ + print( + "found $lwlock in lwlocknames.h, missing from wait_event_names.txt\n" + ); +} + +done_testing(); -- 2.25.1 --huq684BweRXVnRxX--