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 1rLoI5-000a58-IC for pgsql-hackers@arkaria.postgresql.org; Fri, 05 Jan 2024 17:47: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 1rLoH6-002QPm-En for pgsql-hackers@arkaria.postgresql.org; Fri, 05 Jan 2024 17:46:28 +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 1rLoH6-002QPe-4I for pgsql-hackers@lists.postgresql.org; Fri, 05 Jan 2024 17:46:28 +0000 Received: from mail-il1-x134.google.com ([2607:f8b0:4864:20::134]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rLoH3-0001mz-2Q for pgsql-hackers@postgresql.org; Fri, 05 Jan 2024 17:46:27 +0000 Received: by mail-il1-x134.google.com with SMTP id e9e14a558f8ab-3606f57e08aso3229445ab.3 for ; Fri, 05 Jan 2024 09:46:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704476782; x=1705081582; darn=postgresql.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=fSRg/iwURsf4oa0+9f5YZ1vlin6yZhtWdnhW6ygkZpo=; b=JMBrDPKerH/ADIa6LAYSXqNCBiPjDO9UC1C+wL0eObjOWY4u727zGq9KvmOd0kT0XO 6CKTgVUuiLbte7qBHaBRU2dfDb6yfybyRp/ZlwYJXo4dbGBTVzQXYUbMEk4LEnppW+r8 8fmb1BqfBBGLRFQFjLuAzi25ijYTYuQPsm/tk9WQIVNpQzzIoZnRi3heqD1HbAVTEVMU q1l/nxJKpQu7rLvb93fOF8QGXqvUNdAoTATK0MhZEYebusLuOAjIcUZ7Us/T+jE/jmfs YELFF+gW8j5vvnTgMsBCRZpNf0Yh4TaycB8PbWBSXY6hw4sO7mgc1yt5vQq2pbzytR/6 i5fA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704476782; x=1705081582; h=in-reply-to: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=fSRg/iwURsf4oa0+9f5YZ1vlin6yZhtWdnhW6ygkZpo=; b=k94NlDaJY6xW9Dze2oi5FJU0rnj5RIWP9W7rNsSOZkH9hxPhF1p8w3FN/M3gu2oyPn ibh3MMG6Jda7CCeqMbYYIRvDfm2R6YvnZ98nFPL9eV4CL3Lv/fgk1i4WeBcUIHj1t/Rh tAswQcY5pJh0R6sRPW2BJu2eidIe0XuQSVdyF8WO+buUggNG37rK0X1icqOQKieKlYln cbZ4uec+sG8kGccVCVn+52vj5FHVA1/CSuKZTKSePK54QP2jvLn0WzyHc+ZUEsuvjkxV boy0XlUgFYFCBmZwvXSy5YoX++kgw+FUjzoxQSUdVhNdNgzXz6Za0rLkeG20K+vKhLli kqbw== X-Gm-Message-State: AOJu0YwVKXrO5AF6v8jjbdQBMl00avwLZjs5KPcmJkTHNdtoXeQcZL39 K9D3GRA3pvnnwQdmZfh0V9g= X-Google-Smtp-Source: AGHT+IGEX+Q7UpkfNEGJr2ZDdSjk2TzVZmj9h6xCPU6+xYXG3cfkLIu1okW3G6Y+vcrxk4Mp14yQTw== X-Received: by 2002:a05:6e02:1521:b0:360:7828:c653 with SMTP id i1-20020a056e02152100b003607828c653mr583579ilu.1.1704476782465; Fri, 05 Jan 2024 09:46: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 o10-20020a92daca000000b0035d0da89a0asm613229ilq.6.2024.01.05.09.46.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 09:46:21 -0800 (PST) Date: Fri, 5 Jan 2024 11:46:20 -0600 From: Nathan Bossart To: Bertrand Drouvot Cc: Robert Haas , "pgsql-hackers@postgresql.org" , Michael Paquier Subject: Re: verify predefined LWLocks have entries in wait_event_names.txt Message-ID: <20240105174620.GA2285561@nathanxps13> References: <20240102173120.GA1061678@nathanxps13> <20240102214544.GA1063425@nathanxps13> <20240105061144.GA2166447@nathanxps13> <20240105164203.GC2168314@nathanxps13> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="mYCpIKhGyMATD0i+" Content-Disposition: inline In-Reply-To: <20240105164203.GC2168314@nathanxps13> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --mYCpIKhGyMATD0i+ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, Jan 05, 2024 at 10:42:03AM -0600, Nathan Bossart wrote: > On Fri, Jan 05, 2024 at 07:39:39AM +0000, Bertrand Drouvot wrote: >> + die "lists of predefined LWLocks in lwlocknames.txt and wait_event_names.txt do not match" >> + unless $wait_event_lwlocks[$i] eq $lockname; >> >> What about printing $wait_event_lwlocks[$i] and $lockname in the error message? >> Something like? >> >> " >> die "lists of predefined LWLocks in lwlocknames.txt and wait_event_names.txt do not match (comparing $lockname and $wait_event_lwlocks[$i])" >> unless $wait_event_lwlocks[$i] eq $lockname; >> " >> >> I think that would give more clues for debugging purpose. > > Sure, I'll add something like that. I think this particular scenario is > less likely, but that's not a reason to make the error message hard to > decipher. Here is a new version of the patch with this change. I also tried to make the verification logic less fragile. Instead of depending on the exact location of empty lines in wait_event_names.txt, v3 adds a marker comment below the list that clearly indicates it should not be changed. This simplifies the verification code a bit, too. -- Nathan Bossart Amazon Web Services: https://aws.amazon.com --mYCpIKhGyMATD0i+ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-0001-verify-lists-of-predefined-LWLocks-in-lwlocknames.patch" From e1367cb5c9bbad6b963a5f3596a6133df471654c Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Fri, 5 Jan 2024 00:07:40 -0600 Subject: [PATCH v3 1/1] verify lists of predefined LWLocks in lwlocknames.txt and wait_event_names.txt match --- src/backend/Makefile | 2 +- src/backend/storage/lmgr/Makefile | 4 +- .../storage/lmgr/generate-lwlocknames.pl | 48 +++++++++++++++++++ .../utils/activity/wait_event_names.txt | 12 +++++ src/include/storage/meson.build | 2 +- 5 files changed, 64 insertions(+), 4 deletions(-) diff --git a/src/backend/Makefile b/src/backend/Makefile index 816461aa17..7d2ea7d54a 100644 --- a/src/backend/Makefile +++ b/src/backend/Makefile @@ -130,7 +130,7 @@ $(top_builddir)/src/port/libpgport_srv.a: | submake-libpgport parser/gram.h: parser/gram.y $(MAKE) -C parser gram.h -storage/lmgr/lwlocknames.h: storage/lmgr/generate-lwlocknames.pl storage/lmgr/lwlocknames.txt +storage/lmgr/lwlocknames.h: storage/lmgr/generate-lwlocknames.pl storage/lmgr/lwlocknames.txt utils/activity/wait_event_names.txt $(MAKE) -C storage/lmgr lwlocknames.h lwlocknames.c utils/activity/wait_event_types.h: utils/activity/generate-wait_event_types.pl utils/activity/wait_event_names.txt diff --git a/src/backend/storage/lmgr/Makefile b/src/backend/storage/lmgr/Makefile index c48ba943c4..504480e847 100644 --- a/src/backend/storage/lmgr/Makefile +++ b/src/backend/storage/lmgr/Makefile @@ -39,8 +39,8 @@ s_lock_test: s_lock.c $(top_builddir)/src/common/libpgcommon.a $(top_builddir)/s lwlocknames.c: lwlocknames.h touch $@ -lwlocknames.h: $(top_srcdir)/src/backend/storage/lmgr/lwlocknames.txt generate-lwlocknames.pl - $(PERL) $(srcdir)/generate-lwlocknames.pl $< +lwlocknames.h: $(top_srcdir)/src/backend/storage/lmgr/lwlocknames.txt $(top_srcdir)/src/backend/utils/activity/wait_event_names.txt generate-lwlocknames.pl + $(PERL) $(srcdir)/generate-lwlocknames.pl $^ check: s_lock_test ./s_lock_test diff --git a/src/backend/storage/lmgr/generate-lwlocknames.pl b/src/backend/storage/lmgr/generate-lwlocknames.pl index bef5e16e11..237c3b9678 100644 --- a/src/backend/storage/lmgr/generate-lwlocknames.pl +++ b/src/backend/storage/lmgr/generate-lwlocknames.pl @@ -15,6 +15,7 @@ my $continue = "\n"; GetOptions('outdir:s' => \$output_path); open my $lwlocknames, '<', $ARGV[0] or die; +open my $wait_event_names, '<', $ARGV[1] or die; # Include PID in suffix in case parallel make runs this multiple times. my $htmp = "$output_path/lwlocknames.h.tmp$$"; @@ -30,6 +31,42 @@ print $c $autogen, "\n"; print $c "const char *const IndividualLWLockNames[] = {"; +# +# First, record the predefined LWLocks listed in wait_event_names.txt. We'll +# cross-check those with the ones in lwlocknames.txt. +# +my @wait_event_lwlocks; +my $record_lwlocks = 0; + +while (<$wait_event_names>) +{ + chomp; + + # Check for end marker. + last if /^# END OF PREDEFINED LWLOCKS/; + + # Skip comments and empty lines. + next if /^#/; + next if /^\s*$/; + + # Start recording LWLocks when we find the WaitEventLWLock section. + if (/^Section: ClassName(.*)/) + { + my $section_name = $_; + $section_name =~ s/^.*- //; + $record_lwlocks = 1 if $section_name eq "WaitEventLWLock"; + next; + } + + # Go to the next line if we are not yet recording LWLocks. + next if not $record_lwlocks; + + # Record the LWLock. + (my $waiteventname, my $waitevendocsentence) = split(/\t/, $_); + push(@wait_event_lwlocks, $waiteventname . "Lock"); +} + +my $i = 0; while (<$lwlocknames>) { chomp; @@ -50,6 +87,14 @@ while (<$lwlocknames>) die "lwlocknames.txt not in order" if $lockidx < $lastlockidx; die "lwlocknames.txt has duplicates" if $lockidx == $lastlockidx; + die $lockname . " defined in lwlocknames.txt but missing from wait_event_names.txt" + unless $i < scalar(@wait_event_lwlocks); + die "lists of predefined LWLocks do not match (first mismatch at " . + $wait_event_lwlocks[$i] . " in wait_event_names.txt and " . + $lockname . " in lwlocknames.txt)" + unless $wait_event_lwlocks[$i] eq $lockname; + $i++; + while ($lastlockidx < $lockidx - 1) { ++$lastlockidx; @@ -63,6 +108,9 @@ while (<$lwlocknames>) print $h "#define $lockname (&MainLWLockArray[$lockidx].lock)\n"; } +die $wait_event_lwlocks[$i] . " defined in wait_event_names.txt but missing from lwlocknames.txt" + unless scalar(@wait_event_lwlocks) eq $i; + printf $c "\n};\n"; print $h "\n"; printf $h "#define NUM_INDIVIDUAL_LWLOCKS %s\n", $lastlockidx + 1; diff --git a/src/backend/utils/activity/wait_event_names.txt b/src/backend/utils/activity/wait_event_names.txt index 088eb977d4..4d70e84103 100644 --- a/src/backend/utils/activity/wait_event_names.txt +++ b/src/backend/utils/activity/wait_event_names.txt @@ -276,6 +276,10 @@ Extension "Waiting in an extension." # This class of wait events has its own set of C structure, so these are # only used for the documentation. # +# NB: Predefined locks (those declared in lwlocknames.txt) must be listed in +# the top section of locks and must be listed in the same order as in +# lwlocknames.txt. +# Section: ClassName - WaitEventLWLock @@ -326,6 +330,14 @@ NotifyQueueTail "Waiting to update limit on NOTIFY message st WaitEventExtension "Waiting to read or update custom wait events information for extensions." WALSummarizer "Waiting to read or update WAL summarization state." +# +# END OF PREDEFINED LWLOCKS (DO NOT CHANGE THIS LINE) +# +# Predefined LWLocks (those declared in lwlocknames.txt) must be listed in the +# section above and must be listed in the same order as in lwlocknames.txt. +# Other LWLocks must be listed in the section below. +# + XactBuffer "Waiting for I/O on a transaction status SLRU buffer." CommitTsBuffer "Waiting for I/O on a commit timestamp SLRU buffer." SubtransBuffer "Waiting for I/O on a sub-transaction SLRU buffer." diff --git a/src/include/storage/meson.build b/src/include/storage/meson.build index 2a88248464..8df8b404f5 100644 --- a/src/include/storage/meson.build +++ b/src/include/storage/meson.build @@ -1,7 +1,7 @@ # Copyright (c) 2022-2024, PostgreSQL Global Development Group lwlocknames = custom_target('lwlocknames', - input: files('../../backend/storage/lmgr/lwlocknames.txt'), + input: [files('../../backend/storage/lmgr/lwlocknames.txt'), files('../../backend/utils/activity/wait_event_names.txt')], output: ['lwlocknames.h', 'lwlocknames.c'], command: [ perl, files('../../backend/storage/lmgr/generate-lwlocknames.pl'), -- 2.25.1 --mYCpIKhGyMATD0i+--