Skip to content

Commit

Permalink
Add PreCheckPointGuts function to sync replication state before start…
Browse files Browse the repository at this point in the history
… of shutdown checkpoint
  • Loading branch information
Konstantin Knizhnik committed Oct 11, 2023
1 parent 2269155 commit 166b8a0
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions src/backend/access/transam/xlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,7 @@ static void CreateEndOfRecoveryRecord(void);
static XLogRecPtr CreateOverwriteContrecordRecord(XLogRecPtr aborted_lsn,
XLogRecPtr missingContrecPtr,
TimeLineID newTLI);
static void PreCheckPointGuts(int flags);
static void CheckPointGuts(XLogRecPtr checkPointRedo, int flags);
static void KeepLogSeg(XLogRecPtr recptr, XLogSegNo *logSegNo);
static XLogRecPtr XLogGetReplicationSlotMinimumLSN(void);
Expand Down Expand Up @@ -6684,6 +6685,11 @@ CreateCheckPoint(int flags)
*/
SyncPreCheckpoint();

/*
* NEON: perform checkpiont action requiring write to the WAL before we determine the REDO pointer.
*/
PreCheckPointGuts(flags);

/*
* Use a critical section to force system panic if we have trouble.
*/
Expand Down Expand Up @@ -7191,6 +7197,28 @@ CreateOverwriteContrecordRecord(XLogRecPtr aborted_lsn, XLogRecPtr pagePtr,
return recptr;
}

static void
CheckPointReplicationState(void)
{
CheckPointRelationMap();
CheckPointReplicationSlots();
CheckPointSnapBuild();
CheckPointLogicalRewriteHeap();
CheckPointReplicationOrigin();
}

/*
* NEON: we use logical records to persist information of about slots, origins, relation map...
* If it is done inside shutdown checkpoint, then Postgres panics: "concurrent write-ahead log activity while database system is shutting down"
* So it before checkpoint REDO position is determined.
*/
static void
PreCheckPointGuts(int flags)
{
if (flags & CHECKPOINT_IS_SHUTDOWN)
CheckPointReplicationState();
}

/*
* Flush all data in shared memory to disk, and fsync
*
Expand All @@ -7200,18 +7228,8 @@ CreateOverwriteContrecordRecord(XLogRecPtr aborted_lsn, XLogRecPtr pagePtr,
static void
CheckPointGuts(XLogRecPtr checkPointRedo, int flags)
{
CheckPointRelationMap();
CheckPointReplicationSlots();
CheckPointSnapBuild();
CheckPointLogicalRewriteHeap();

/*
* NEON: FIXME: we use logical recortds to persist information of about origins,
* but writting in WAL during checkpoint at shutdown cause PANIC:
* "concurrent write-ahead log activity while database system is shutting down"
*/
if (!(flags & CHECKPOINT_IS_SHUTDOWN))
CheckPointReplicationOrigin();
CheckPointReplicationState();

/* Write out all dirty data in SLRUs and the main buffer pool */
TRACE_POSTGRESQL_BUFFER_CHECKPOINT_START(flags);
Expand Down

0 comments on commit 166b8a0

Please sign in to comment.