From 7ffcbfde9ae274fceca9601d11b97393c8414e36 Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Tue, 8 Apr 2025 12:03:56 +0300 Subject: [PATCH] refactor: Move LFC function prototypes to separate header file (#11458) Also, move the call to the lfc_init() function. It was weird to have it in libpagestore.c, when libpagestore.c otherwise had nothing to do with the LFC. Move it directly into _PG_init() --- pgxn/neon/file_cache.c | 2 +- pgxn/neon/file_cache.h | 52 ++++++++++++++++++++++++++++++++++++ pgxn/neon/libpagestore.c | 2 -- pgxn/neon/neon.c | 2 ++ pgxn/neon/neon.h | 10 +++++++ pgxn/neon/pagestore_client.h | 42 ----------------------------- pgxn/neon/pagestore_smgr.c | 1 + 7 files changed, 66 insertions(+), 45 deletions(-) create mode 100644 pgxn/neon/file_cache.h diff --git a/pgxn/neon/file_cache.c b/pgxn/neon/file_cache.c index 2505fcb847..8c2990e57a 100644 --- a/pgxn/neon/file_cache.c +++ b/pgxn/neon/file_cache.c @@ -21,7 +21,6 @@ #include "access/xlog.h" #include "funcapi.h" #include "miscadmin.h" -#include "pagestore_client.h" #include "common/hashfn.h" #include "pgstat.h" #include "port/pg_iovec.h" @@ -43,6 +42,7 @@ #include "hll.h" #include "bitmap.h" +#include "file_cache.h" #include "neon.h" #include "neon_lwlsncache.h" #include "neon_perf_counters.h" diff --git a/pgxn/neon/file_cache.h b/pgxn/neon/file_cache.h new file mode 100644 index 0000000000..849558b83d --- /dev/null +++ b/pgxn/neon/file_cache.h @@ -0,0 +1,52 @@ +/*------------------------------------------------------------------------- + * + * file_cache.h + * Local File Cache definitions + * + * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + *------------------------------------------------------------------------- + */ +#ifndef FILE_CACHE_h +#define FILE_CACHE_h + +#include "neon_pgversioncompat.h" + +/* GUCs */ +extern bool lfc_store_prefetch_result; + +/* functions for local file cache */ +extern void lfc_writev(NRelFileInfo rinfo, ForkNumber forkNum, + BlockNumber blkno, const void *const *buffers, + BlockNumber nblocks); +/* returns number of blocks read, with one bit set in *read for each */ +extern int lfc_readv_select(NRelFileInfo rinfo, ForkNumber forkNum, + BlockNumber blkno, void **buffers, + BlockNumber nblocks, bits8 *mask); + +extern bool lfc_cache_contains(NRelFileInfo rinfo, ForkNumber forkNum, + BlockNumber blkno); +extern int lfc_cache_containsv(NRelFileInfo rinfo, ForkNumber forkNum, + BlockNumber blkno, int nblocks, bits8 *bitmap); +extern void lfc_init(void); +extern bool lfc_prefetch(NRelFileInfo rinfo, ForkNumber forknum, BlockNumber blkno, + const void* buffer, XLogRecPtr lsn); + + +static inline bool +lfc_read(NRelFileInfo rinfo, ForkNumber forkNum, BlockNumber blkno, + void *buffer) +{ + bits8 rv = 0; + return lfc_readv_select(rinfo, forkNum, blkno, &buffer, 1, &rv) == 1; +} + +static inline void +lfc_write(NRelFileInfo rinfo, ForkNumber forkNum, BlockNumber blkno, + const void *buffer) +{ + return lfc_writev(rinfo, forkNum, blkno, &buffer, 1); +} + +#endif /* FILE_CACHE_H */ diff --git a/pgxn/neon/libpagestore.c b/pgxn/neon/libpagestore.c index 60b2249461..9ea708f29a 100644 --- a/pgxn/neon/libpagestore.c +++ b/pgxn/neon/libpagestore.c @@ -1475,6 +1475,4 @@ pg_init_libpagestore(void) } memset(page_servers, 0, sizeof(page_servers)); - - lfc_init(); } diff --git a/pgxn/neon/neon.c b/pgxn/neon/neon.c index 081025e2d5..69da83f3fb 100644 --- a/pgxn/neon/neon.c +++ b/pgxn/neon/neon.c @@ -29,6 +29,7 @@ #include "utils/guc_tables.h" #include "extension_server.h" +#include "file_cache.h" #include "neon.h" #include "neon_lwlsncache.h" #include "control_plane_connector.h" @@ -434,6 +435,7 @@ _PG_init(void) #endif pg_init_libpagestore(); + lfc_init(); pg_init_walproposer(); init_lwlsncache(); diff --git a/pgxn/neon/neon.h b/pgxn/neon/neon.h index e2fa136e37..a4339c9776 100644 --- a/pgxn/neon/neon.h +++ b/pgxn/neon/neon.h @@ -47,6 +47,16 @@ extern uint32 WAIT_EVENT_NEON_WAL_DL; #define WAIT_EVENT_NEON_WAL_DL WAIT_EVENT_WAL_READ #endif + +#define NEON_TAG "[NEON_SMGR] " +#define neon_log(tag, fmt, ...) ereport(tag, \ + (errmsg(NEON_TAG fmt, ##__VA_ARGS__), \ + errhidestmt(true), errhidecontext(true), errposition(0), internalerrposition(0))) +#define neon_shard_log(shard_no, tag, fmt, ...) ereport(tag, \ + (errmsg(NEON_TAG "[shard %d] " fmt, shard_no, ##__VA_ARGS__), \ + errhidestmt(true), errhidecontext(true), errposition(0), internalerrposition(0))) + + extern void pg_init_libpagestore(void); extern void pg_init_walproposer(void); extern void pagestore_smgr_init(void); diff --git a/pgxn/neon/pagestore_client.h b/pgxn/neon/pagestore_client.h index a2e3d57e47..6ddad21362 100644 --- a/pgxn/neon/pagestore_client.h +++ b/pgxn/neon/pagestore_client.h @@ -58,14 +58,6 @@ typedef struct #define messageTag(m) (((const NeonMessage *)(m))->tag) -#define NEON_TAG "[NEON_SMGR] " -#define neon_log(tag, fmt, ...) ereport(tag, \ - (errmsg(NEON_TAG fmt, ##__VA_ARGS__), \ - errhidestmt(true), errhidecontext(true), errposition(0), internalerrposition(0))) -#define neon_shard_log(shard_no, tag, fmt, ...) ereport(tag, \ - (errmsg(NEON_TAG "[shard %d] " fmt, shard_no, ##__VA_ARGS__), \ - errhidestmt(true), errhidecontext(true), errposition(0), internalerrposition(0))) - /* SLRUs downloadable from page server */ typedef enum { SLRU_CLOG, @@ -234,7 +226,6 @@ extern char *neon_timeline; extern char *neon_tenant; extern int32 max_cluster_size; extern int neon_protocol_version; -extern bool lfc_store_prefetch_result; extern shardno_t get_shard_number(BufferTag* tag); @@ -285,37 +276,4 @@ extern void set_cached_relsize(NRelFileInfo rinfo, ForkNumber forknum, BlockNumb extern void update_cached_relsize(NRelFileInfo rinfo, ForkNumber forknum, BlockNumber size); extern void forget_cached_relsize(NRelFileInfo rinfo, ForkNumber forknum); -/* functions for local file cache */ -extern void lfc_writev(NRelFileInfo rinfo, ForkNumber forkNum, - BlockNumber blkno, const void *const *buffers, - BlockNumber nblocks); -/* returns number of blocks read, with one bit set in *read for each */ -extern int lfc_readv_select(NRelFileInfo rinfo, ForkNumber forkNum, - BlockNumber blkno, void **buffers, - BlockNumber nblocks, bits8 *mask); - -extern bool lfc_cache_contains(NRelFileInfo rinfo, ForkNumber forkNum, - BlockNumber blkno); -extern int lfc_cache_containsv(NRelFileInfo rinfo, ForkNumber forkNum, - BlockNumber blkno, int nblocks, bits8 *bitmap); -extern void lfc_init(void); -extern bool lfc_prefetch(NRelFileInfo rinfo, ForkNumber forknum, BlockNumber blkno, - const void* buffer, XLogRecPtr lsn); - - -static inline bool -lfc_read(NRelFileInfo rinfo, ForkNumber forkNum, BlockNumber blkno, - void *buffer) -{ - bits8 rv = 0; - return lfc_readv_select(rinfo, forkNum, blkno, &buffer, 1, &rv) == 1; -} - -static inline void -lfc_write(NRelFileInfo rinfo, ForkNumber forkNum, BlockNumber blkno, - const void *buffer) -{ - return lfc_writev(rinfo, forkNum, blkno, &buffer, 1); -} - #endif /* PAGESTORE_CLIENT_H */ diff --git a/pgxn/neon/pagestore_smgr.c b/pgxn/neon/pagestore_smgr.c index eb8df11923..6d58f4f28f 100644 --- a/pgxn/neon/pagestore_smgr.c +++ b/pgxn/neon/pagestore_smgr.c @@ -65,6 +65,7 @@ #include "utils/timeout.h" #include "bitmap.h" +#include "file_cache.h" #include "neon.h" #include "neon_lwlsncache.h" #include "neon_perf_counters.h"