From: Andrey Borodin =0A= Date: Mon, 28 Aug 2017 10:21:53 +0500=0A= Subject: [PATCH] hooks to watch for changed pages=0A= =0A= ---=0A= src/backend/access/transam/xlog.c | 14 ++++++++++++++=0A= src/backend/access/transam/xloginsert.c | 19 +++++++++++++++++++=0A= src/include/access/xloginsert.h | 24 ++++++++++++++++++++++++=0A= 3 files changed, 57 insertions(+)=0A= =0A= diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam= /xlog.c=0A= index df4843f409..f18b457cc3 100644=0A= --- a/src/backend/access/transam/xlog.c=0A= +++ b/src/backend/access/transam/xlog.c=0A= @@ -926,6 +926,9 @@ static void WALInsertLockAcquireExclusive(void);=0A= static void WALInsertLockRelease(void);=0A= static void WALInsertLockUpdateInsertingAt(XLogRecPtr insertingAt);=0A= =20=0A= +/* Hook for plugins to get notified during the end of segment */=0A= +PGDLLIMPORT wal_switch_hook_type wal_switch_hook =3D NULL;=0A= +=0A= /*=0A= * Insert an XLOG record represented by an already-constructed chain of da= ta=0A= * chunks. This is a low-level routine; to construct the WAL record heade= r=0A= @@ -7024,6 +7027,7 @@ StartupXLOG(void)=0A= do=0A= {=0A= bool switchedTLI =3D false;=0A= + int nblock;=0A= =20=0A= #ifdef WAL_DEBUG=0A= if (XLOG_DEBUG ||=0A= @@ -7186,6 +7190,16 @@ StartupXLOG(void)=0A= /* Pop the error context stack */=0A= error_context_stack =3D errcallback.previous;=0A= =20=0A= + if (xlog_insert_buffer_hook)=0A= + for(nblock =3D 0; nblock < xlogreader->max_block_id; nblock++)=0A= + {=0A= + if(xlogreader->blocks[nblock].forknum =3D=3D MAIN_FORKNUM)=0A= + {=0A= + xlog_insert_buffer_hook(xlogreader->blocks[nblock].blkno,=0A= + xlogreader->blocks[nblock].rnode, true);=0A= + }=0A= + }=0A= +=0A= /*=0A= * Update lastReplayedEndRecPtr after this record has been=0A= * successfully replayed.=0A= diff --git a/src/backend/access/transam/xloginsert.c b/src/backend/access/t= ransam/xloginsert.c=0A= index 3af03ecdb1..2f6d52dc49 100644=0A= --- a/src/backend/access/transam/xloginsert.c=0A= +++ b/src/backend/access/transam/xloginsert.c=0A= @@ -112,6 +112,9 @@ static XLogRecData *XLogRecordAssemble(RmgrId rmid, uin= t8 info,=0A= static bool XLogCompressBackupBlock(char *page, uint16 hole_offset,=0A= uint16 hole_length, char *dest, uint16 *dlen);=0A= =20=0A= +/* Hook for plugins to get control at the beginning of insertion xlog */= =0A= +PGDLLIMPORT xlog_begin_insert_hook_type xlog_begin_insert_hook =3D NULL;= =0A= +=0A= /*=0A= * Begin constructing a WAL record. This must be called before the=0A= * XLogRegister* functions and XLogInsert().=0A= @@ -131,6 +134,8 @@ XLogBeginInsert(void)=0A= elog(ERROR, "XLogBeginInsert was already called");=0A= =20=0A= begininsert_called =3D true;=0A= + if(xlog_begin_insert_hook)=0A= + xlog_begin_insert_hook();=0A= }=0A= =20=0A= /*=0A= @@ -205,6 +210,9 @@ XLogResetInsertion(void)=0A= begininsert_called =3D false;=0A= }=0A= =20=0A= +/* Hook for plugins to get control in during page insertion into xlog */= =0A= +PGDLLIMPORT xlog_insert_buffer_hook_type xlog_insert_buffer_hook =3D NULL;= =0A= +=0A= /*=0A= * Register a reference to a buffer with the WAL record being constructed.= =0A= * This must be called for every page that the WAL-logged operation modifi= es.=0A= @@ -256,6 +264,10 @@ XLogRegisterBuffer(uint8 block_id, Buffer buffer, uint= 8 flags)=0A= #endif=0A= =20=0A= regbuf->in_use =3D true;=0A= + if (xlog_insert_buffer_hook && regbuf->forkno =3D=3D MAIN_FORKNUM)=0A= + {=0A= + xlog_insert_buffer_hook(regbuf->block, regbuf->rnode, false);=0A= + }=0A= }=0A= =20=0A= /*=0A= @@ -400,6 +412,9 @@ XLogSetRecordFlags(uint8 flags)=0A= curinsert_flags =3D flags;=0A= }=0A= =20=0A= +/* Hook for plugins to get control at the end of insertion of xlog record = */=0A= +PGDLLIMPORT xlog_end_insert_hook_type xlog_end_insert_hook =3D NULL;=0A= +=0A= /*=0A= * Insert an XLOG record having the specified RMID and info bytes, with th= e=0A= * body of the record being the data and buffer references registered earl= ier=0A= @@ -438,6 +453,8 @@ XLogInsert(RmgrId rmid, uint8 info)=0A= if (IsBootstrapProcessingMode() && rmid !=3D RM_XLOG_ID)=0A= {=0A= XLogResetInsertion();=0A= + if (xlog_end_insert_hook)=0A= + xlog_end_insert_hook(false);=0A= EndPos =3D SizeOfXLogLongPHD; /* start of 1st chkpt record */=0A= return EndPos;=0A= }=0A= @@ -463,6 +480,8 @@ XLogInsert(RmgrId rmid, uint8 info)=0A= } while (EndPos =3D=3D InvalidXLogRecPtr);=0A= =20=0A= XLogResetInsertion();=0A= + if (xlog_end_insert_hook)=0A= + xlog_end_insert_hook(true);=0A= =20=0A= return EndPos;=0A= }=0A= diff --git a/src/include/access/xloginsert.h b/src/include/access/xloginser= t.h=0A= index 174c88677f..72f7e2e722 100644=0A= --- a/src/include/access/xloginsert.h=0A= +++ b/src/include/access/xloginsert.h=0A= @@ -58,4 +58,28 @@ extern XLogRecPtr XLogSaveBufferForHint(Buffer buffer, b= ool buffer_std);=0A= =20=0A= extern void InitXLogInsert(void);=0A= =20=0A= +/* Hook for plugins to get control in during page insertion into xlog */= =0A= +typedef void (*xlog_insert_buffer_hook_type) (BlockNumber block_number, Re= lFileNode rel, bool recovery);=0A= +=0A= +/* in xloginsert.c */=0A= +extern PGDLLIMPORT xlog_insert_buffer_hook_type xlog_insert_buffer_hook;= =0A= +=0A= +/* Hook for plugins to get control at the beginning of insertion xlog */= =0A= +typedef void (*xlog_begin_insert_hook_type) ();=0A= +=0A= +/* in xloginsert.c */=0A= +extern PGDLLIMPORT xlog_begin_insert_hook_type xlog_begin_insert_hook;=0A= +=0A= +/* Hook for plugins to get control at the end of insertion of xlog record = */=0A= +typedef void (*xlog_end_insert_hook_type) (bool inserted);=0A= +=0A= +/* in xloginsert.c */=0A= +extern PGDLLIMPORT xlog_end_insert_hook_type xlog_end_insert_hook;=0A= +=0A= +/* Hook for plugins to get notified during the end of segment */=0A= +typedef void (*wal_switch_hook_type) (XLogRecPtr EndPos);=0A= +=0A= +/* in xlog.c */=0A= +extern PGDLLIMPORT wal_switch_hook_type wal_switch_hook;=0A= +=0A= #endif /* XLOGINSERT_H */=0A= --=20=0A= 2.11.0 (Apple Git-81)=0A= =0A= --Apple-Mail=_CD5763FB-6F6E-4B94-84CA-A1AA2682E0EF Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers --Apple-Mail=_CD5763FB-6F6E-4B94-84CA-A1AA2682E0EF--