Skip to content

Commit

Permalink
Allow to join empty safekeeper to existing cluster (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
petuhovskiy authored and tristan957 committed Nov 8, 2023
1 parent 55c0ac5 commit 66376f3
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/backend/replication/walproposer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1319,6 +1319,34 @@ SendProposerElected(Safekeeper *sk)
{
/* safekeeper is empty or no common point, start from the beginning */
sk->startStreamingAt = propTermHistory.entries[0].lsn;

if (sk->startStreamingAt < truncateLsn)
{
/*
* There's a gap between the WAL starting point and a truncateLsn,
* which can't appear in a normal working cluster. That gap means
* that all safekeepers reported that they have persisted WAL up
* to the truncateLsn before, but now current safekeeper tells
* otherwise.
*
* Also we have a special condition here, which is empty safekeeper
* with no history. In combination with a gap, that can happen when
* we introduce a new safekeeper to the cluster. This is a rare case,
* which is triggered manually for now, and should be treated with
* care.
*/

/*
* truncateLsn will not change without ack from current safekeeper,
* and it's aligned to the WAL record, so we can safely start
* streaming from this point.
*/
sk->startStreamingAt = truncateLsn;

elog(WARNING, "empty safekeeper joined cluster as %s:%s, historyStart=%X/%X, sk->startStreamingAt=%X/%X",
sk->host, sk->port, LSN_FORMAT_ARGS(propTermHistory.entries[0].lsn),
LSN_FORMAT_ARGS(sk->startStreamingAt));
}
}
else
{
Expand Down

0 comments on commit 66376f3

Please sign in to comment.