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

Commitce5c620

Browse files
committed
Add pgstat_drop_matching_entries() to pgstats
This allows users of the cumulative statistics to drop entries in theshared hash stats table, deleting as well local references. Callers ofthis function can optionally define a callback able to filter whichentries to drop, similarly to pgstat_reset_matching_entries() with itscallback do_reset().pgstat_drop_all_entries() is refactored so as it uses this new function.Author: Lukas FittiDiscussion:https://postgr.es/m/CAP53PkwuFbo3NkwZgxwNRMjMfqPEqidD-SggaoQ4ijotBVLJAA@mail.gmail.com
1 parent1e380fa commitce5c620

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -993,19 +993,39 @@ pgstat_drop_entry(PgStat_Kind kind, Oid dboid, uint64 objid)
993993
returnfreed;
994994
}
995995

996+
/*
997+
* Scan through the shared hashtable of stats, dropping statistics if
998+
* approved by the optional do_drop() function.
999+
*/
9961000
void
997-
pgstat_drop_all_entries(void)
1001+
pgstat_drop_matching_entries(bool (*do_drop) (PgStatShared_HashEntry*,Datum),
1002+
Datummatch_data)
9981003
{
9991004
dshash_seq_statushstat;
10001005
PgStatShared_HashEntry*ps;
10011006
uint64not_freed_count=0;
10021007

1008+
/* entries are removed, take an exclusive lock */
10031009
dshash_seq_init(&hstat,pgStatLocal.shared_hash, true);
10041010
while ((ps=dshash_seq_next(&hstat))!=NULL)
10051011
{
10061012
if (ps->dropped)
10071013
continue;
10081014

1015+
if (do_drop!=NULL&& !do_drop(ps,match_data))
1016+
continue;
1017+
1018+
/* delete local reference */
1019+
if (pgStatEntryRefHash)
1020+
{
1021+
PgStat_EntryRefHashEntry*lohashent=
1022+
pgstat_entry_ref_hash_lookup(pgStatEntryRefHash,ps->key);
1023+
1024+
if (lohashent)
1025+
pgstat_release_entry_ref(lohashent->key,lohashent->entry_ref,
1026+
true);
1027+
}
1028+
10091029
if (!pgstat_drop_entry_internal(ps,&hstat))
10101030
not_freed_count++;
10111031
}
@@ -1015,6 +1035,15 @@ pgstat_drop_all_entries(void)
10151035
pgstat_request_entry_refs_gc();
10161036
}
10171037

1038+
/*
1039+
* Scan through the shared hashtable of stats and drop all entries.
1040+
*/
1041+
void
1042+
pgstat_drop_all_entries(void)
1043+
{
1044+
pgstat_drop_matching_entries(NULL,0);
1045+
}
1046+
10181047
staticvoid
10191048
shared_stat_reset_contents(PgStat_Kindkind,PgStatShared_Common*header,
10201049
TimestampTzts)

‎src/include/utils/pgstat_internal.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,8 @@ extern bool pgstat_lock_entry_shared(PgStat_EntryRef *entry_ref, bool nowait);
718718
externvoidpgstat_unlock_entry(PgStat_EntryRef*entry_ref);
719719
externboolpgstat_drop_entry(PgStat_Kindkind,Oiddboid,uint64objid);
720720
externvoidpgstat_drop_all_entries(void);
721+
externvoidpgstat_drop_matching_entries(bool (*do_drop) (PgStatShared_HashEntry*,Datum),
722+
Datummatch_data);
721723
externPgStat_EntryRef*pgstat_get_entry_ref_locked(PgStat_Kindkind,Oiddboid,uint64objid,
722724
boolnowait);
723725
externvoidpgstat_reset_entry(PgStat_Kindkind,Oiddboid,uint64objid,TimestampTzts);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp