From 668e3e4a11129675c19b20ed825978c1e0ed32a4 Mon Sep 17 00:00:00 2001 From: Harry Hao Date: Wed, 16 Mar 2022 13:20:37 +0800 Subject: [PATCH] Patched CreateRestartPoint to reproduce invalid checkpoint at startup. Sleep before checking ControlFile->state at CreateRestartPoint, to increase the chance it changed to DB_IN_PRODUCTION by promotion. If that happens, the ControlFile->checkPoint is stale and invalid. If that was a fast promotion, the post-recovery checkpoint can be skipped if crash happens, then the database will not recover. Also added chaos_sigsegv to simulate a crash, and some logs to show the timing of restartpoint, promotion and the crash. --- src/backend/access/transam/xlog.c | 10 +++++++++- src/test/regress/regress.c | 9 +++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 0d2bd7a357..379425b23d 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -5723,12 +5723,14 @@ PerformRecoveryXLogAction(void) * checkpoint later anyway, just for safety. */ CreateEndOfRecoveryRecord(); + ereport(WARNING, errmsg("TEST: fast promoted")); } else { RequestCheckpoint(CHECKPOINT_END_OF_RECOVERY | CHECKPOINT_IMMEDIATE | CHECKPOINT_WAIT); + ereport(WARNING, errmsg("TEST: normal promoted")); } return promoted; @@ -6991,6 +6993,12 @@ CreateRestartPoint(int flags) */ PriorRedoPtr = ControlFile->checkPointCopy.redo; + /* + * Sleep to increase chance state become DB_IN_PRODUCTION when promoted. + */ + ereport(WARNING, errmsg("TEST: restartpoint sleep before check state")); + pg_usleep(5000000L); + ereport(WARNING, errmsg("TEST: restartpoint state=%d", ControlFile->state)); /* * Update pg_control, using current time. Check that it still shows * DB_IN_ARCHIVE_RECOVERY state and an older checkpoint, else do nothing; @@ -7076,7 +7084,7 @@ CreateRestartPoint(int flags) */ if (!RecoveryInProgress()) replayTLI = XLogCtl->InsertTimeLineID; - + RemoveOldXlogFiles(_logSegNo, RedoRecPtr, endptr, replayTLI); /* diff --git a/src/test/regress/regress.c b/src/test/regress/regress.c index 0802fb9136..ad9cbea762 100644 --- a/src/test/regress/regress.c +++ b/src/test/regress/regress.c @@ -1216,3 +1216,12 @@ binary_coercible(PG_FUNCTION_ARGS) PG_RETURN_BOOL(IsBinaryCoercible(srctype, targettype)); } + +PG_FUNCTION_INFO_V1(chaos_sigsegv); +Datum +chaos_sigsegv(PG_FUNCTION_ARGS) +{ + char *p = NULL; + *p = 0; + PG_RETURN_VOID(); +} -- 2.30.1