From bfdd37b54e9831f580f3a759532228178ef07efa Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Wed, 23 Jul 2025 13:00:49 +0300 Subject: [PATCH] Fix segfault in unimplemented function We need to implement this eventually, but for now let's at least silence the segfault. See also https://github.com/neondatabase/neon/pull/12696 --- pgxn/neon/communicator_new.c | 15 ++++----------- pgxn/neon/communicator_new.h | 2 +- pgxn/neon/file_cache.c | 32 ++++++++++++++++---------------- pgxn/neon/file_cache.h | 2 +- pgxn/neon/neon.c | 11 +++++------ 5 files changed, 27 insertions(+), 35 deletions(-) diff --git a/pgxn/neon/communicator_new.c b/pgxn/neon/communicator_new.c index b951ecff74..a38d7a1ae5 100644 --- a/pgxn/neon/communicator_new.c +++ b/pgxn/neon/communicator_new.c @@ -1358,19 +1358,12 @@ communicator_new_approximate_working_set_size_seconds(time_t duration, bool rese /* - * Return an array of LfcStatsEntrys, terminated by an entry with NULL name + * Return an array of LfcStatsEntrys */ LfcStatsEntry * -communicator_new_get_lfc_stats(void) +communicator_new_get_lfc_stats(uint32 *num_entries) { - LfcStatsEntry *entries; - int i = 0; - // TODO -#define NUM_ENTRIES 0 - entries = palloc(sizeof(LfcStatsEntry) * (NUM_ENTRIES + 1)); - entries[i++] = (LfcStatsEntry) { NULL, false, 0 }; - Assert(i <= NUM_ENTRIES); - - return entries; + *num_entries = 0; + return NULL; } diff --git a/pgxn/neon/communicator_new.h b/pgxn/neon/communicator_new.h index 9ec762f479..d3d4da20d5 100644 --- a/pgxn/neon/communicator_new.h +++ b/pgxn/neon/communicator_new.h @@ -61,6 +61,6 @@ extern void communicator_new_update_cached_rel_size(NRelFileInfo rinfo, ForkNumb /* other functions */ extern int32 communicator_new_approximate_working_set_size_seconds(time_t duration, bool reset); extern FileCacheState *communicator_new_get_lfc_state(size_t max_entries); -extern LfcStatsEntry *communicator_new_get_lfc_stats(void); +extern LfcStatsEntry *communicator_new_get_lfc_stats(uint32 *num_entries); #endif /* COMMUNICATOR_NEW_H */ diff --git a/pgxn/neon/file_cache.c b/pgxn/neon/file_cache.c index 43aa420665..2096a39d5e 100644 --- a/pgxn/neon/file_cache.c +++ b/pgxn/neon/file_cache.c @@ -1535,40 +1535,40 @@ lfc_writev(NRelFileInfo rinfo, ForkNumber forkNum, BlockNumber blkno, } /* - * Return an array of LfcStatsEntrys, terminated by an entry with NULL name + * Return an array of LfcStatsEntrys */ LfcStatsEntry * -get_lfc_stats(void) +get_lfc_stats(uint32 *num_entries) { LfcStatsEntry *entries; - int i = 0; + int n = 0; #define NUM_ENTRIES 10 - entries = palloc(sizeof(LfcStatsEntry) * (NUM_ENTRIES + 1)); + entries = palloc(sizeof(LfcStatsEntry) * NUM_ENTRIES); - entries[i++] = (LfcStatsEntry) {"file_cache_chunk_size_pages", lfc_ctl == NULL, + entries[n++] = (LfcStatsEntry) {"file_cache_chunk_size_pages", lfc_ctl == NULL, lfc_ctl ? lfc_blocks_per_chunk : 0 }; - entries[i++] = (LfcStatsEntry) {"file_cache_misses", lfc_ctl == NULL, + entries[n++] = (LfcStatsEntry) {"file_cache_misses", lfc_ctl == NULL, lfc_ctl ? lfc_ctl->misses : 0}; - entries[i++] = (LfcStatsEntry) {"file_cache_hits", lfc_ctl == NULL, + entries[n++] = (LfcStatsEntry) {"file_cache_hits", lfc_ctl == NULL, lfc_ctl ? lfc_ctl->hits : 0 }; - entries[i++] = (LfcStatsEntry) {"file_cache_used", lfc_ctl == NULL, + entries[n++] = (LfcStatsEntry) {"file_cache_used", lfc_ctl == NULL, lfc_ctl ? lfc_ctl->used : 0 }; - entries[i++] = (LfcStatsEntry) {"file_cache_writes", lfc_ctl == NULL, + entries[n++] = (LfcStatsEntry) {"file_cache_writes", lfc_ctl == NULL, lfc_ctl ? lfc_ctl->writes : 0 }; - entries[i++] = (LfcStatsEntry) {"file_cache_size", lfc_ctl == NULL, + entries[n++] = (LfcStatsEntry) {"file_cache_size", lfc_ctl == NULL, lfc_ctl ? lfc_ctl->size : 0 }; - entries[i++] = (LfcStatsEntry) {"file_cache_used_pages", lfc_ctl == NULL, + entries[n++] = (LfcStatsEntry) {"file_cache_used_pages", lfc_ctl == NULL, lfc_ctl ? lfc_ctl->used_pages : 0 }; - entries[i++] = (LfcStatsEntry) {"file_cache_evicted_pages", lfc_ctl == NULL, + entries[n++] = (LfcStatsEntry) {"file_cache_evicted_pages", lfc_ctl == NULL, lfc_ctl ? lfc_ctl->evicted_pages : 0 }; - entries[i++] = (LfcStatsEntry) {"file_cache_limit", lfc_ctl == NULL, + entries[n++] = (LfcStatsEntry) {"file_cache_limit", lfc_ctl == NULL, lfc_ctl ? lfc_ctl->limit : 0 }; - entries[i++] = (LfcStatsEntry) {"file_cache_chunks_pinned", lfc_ctl == NULL, + entries[n++] = (LfcStatsEntry) {"file_cache_chunks_pinned", lfc_ctl == NULL, lfc_ctl ? lfc_ctl->pinned : 0 }; - entries[i++] = (LfcStatsEntry) { NULL, false, 0 }; - Assert(i <= NUM_ENTRIES); + Assert(n <= NUM_ENTRIES); + *num_entries = n; return entries; } diff --git a/pgxn/neon/file_cache.h b/pgxn/neon/file_cache.h index c3c6611874..d6ada4c6fb 100644 --- a/pgxn/neon/file_cache.h +++ b/pgxn/neon/file_cache.h @@ -45,7 +45,7 @@ extern bool lfc_prefetch(NRelFileInfo rinfo, ForkNumber forknum, BlockNumber blk extern FileCacheState* lfc_get_state(size_t max_entries); extern int32 lfc_approximate_working_set_size_seconds(time_t duration, bool reset); -extern LfcStatsEntry *get_lfc_stats(void); +extern LfcStatsEntry *get_lfc_stats(uint32 *num_entries); static inline bool lfc_read(NRelFileInfo rinfo, ForkNumber forkNum, BlockNumber blkno, diff --git a/pgxn/neon/neon.c b/pgxn/neon/neon.c index 650394c8b8..d28aeed879 100644 --- a/pgxn/neon/neon.c +++ b/pgxn/neon/neon.c @@ -720,18 +720,18 @@ neon_get_lfc_stats(PG_FUNCTION_ARGS) #define NUM_NEON_GET_STATS_COLS 2 ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo; LfcStatsEntry *entries; - LfcStatsEntry *entry; + uint32 num_entries; InitMaterializedSRF(fcinfo, 0); if (neon_use_communicator_worker) - entries = communicator_new_get_lfc_stats(); + entries = communicator_new_get_lfc_stats(&num_entries); else - entries = get_lfc_stats(); + entries = get_lfc_stats(&num_entries); - entry = entries; - while (entry->metric_name != NULL) + for (uint32 i = 0; i < num_entries; i++) { + LfcStatsEntry *entry = &entries[i]; Datum values[NUM_NEON_GET_STATS_COLS]; bool nulls[NUM_NEON_GET_STATS_COLS]; @@ -739,7 +739,6 @@ neon_get_lfc_stats(PG_FUNCTION_ARGS) nulls[1] = entry->isnull; values[1] = Int64GetDatum(entry->isnull ? 0 : entry->value); tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls); - entry++; } PG_RETURN_VOID();