On Mon, Feb 26, 2024 at 7:27 PM Daniel Gustafsson <dan...@yesql.se> wrote: > > > On 1 Jul 2020, at 10:36, Daniel Gustafsson <dan...@yesql.se> wrote: > > > >> On 27 Mar 2020, at 11:22, Haozhou Wang <haw...@pivotal.io> wrote: > > > >> We rebased this patch with the newest master. > > > > This patch now fails to build according to Travis: > > > > smgr.c: In function ‘smgrtruncate’: > > smgr.c:578:47: error: passing argument 4 of ‘smgrtruncate_hook’ makes > > integer from pointer without a cast [-Werror=int-conversion] > > (*smgrtruncate_hook)(reln, forknum, nforks, nblocks); > > ^ > > smgr.c:578:47: note: expected ‘BlockNumber {aka unsigned int}’ but argument > > is of type ‘BlockNumber * {aka unsigned int *}’ > > > > > > The warning is also present in the Windows build: > > > > src/backend/storage/smgr/smgr.c(578): warning C4047: 'function' : > > 'BlockNumber' differs in levels of indirection from 'BlockNumber *' > > [C:\projects\postgresql\postgres.vcxproj] > > src/backend/storage/smgr/smgr.c(578): warning C4024: 'smgrtruncate_hook' : > > different types for formal and actual parameter 4 > > [C:\projects\postgresql\postgres.vcxproj] > > 2 Warning(s) > > > > Marking the patch as Waiting for Author. > > As the thread has stalled and the above compilation issue hasn't been > addressed, I'm marking this entry Returned with Feedback. Feel free to open a > new entry when there is a fixed patch.
Hi, Looks that many hackers are happy with the original patch except that the original patch needs a simple rebase, though it has been 3 years. Shall we push forward this patch so that it can benefit extensions not only diskquota? The attachment is a rebased version of the original patch. > > cheers ./daniel > > >
From 6479e1ccc92c53468dc879d33fa1a93f66ae4521 Mon Sep 17 00:00:00 2001 From: Hubert Zhang <hubertzh...@apache.org> Date: Mon, 26 Feb 2024 19:24:43 +0800 Subject: [PATCH v8] Add smgr hooks to extend the logic of storage management One example is that these hooks could be used by diskquota extension to detect heap table change(create/extend/truncate/unlink). Co-authored-by: Haozhou Wang <haw...@pivotal.io> Co-authored-by: Hubert Zhang <hzh...@pivotal.io> Co-authored-by: Hao Wu <gfphoeni...@gmail.com> --- src/backend/storage/smgr/smgr.c | 21 +++++++++++++++++++++ src/include/storage/smgr.h | 16 ++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/backend/storage/smgr/smgr.c b/src/backend/storage/smgr/smgr.c index f7f7fe30b6..7992da84ce 100644 --- a/src/backend/storage/smgr/smgr.c +++ b/src/backend/storage/smgr/smgr.c @@ -142,6 +142,15 @@ static dlist_head unpinned_relns; static void smgrshutdown(int code, Datum arg); static void smgrdestroy(SMgrRelation reln); +/* + * Hook for plugins to extend smgr functions. + * for example, collect statistics from smgr functions + * via recording the active relfilenode information. + */ +smgrcreate_hook_type smgrcreate_hook = NULL; +smgrextend_hook_type smgrextend_hook = NULL; +smgrtruncate_hook_type smgrtruncate_hook = NULL; +smgrdounlinkall_hook_type smgrdounlinkall_hook = NULL; /* * smgrinit(), smgrshutdown() -- Initialize or shut down storage @@ -413,6 +422,9 @@ smgrexists(SMgrRelation reln, ForkNumber forknum) void smgrcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo) { + if (smgrcreate_hook) + (*smgrcreate_hook)(reln, forknum, isRedo); + smgrsw[reln->smgr_which].smgr_create(reln, forknum, isRedo); } @@ -471,6 +483,9 @@ smgrdounlinkall(SMgrRelation *rels, int nrels, bool isRedo) if (nrels == 0) return; + if (smgrdounlinkall_hook) + (*smgrdounlinkall_hook)(rels, nrels, isRedo); + /* * Get rid of any remaining buffers for the relations. bufmgr will just * drop them without bothering to write the contents. @@ -538,6 +553,9 @@ void smgrextend(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, const void *buffer, bool skipFsync) { + if (smgrextend_hook) + (*smgrextend_hook)(reln, forknum, blocknum, buffer, skipFsync); + smgrsw[reln->smgr_which].smgr_extend(reln, forknum, blocknum, buffer, skipFsync); @@ -706,6 +724,9 @@ smgrtruncate(SMgrRelation reln, ForkNumber *forknum, int nforks, BlockNumber *nb { int i; + if (smgrtruncate_hook) + (*smgrtruncate_hook)(reln, forknum, nforks, nblocks); + /* * Get rid of any buffers for the about-to-be-deleted blocks. bufmgr will * just drop them without bothering to write the contents. diff --git a/src/include/storage/smgr.h b/src/include/storage/smgr.h index 2b57addbdb..0ac1ed8f93 100644 --- a/src/include/storage/smgr.h +++ b/src/include/storage/smgr.h @@ -124,4 +124,20 @@ smgrwrite(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, smgrwritev(reln, forknum, blocknum, &buffer, 1, skipFsync); } +/* + * Hook for plugins to extend smgr functions. + * for example, collect statistics from smgr functions + * via recording the active relfilenode information. + */ +typedef void (*smgrcreate_hook_type)(SMgrRelation reln, ForkNumber forknum, bool isRedo); +extern PGDLLIMPORT smgrcreate_hook_type smgrcreate_hook; +typedef void (*smgrextend_hook_type)(SMgrRelation reln, ForkNumber forknum, + BlockNumber blocknum, const void *buffer, bool skipFsync); +extern PGDLLIMPORT smgrextend_hook_type smgrextend_hook; +typedef void (*smgrtruncate_hook_type)(SMgrRelation reln, ForkNumber *forknum, + int nforks, BlockNumber *nblocks); +extern PGDLLIMPORT smgrtruncate_hook_type smgrtruncate_hook; +typedef void (*smgrdounlinkall_hook_type)(SMgrRelation *rels, int nrels, bool isRedo); +extern PGDLLIMPORT smgrdounlinkall_hook_type smgrdounlinkall_hook; + #endif /* SMGR_H */ -- 2.43.2