mirror of
https://github.com/postgres/postgres.git
synced 2025-09-02 04:21:28 +03:00
pgstat: add pg_stat_force_next_flush(), use it to simplify tests.
In the stats collector days it was hard to write tests for the stats system, because fundamentally delivery of stats messages over UDP was not synchronous (nor guaranteed). Now we easily can force pending stats updates to be flushed synchronously. This moves stats.sql into a parallel group, there isn't a reason for it to run in isolation anymore. And it may shake out some bugs. Bumps catversion. Author: Andres Freund <andres@anarazel.de> Discussion: https://postgr.es/m/20220303021600.hs34ghqcw6zcokdh@alap3.anarazel.de
This commit is contained in:
@@ -219,6 +219,12 @@ static MemoryContext pgStatPendingContext = NULL;
|
||||
static dlist_head pgStatPending = DLIST_STATIC_INIT(pgStatPending);
|
||||
|
||||
|
||||
/*
|
||||
* Force the next stats flush to happen regardless of
|
||||
* PGSTAT_MIN_INTERVAL. Useful in test scripts.
|
||||
*/
|
||||
static bool pgStatForceNextFlush = false;
|
||||
|
||||
/*
|
||||
* For assertions that check pgstat is not used before initialization / after
|
||||
* shutdown.
|
||||
@@ -560,6 +566,13 @@ pgstat_report_stat(bool force)
|
||||
pgstat_assert_is_up();
|
||||
Assert(!IsTransactionBlock());
|
||||
|
||||
/* "absorb" the forced flush even if there's nothing to flush */
|
||||
if (pgStatForceNextFlush)
|
||||
{
|
||||
force = true;
|
||||
pgStatForceNextFlush = false;
|
||||
}
|
||||
|
||||
/* Don't expend a clock check if nothing to do */
|
||||
if (dlist_is_empty(&pgStatPending) &&
|
||||
!have_slrustats &&
|
||||
@@ -637,6 +650,16 @@ pgstat_report_stat(bool force)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Force locally pending stats to be flushed during the next
|
||||
* pgstat_report_stat() call. This is useful for writing tests.
|
||||
*/
|
||||
void
|
||||
pgstat_force_next_flush(void)
|
||||
{
|
||||
pgStatForceNextFlush = true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Only for use by pgstat_reset_counters()
|
||||
*/
|
||||
|
@@ -2067,6 +2067,16 @@ pg_stat_clear_snapshot(PG_FUNCTION_ARGS)
|
||||
}
|
||||
|
||||
|
||||
/* Force statistics to be reported at the next occasion */
|
||||
Datum
|
||||
pg_stat_force_next_flush(PG_FUNCTION_ARGS)
|
||||
{
|
||||
pgstat_force_next_flush();
|
||||
|
||||
PG_RETURN_VOID();
|
||||
}
|
||||
|
||||
|
||||
/* Reset all counters for the current database */
|
||||
Datum
|
||||
pg_stat_reset(PG_FUNCTION_ARGS)
|
||||
|
Reference in New Issue
Block a user