mirror of
https://github.com/percona/pg_stat_monitor.git
synced 2026-02-04 14:06:20 +00:00
PG-220: Fix read/write of dumped query buffer to files.
This commit fix some issues when the query buffer overflows and pg_stat_monitor attempts to dump its contents to a file. The dump process is now as follows: 1. The dump will always be a full dump of the current query buffer, meaning pg_stat_monitor will dump MAX_QUERY_BUFFER_BUCKET bytes to the dump file. 2. When scanning the dump file, read chunks of size MAX_QUERY_BUFFER_BUCKET, then look for the query ID using that chunk and the query position metadata, this allows pg_stat_monitor to avoid scanning the whole chunk when looking for a query ID. The code in charge to read from/write to the dump file now takes into account that read() and write() may return less bytes than what it was asked for, the code now ensures that we actually read or write the amount of bytes required (MAX_QUERY_BUFFER_BUCKET), also it handles rare but posssible interrupts when doing those operations.
This commit is contained in:
@@ -390,7 +390,7 @@ void hash_entry_dealloc(int new_bucket_id, int old_bucket_id, unsigned char *que
|
||||
pgssEntry* hash_entry_alloc(pgssSharedState *pgss, pgssHashKey *key, int encoding);
|
||||
Size hash_memsize(void);
|
||||
|
||||
int read_query_buffer(int bucket_id, uint64 queryid, char *query_txt);
|
||||
int read_query_buffer(int bucket_id, uint64 queryid, char *query_txt, size_t pos);
|
||||
uint64 read_query(unsigned char *buf, uint64 queryid, char * query, size_t pos);
|
||||
pgssQueryEntry* hash_find_query_entry(uint64 bucket_id, uint64 queryid, uint64 dbid, uint64 userid, uint64 ip, uint64 appid);
|
||||
pgssQueryEntry* hash_create_query_entry(uint64 bucket_id, uint64 queryid, uint64 dbid, uint64 userid, uint64 ip, uint64 appid);
|
||||
|
||||
Reference in New Issue
Block a user