v4-0003-Add-checkpoint_create_hook.patch
text/x-patch
Filename: v4-0003-Add-checkpoint_create_hook.patch
Type: text/x-patch
Part: 3
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: format-patch
Series: patch v4-0003
Subject: Add checkpoint_create_hook
| File | + | − |
|---|---|---|
| src/backend/access/transam/xlog.c | 5 | 0 |
| src/include/access/xlog.h | 4 | 0 |
From 01d76e69d1e0b2018f72160ef8873c4997f42030 Mon Sep 17 00:00:00 2001
From: Tristan Partin <tristan@neon.tech>
Date: Fri, 13 Oct 2023 13:57:18 -0500
Subject: [PATCH v4 3/6] Add checkpoint_create_hook
Allows an extension to hook into CheckPointCreate().
---
src/backend/access/transam/xlog.c | 5 +++++
src/include/access/xlog.h | 4 ++++
2 files changed, 9 insertions(+)
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 799fc739e18..cdd6eff2fd5 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -208,6 +208,8 @@ const struct config_enum_entry archive_mode_options[] = {
*/
CheckpointStatsData CheckpointStats;
+checkpoint_create_hook_type checkpoint_create_hook = NULL;
+
/*
* During recovery, lastFullPageWrites keeps track of full_page_writes that
* the replayed WAL records indicate. It's initialized with full_page_writes
@@ -7173,6 +7175,9 @@ CreateCheckPoint(int flags)
*/
END_CRIT_SECTION();
+ if (checkpoint_create_hook != NULL)
+ checkpoint_create_hook(&checkPoint);
+
/*
* In some cases there are groups of actions that must all occur on one
* side or the other of a checkpoint record. Before flushing the
diff --git a/src/include/access/xlog.h b/src/include/access/xlog.h
index d313099c027..8aab37ef52d 100644
--- a/src/include/access/xlog.h
+++ b/src/include/access/xlog.h
@@ -13,6 +13,7 @@
#include "access/xlogbackup.h"
#include "access/xlogdefs.h"
+#include "catalog/pg_control.h"
#include "datatype/timestamp.h"
#include "lib/stringinfo.h"
#include "nodes/pg_list.h"
@@ -59,6 +60,9 @@ extern PGDLLIMPORT int wal_decode_buffer_size;
extern PGDLLIMPORT int CheckPointSegments;
+typedef void (*checkpoint_create_hook_type) (const CheckPoint *);
+extern PGDLLIMPORT checkpoint_create_hook_type checkpoint_create_hook;
+
/* Archive modes */
typedef enum ArchiveMode
{
--
2.47.2