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

Commit5cd1c40

Browse files
committed
pgstat: set timestamps of fixed-numbered stats after a crash.
When not loading stats at startup (i.e. pgstat_discard_stats() gettingcalled), reset timestamps of fixed numbered stats would be left at0. Oversight in5891c7a.Instead use pgstat_reset_after_failure() and add tests verifying thatfixed-numbered reset timestamps are set appropriately.Reported-By: "David G. Johnston" <david.g.johnston@gmail.com>Discussion:https://postgr.es/m/CAKFQuwamFuaQHKdhcMt4Gbw5+Hca2UE741B8gOOXoA=TtAd2Yw@mail.gmail.com
1 parent3f19e17 commit5cd1c40

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

‎src/backend/utils/activity/pgstat.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ typedef struct PgStat_SnapshotEntry
166166
staticvoidpgstat_write_statsfile(void);
167167
staticvoidpgstat_read_statsfile(void);
168168

169-
staticvoidpgstat_reset_after_failure(TimestampTzts);
169+
staticvoidpgstat_reset_after_failure(void);
170170

171171
staticboolpgstat_flush_pending_entries(boolnowait);
172172

@@ -427,6 +427,12 @@ pgstat_discard_stats(void)
427427
errmsg("unlinked permanent statistics file \"%s\"",
428428
PGSTAT_STAT_PERMANENT_FILENAME)));
429429
}
430+
431+
/*
432+
* Reset stats contents. This will set reset timestamps of fixed-numbered
433+
* stats to the current time (no variable stats exist).
434+
*/
435+
pgstat_reset_after_failure();
430436
}
431437

432438
/*
@@ -1422,7 +1428,6 @@ pgstat_read_statsfile(void)
14221428
boolfound;
14231429
constchar*statfile=PGSTAT_STAT_PERMANENT_FILENAME;
14241430
PgStat_ShmemControl*shmem=pgStatLocal.shmem;
1425-
TimestampTzts=GetCurrentTimestamp();
14261431

14271432
/* shouldn't be called from postmaster */
14281433
Assert(IsUnderPostmaster|| !IsPostmasterEnvironment);
@@ -1445,7 +1450,7 @@ pgstat_read_statsfile(void)
14451450
(errcode_for_file_access(),
14461451
errmsg("could not open statistics file \"%s\": %m",
14471452
statfile)));
1448-
pgstat_reset_after_failure(ts);
1453+
pgstat_reset_after_failure();
14491454
return;
14501455
}
14511456

@@ -1597,19 +1602,20 @@ pgstat_read_statsfile(void)
15971602
ereport(LOG,
15981603
(errmsg("corrupted statistics file \"%s\"",statfile)));
15991604

1600-
/* Set the current timestamp as reset timestamp */
1601-
pgstat_reset_after_failure(ts);
1605+
pgstat_reset_after_failure();
16021606

16031607
gotodone;
16041608
}
16051609

16061610
/*
1607-
* Helper to reset / drop stats after restoring stats from disk failed,
1608-
* potentially after already loading parts.
1611+
* Helper to reset / drop stats aftera crash or afterrestoring stats from
1612+
*disk failed,potentially after already loading parts.
16091613
*/
16101614
staticvoid
1611-
pgstat_reset_after_failure(TimestampTzts)
1615+
pgstat_reset_after_failure(void)
16121616
{
1617+
TimestampTzts=GetCurrentTimestamp();
1618+
16131619
/* reset fixed-numbered stats */
16141620
for (intkind=PGSTAT_KIND_FIRST_VALID;kind <=PGSTAT_KIND_LAST;kind++)
16151621
{

‎src/test/recovery/t/029_stats_restart.pl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,16 @@
250250
$wal_restart2->{reset},
251251
"$sect: newer stats_reset");
252252

253+
$node->stop('immediate');
254+
$node->start;
255+
256+
$sect ="post immediate restart";
257+
my$wal_restart_immediate = wal_stats();
258+
259+
cmp_ok(
260+
$wal_reset_restart->{reset},'lt',
261+
$wal_restart_immediate->{reset},
262+
"$sect: reset timestamp is new");
253263

254264
$node->stop;
255265
done_testing();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp