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

Commit5b1b9bc

Browse files
Cross-check lists of predefined LWLocks.
Both lwlocknames.txt and wait_event_names.txt contain a list of allthe predefined LWLocks, i.e., those with predefined positionswithin MainLWLockArray. It is easy to miss one or the other,especially since the list in wait_event_names.txt omits the "Lock"suffix from all the LWLock wait events. This commit adds a cross-check of these lists to the script that generates lwlocknames.h.If the lists do not match exactly, building will fail.Suggested-by: Robert HaasReviewed-by: Robert Haas, Michael Paquier, Bertrand DrouvotDiscussion:https://postgr.es/m/20240102173120.GA1061678%40nathanxps13
1 parenta7be2a6 commit5b1b9bc

File tree

5 files changed

+67
-4
lines changed

5 files changed

+67
-4
lines changed

‎src/backend/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ $(top_builddir)/src/port/libpgport_srv.a: | submake-libpgport
130130
parser/gram.h: parser/gram.y
131131
$(MAKE) -C parser gram.h
132132

133-
storage/lmgr/lwlocknames.h: storage/lmgr/generate-lwlocknames.pl storage/lmgr/lwlocknames.txt
133+
storage/lmgr/lwlocknames.h: storage/lmgr/generate-lwlocknames.pl storage/lmgr/lwlocknames.txt utils/activity/wait_event_names.txt
134134
$(MAKE) -C storage/lmgr lwlocknames.h lwlocknames.c
135135

136136
utils/activity/wait_event_types.h: utils/activity/generate-wait_event_types.pl utils/activity/wait_event_names.txt

‎src/backend/storage/lmgr/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ s_lock_test: s_lock.c $(top_builddir)/src/common/libpgcommon.a $(top_builddir)/s
3939
lwlocknames.c: lwlocknames.h
4040
touch$@
4141

42-
lwlocknames.h:$(top_srcdir)/src/backend/storage/lmgr/lwlocknames.txt generate-lwlocknames.pl
43-
$(PERL)$(srcdir)/generate-lwlocknames.pl$<
42+
lwlocknames.h:$(top_srcdir)/src/backend/storage/lmgr/lwlocknames.txt$(top_srcdir)/src/backend/utils/activity/wait_event_names.txtgenerate-lwlocknames.pl
43+
$(PERL)$(srcdir)/generate-lwlocknames.pl$^
4444

4545
check: s_lock_test
4646
./s_lock_test

‎src/backend/storage/lmgr/generate-lwlocknames.pl

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
GetOptions('outdir:s'=> \$output_path);
1616

1717
openmy$lwlocknames,'<',$ARGV[0]ordie;
18+
openmy$wait_event_names,'<',$ARGV[1]ordie;
1819

1920
# Include PID in suffix in case parallel make runs this multiple times.
2021
my$htmp ="$output_path/lwlocknames.h.tmp$$";
@@ -30,6 +31,40 @@
3031

3132
print$c"const char *const IndividualLWLockNames[] = {";
3233

34+
#
35+
# First, record the predefined LWLocks listed in wait_event_names.txt. We'll
36+
# cross-check those with the ones in lwlocknames.txt.
37+
#
38+
my@wait_event_lwlocks;
39+
my$record_lwlocks = 0;
40+
41+
while (<$wait_event_names>)
42+
{
43+
chomp;
44+
45+
# Check for end marker.
46+
lastif/^# END OF PREDEFINED LWLOCKS/;
47+
48+
# Skip comments and empty lines.
49+
nextif/^#/;
50+
nextif/^\s*$/;
51+
52+
# Start recording LWLocks when we find the WaitEventLWLock section.
53+
if (/^Section: ClassName - WaitEventLWLock$/)
54+
{
55+
$record_lwlocks = 1;
56+
next;
57+
}
58+
59+
# Go to the next line if we are not yet recording LWLocks.
60+
nextifnot$record_lwlocks;
61+
62+
# Record the LWLock.
63+
(my$waiteventname,my$waitevendocsentence) =split(/\t/,$_);
64+
push(@wait_event_lwlocks,$waiteventname ."Lock");
65+
}
66+
67+
my$i = 0;
3368
while (<$lwlocknames>)
3469
{
3570
chomp;
@@ -50,6 +85,15 @@
5085
die"lwlocknames.txt not in order"if$lockidx <$lastlockidx;
5186
die"lwlocknames.txt has duplicates"if$lockidx ==$lastlockidx;
5287

88+
die"$lockname defined in lwlocknames.txt but missing from"
89+
."wait_event_names.txt"
90+
if$i >=scalar@wait_event_lwlocks;
91+
die"lists of predefined LWLocks do not match (first mismatch at"
92+
."$wait_event_lwlocks[$i] in wait_event_names.txt and$lockname in"
93+
."lwlocknames.txt)"
94+
if$wait_event_lwlocks[$i]ne$lockname;
95+
$i++;
96+
5397
while ($lastlockidx <$lockidx - 1)
5498
{
5599
++$lastlockidx;
@@ -63,6 +107,11 @@
63107
print$h"#define$lockname (&MainLWLockArray[$lockidx].lock)\n";
64108
}
65109

110+
die
111+
"$wait_event_lwlocks[$i] defined in wait_event_names.txt but missing from"
112+
."lwlocknames.txt"
113+
if$i <scalar@wait_event_lwlocks;
114+
66115
printf$c"\n};\n";
67116
print$h"\n";
68117
printf$h"#define NUM_INDIVIDUAL_LWLOCKS%s\n",$lastlockidx + 1;

‎src/backend/utils/activity/wait_event_names.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,10 @@ Extension"Waiting in an extension."
276276
# This class of wait events has its own set of C structure, so these are
277277
# only used for the documentation.
278278
#
279+
# NB: Predefined LWLocks (i.e., those declared in lwlocknames.txt) must be
280+
# listed in the top section of locks and must be listed in the same order as in
281+
# lwlocknames.txt.
282+
#
279283

280284
Section: ClassName - WaitEventLWLock
281285

@@ -326,6 +330,14 @@ NotifyQueueTail"Waiting to update limit on <command>NOTIFY</command> message st
326330
WaitEventExtension"Waiting to read or update custom wait events information for extensions."
327331
WALSummarizer"Waiting to read or update WAL summarization state."
328332

333+
#
334+
# END OF PREDEFINED LWLOCKS (DO NOT CHANGE THIS LINE)
335+
#
336+
# Predefined LWLocks (i.e., those declared in lwlocknames.txt) must be listed
337+
# in the section above and must be listed in the same order as in
338+
# lwlocknames.txt. Other LWLocks must be listed in the section below.
339+
#
340+
329341
XactBuffer"Waiting for I/O on a transaction status SLRU buffer."
330342
CommitTsBuffer"Waiting for I/O on a commit timestamp SLRU buffer."
331343
SubtransBuffer"Waiting for I/O on a sub-transaction SLRU buffer."

‎src/include/storage/meson.build

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# Copyright (c) 2022-2024, PostgreSQL Global Development Group
22

33
lwlocknames=custom_target('lwlocknames',
4-
input:files('../../backend/storage/lmgr/lwlocknames.txt'),
4+
input:files(
5+
'../../backend/storage/lmgr/lwlocknames.txt',
6+
'../../backend/utils/activity/wait_event_names.txt'),
57
output: ['lwlocknames.h','lwlocknames.c'],
68
command: [
79
perl,files('../../backend/storage/lmgr/generate-lwlocknames.pl'),

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp