Add dump_relsize_cache() function

Quite useful for seeing what's in the cache.
This commit is contained in:
Heikki Linnakangas
2024-08-23 14:28:04 +03:00
parent f7ab3ffcb7
commit e986896676
7 changed files with 93 additions and 2 deletions

View File

@@ -441,6 +441,11 @@ WAL-log them periodically, from a backgound worker.
Similarly to replications snapshot files, the CID mapping files generated during VACUUM FULL of a catalog table are WAL-logged
FIXME: But they're not, AFAICS?
FIXME: However, we do WAL-log the file in pg_logical/mappings. But AFAICS that's WAL-logged
by PostgreSQL too. Why do we need separate WAL-logging for that? See changes in rewriteheap.c
### How to get rid of the patch
WAL-log them periodically, from a backgound worker.

View File

@@ -284,6 +284,9 @@ extern PGDLLEXPORT void neon_read_at_lsn(NRelFileInfo rnode, ForkNumber forkNum,
extern void neon_write(SMgrRelation reln, ForkNumber forknum,
BlockNumber blocknum, const void *buffer, bool skipFsync);
#endif
extern PGDLLEXPORT void neon_dump_relsize_cache(void);
extern void neon_writeback(SMgrRelation reln, ForkNumber forknum,
BlockNumber blocknum, BlockNumber nblocks);
extern BlockNumber neon_nblocks(SMgrRelation reln, ForkNumber forknum);

View File

@@ -277,3 +277,62 @@ relsize_shmem_request(void)
RequestNamedLWLockTranche("neon_relsize", 1);
}
#endif
/*
* A debugging function, to print the contents of the relsize cache as NOTICE
* messages. This is exposed in the neon_test_utils extension.
*/
void
neon_dump_relsize_cache(void)
{
HASH_SEQ_STATUS status;
RelSizeEntry *entry;
dlist_iter iter;
int cnt;
if (relsize_hash_size == 0)
{
elog(NOTICE, "relsize cache is disable");
return;
}
LWLockAcquire(relsize_lock, LW_EXCLUSIVE);
elog(NOTICE, "stats: size %lu hits: " UINT64_FORMAT " misses " UINT64_FORMAT " writes " UINT64_FORMAT,
(unsigned long) relsize_ctl->size, relsize_ctl->hits, relsize_ctl->misses, relsize_ctl->writes);
elog(NOTICE, "hash:");
cnt = 0;
hash_seq_init(&status, relsize_hash);
while ((entry = hash_seq_search(&status)) != NULL)
{
cnt++;
elog(NOTICE, "hash entry %d: rel %u/%u/%u.%u size %u",
cnt,
RelFileInfoFmt(entry->tag.rinfo),
entry->tag.forknum,
entry->size);
}
elog(NOTICE, "LRU:");
cnt = 0;
dlist_foreach(iter, &relsize_ctl->lru)
{
entry = dlist_container(RelSizeEntry, lru_node, iter.cur);
cnt++;
elog(NOTICE, "LRU entry %d: rel %u/%u/%u.%u size %u",
cnt,
RelFileInfoFmt(entry->tag.rinfo),
entry->tag.forknum,
entry->size);
if (cnt > relsize_hash_size * 2)
{
elog(NOTICE, "broken LRU chain??");
break;
}
}
LWLockRelease(relsize_lock);
}

View File

@@ -7,7 +7,7 @@ OBJS = \
neontest.o
EXTENSION = neon_test_utils
DATA = neon_test_utils--1.3.sql
DATA = neon_test_utils--1.4.sql
PGFILEDESC = "neon_test_utils - helpers for neon testing and debugging"
PG_CONFIG = pg_config

View File

@@ -69,3 +69,8 @@ BEGIN
PERFORM trigger_segfault();
END;
$$;
CREATE FUNCTION dump_relsize_cache()
RETURNS VOID
AS 'MODULE_PATHNAME', 'dump_relsize_cache'
LANGUAGE C PARALLEL UNSAFE;

View File

@@ -1,6 +1,6 @@
# neon_test_utils extension
comment = 'helpers for neon testing and debugging'
default_version = '1.3'
default_version = '1.4'
module_pathname = '$libdir/neon_test_utils'
relocatable = true
trusted = true

View File

@@ -45,6 +45,7 @@ PG_FUNCTION_INFO_V1(get_raw_page_at_lsn_ex);
PG_FUNCTION_INFO_V1(neon_xlogflush);
PG_FUNCTION_INFO_V1(trigger_panic);
PG_FUNCTION_INFO_V1(trigger_segfault);
PG_FUNCTION_INFO_V1(dump_relsize_cache);
/*
* Linkage to functions in neon module.
@@ -60,6 +61,10 @@ typedef void (*neon_read_at_lsn_type) (NRelFileInfo rinfo, ForkNumber forkNum, B
static neon_read_at_lsn_type neon_read_at_lsn_ptr;
typedef void (*neon_dump_relsize_cache_type) (void);
static neon_dump_relsize_cache_type neon_dump_relsize_cache_ptr;
/*
* Module initialize function: fetch function pointers for cross-module calls.
*/
@@ -68,12 +73,18 @@ _PG_init(void)
{
/* Asserts verify that typedefs above match original declarations */
AssertVariableIsOfType(&neon_read_at_lsn, neon_read_at_lsn_type);
AssertVariableIsOfType(&neon_dump_relsize_cache, neon_dump_relsize_cache_type);
neon_read_at_lsn_ptr = (neon_read_at_lsn_type)
load_external_function("$libdir/neon", "neon_read_at_lsn",
true, NULL);
neon_dump_relsize_cache_ptr = (neon_dump_relsize_cache_type)
load_external_function("$libdir/neon", "neon_dump_relsize_cache",
true, NULL);
}
#define neon_read_at_lsn neon_read_at_lsn_ptr
#define neon_dump_relsize_cache neon_dump_relsize_cache_ptr
/*
* test_consume_oids(int4), for rapidly consuming OIDs, to test wraparound.
@@ -528,3 +539,11 @@ trigger_segfault(PG_FUNCTION_ARGS)
*ptr = 42;
PG_RETURN_VOID();
}
Datum
dump_relsize_cache(PG_FUNCTION_ARGS)
{
neon_dump_relsize_cache();
PG_RETURN_VOID();
}