Skip to content

Commit befbd8c

Browse files
michaelpqCommitfest Bot
authored andcommitted
injection_points: Add entry counting
This serves as coverage for the track_counts, as other in-core stats kinds do not need to cap their maximum.
1 parent 66df5e7 commit befbd8c

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

src/test/modules/injection_points/injection_points--1.0.sql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,16 @@ RETURNS bigint
9999
AS 'MODULE_PATHNAME', 'injection_points_stats_numcalls'
100100
LANGUAGE C STRICT;
101101

102+
--
103+
-- injection_points_stats_count()
104+
--
105+
-- Return the number of entries stored in the pgstats hash table.
106+
--
107+
CREATE FUNCTION injection_points_stats_count()
108+
RETURNS bigint
109+
AS 'MODULE_PATHNAME', 'injection_points_stats_count'
110+
LANGUAGE C STRICT;
111+
102112
--
103113
-- injection_points_stats_drop()
104114
--

src/test/modules/injection_points/injection_stats.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ static const PgStat_KindInfo injection_stats = {
4949
.shared_data_len = sizeof(((PgStatShared_InjectionPoint *) 0)->stats),
5050
.pending_size = sizeof(PgStat_StatInjEntry),
5151
.flush_pending_cb = injection_stats_flush_cb,
52+
.track_counts = true,
5253
};
5354

5455
/*
@@ -198,6 +199,17 @@ injection_points_stats_numcalls(PG_FUNCTION_ARGS)
198199
PG_RETURN_INT64(entry->numcalls);
199200
}
200201

202+
/*
203+
* SQL function returning the number of entries allocated for injection
204+
* points in the shared hashtable of pgstats.
205+
*/
206+
PG_FUNCTION_INFO_V1(injection_points_stats_count);
207+
Datum
208+
injection_points_stats_count(PG_FUNCTION_ARGS)
209+
{
210+
PG_RETURN_INT64(pgstat_get_entry_count(PGSTAT_KIND_INJECTION));
211+
}
212+
201213
/* Only used by injection_points_stats_drop() */
202214
static bool
203215
match_inj_entries(PgStatShared_HashEntry *entry, Datum match_data)

src/test/modules/injection_points/t/001_stats.pl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
my $numcalls = $node->safe_psql('postgres',
3737
"SELECT injection_points_stats_numcalls('stats-notice');");
3838
is($numcalls, '2', 'number of stats calls');
39+
my $entrycount =
40+
$node->safe_psql('postgres', "SELECT injection_points_stats_count();");
41+
is($entrycount, '1', 'number of entries');
3942
my $fixedstats = $node->safe_psql('postgres',
4043
"SELECT * FROM injection_points_stats_fixed();");
4144
is($fixedstats, '1|0|2|0|0', 'fixed stats after some calls');
@@ -55,6 +58,9 @@
5558
$numcalls = $node->safe_psql('postgres',
5659
"SELECT injection_points_stats_numcalls('stats-notice');");
5760
is($numcalls, '3', 'number of stats after clean restart');
61+
$entrycount =
62+
$node->safe_psql('postgres', "SELECT injection_points_stats_count();");
63+
is($entrycount, '1', 'number of entries after clean restart');
5864
$fixedstats = $node->safe_psql('postgres',
5965
"SELECT * FROM injection_points_stats_fixed();");
6066
is($fixedstats, '1|0|2|1|1', 'fixed stats after clean restart');
@@ -65,6 +71,9 @@
6571
$numcalls = $node->safe_psql('postgres',
6672
"SELECT injection_points_stats_numcalls('stats-notice');");
6773
is($numcalls, '', 'number of stats after crash');
74+
$entrycount =
75+
$node->safe_psql('postgres', "SELECT injection_points_stats_count();");
76+
is($entrycount, '0', 'number of entries after crash');
6877
$fixedstats = $node->safe_psql('postgres',
6978
"SELECT * FROM injection_points_stats_fixed();");
7079
is($fixedstats, '0|0|0|0|0', 'fixed stats after crash');
@@ -81,6 +90,9 @@
8190
$numcalls = $node->safe_psql('postgres',
8291
"SELECT injection_points_stats_numcalls('stats-notice');");
8392
is($numcalls, '', 'no stats after drop via SQL function');
93+
$entrycount =
94+
$node->safe_psql('postgres', "SELECT injection_points_stats_count();");
95+
is($entrycount, '0', 'number of entries after drop via SQL function');
8496

8597
# Stop the server, disable the module, then restart. The server
8698
# should be able to come up.

0 commit comments

Comments
 (0)