mirror of
https://github.com/percona/pg_stat_monitor.git
synced 2026-02-04 14:06:20 +00:00
PG-230: Fix duplicated query entries.
A problem during bucket management was allowing some queries to be duplicated, old entries would sit around without having their statistics updated. The problem would arise during the following chain of events: 1. A query goes through pgss_post_parse_analyze, in this stage (PGSS_PARSE) we only save the query into the query buffer and create an entry in the query hash table. 2. The query then goes through pgss_ExecutorStart (PGSS_EXEC), in this stage we create an entry for query statistic counters with default values, all time stats equal zero, etc. 3. The query then goes through pgss_ExecutorEnd (PGSS_FINISH), in this stage we update the query statistis, no. calls, total time taken, min_time, etc. The problem is that between steps 2 and 3, the current bucket ID timer may have been expired. For example, during steps 1 and 2 the query may have been stored in bucket ID 1, but when the query is finished (pgss_ExecutorEnd) the current bucket ID may have been updated to 2. This is leaving an entry for the query in bucket ID 1 with state ACTIVE, with time statistics not updated yet. This is also creating an entry for the query in the bucket ID 2, with all statistics (time and others) being updated for this entry. To solve this problem, during transition to a new bucket id, we scan all pending queries in the previous bucket id and move them to the new bucket id. This way finished queries will always be associated with the bucket id that was active at the time they've finished.
This commit is contained in:
@@ -380,7 +380,7 @@ void hash_entry_reset(void);
|
||||
void hash_query_entryies_reset(void);
|
||||
void hash_query_entries();
|
||||
void hash_query_entry_dealloc(int bucket, unsigned char *buf);
|
||||
bool hash_entry_dealloc(int bucket);
|
||||
bool hash_entry_dealloc(int new_bucket_id, int old_bucket_id);
|
||||
pgssEntry* hash_entry_alloc(pgssSharedState *pgss, pgssHashKey *key, int encoding);
|
||||
Size hash_memsize(void);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user