This is an automated email from the ASF dual-hosted git repository.
maxyang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
The following commit(s) were added to refs/heads/main by this push:
new 8da76608f4 Add hooks for extensiona, allow custom Table-AM to
implement custom xlog (#848)
8da76608f4 is described below
commit 8da76608f496d12e978720db4e20bd58ca50d363
Author: Xun Gong <[email protected]>
AuthorDate: Wed Jan 8 09:39:12 2025 +0800
Add hooks for extensiona, allow custom Table-AM to implement custom xlog
(#848)
Add two hook functions for extension, make custom Table-Am can hook in xlog
redo
typedef void (*ConsistencyCheck_hook_type) (void);
extern PGDLLIMPORT ConsistencyCheck_hook_type xlog_check_consistency_hook;
typedef void (*XLOGDropDatabase_hook_type)(Oid dbid);
extern XLOGDropDatabase_hook_type XLOGDropDatabase_hook;
In cloudberrydb, when mirror instance redo xlog, StartupXLog will start
replaying from the
latest checkpoint's REDO location in pg_control. When processing the xlog
of data writing,
we need to write the data in xlog into the data file, but the entire db
directory may be deleted
due to the drop database xlog that has been replayed last time.
XLogDropDatabase and XLogCheckInvalidPages limits the table to be organized
in page mode.
For custom Table-Am, their data organization is not necessarily in page
mode.
We need to provide a hook for the implementation of custom wal log to
handle this situation.
master:
\c testdb
t1: create table t1(a int);
t2: select pg_sleep(checkpoint_timeout); --wait checkpoint_timeout, do
checkpoint on mirror;
t3: insert into t1 select generate_series(1,10);
t4: dropdb testdb
t5: pkill postgres -- mirror should redo dropdb and not do next checkpoint
on mirror
then we restart the cluster, mirror will recovery restart at the xlog of
insert sql, but the data path of testdb has been deleted
---
src/backend/access/transam/xlog.c | 8 ++++++++
src/backend/access/transam/xlogutils.c | 4 ++++
src/include/access/xlog.h | 19 +++++++++++++++++++
3 files changed, 31 insertions(+)
diff --git a/src/backend/access/transam/xlog.c
b/src/backend/access/transam/xlog.c
index 20a8fbbe0b..15ea696d1c 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -346,6 +346,10 @@ bool StandbyMode = false;
Startup_hook_type Startup_hook = NULL;
+ConsistencyCheck_hook_type xlog_check_consistency_hook = NULL;
+
+XLOGDropDatabase_hook_type XLOGDropDatabase_hook = NULL;
+
/*
* if recoveryStopsBefore/After returns true, it saves information of the stop
* point here
@@ -8634,6 +8638,10 @@ CheckRecoveryConsistency(void)
*/
XLogCheckInvalidPages();
+ if (xlog_check_consistency_hook) {
+ xlog_check_consistency_hook();
+ }
+
reachedConsistency = true;
ereport(LOG,
(errmsg("consistent recovery state reached at
%X/%X",
diff --git a/src/backend/access/transam/xlogutils.c
b/src/backend/access/transam/xlogutils.c
index fe369ebbd8..a5f50caab0 100644
--- a/src/backend/access/transam/xlogutils.c
+++ b/src/backend/access/transam/xlogutils.c
@@ -674,6 +674,10 @@ XLogDropDatabase(Oid dbid)
smgrcloseall();
forget_invalid_pages_db(dbid);
+
+ if (XLOGDropDatabase_hook) {
+ XLOGDropDatabase_hook(dbid);
+ }
}
/*
diff --git a/src/include/access/xlog.h b/src/include/access/xlog.h
index cec7f91a3b..933a19071b 100644
--- a/src/include/access/xlog.h
+++ b/src/include/access/xlog.h
@@ -166,6 +166,25 @@ extern int FileEncryptionEnabled;
typedef void (*Startup_hook_type) (void);
extern PGDLLIMPORT Startup_hook_type Startup_hook;
+/* Hook for extensions to do consistency check */
+typedef void (*ConsistencyCheck_hook_type) (void);
+extern PGDLLIMPORT ConsistencyCheck_hook_type xlog_check_consistency_hook;
+
+/* Hook for extensions to do drop database xlog record
+ *
+ * For custom wal log, when mirror redo xlog, since each restart will start
+ * replaying from the latest checkpoint's REDO location in pg_control, when
+ * processing the xlog of data writing, the entire db directory may be deleted
+ * due to the drop database xlog that has been replayed last time. We need to
+ * provide a hook for the implementation of custom wal log to handle this
situation.
+ *
+ * Why can't forget_invalid_pages_db meet the requirements?
+ * Because forget_invalid_pages_db limits the table to be organized in page
mode.
+ * For custom Table-Am, their data organization is not necessarily in page
mode.
+ */
+typedef void (*XLOGDropDatabase_hook_type)(Oid dbid);
+extern XLOGDropDatabase_hook_type XLOGDropDatabase_hook;
+
/* Archive modes */
typedef enum ArchiveMode
{
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]