1
0
mirror of https://github.com/postgres/postgres.git synced 2025-10-25 13:17:41 +03:00

Enable logical slots to follow timeline switches

When decoding from a logical slot, it's necessary for xlog reading to be
able to read xlog from historical (i.e. not current) timelines;
otherwise, decoding fails after failover, because the archives are in
the historical timeline.  This is required to make "failover logical
slots" possible; it currently has no other use, although theoretically
it could be used by an extension that creates a slot on a standby and
continues to replay from the slot when the standby is promoted.

This commit includes a module in src/test/modules with functions to
manipulate the slots (which is not otherwise possible in SQL code) in
order to enable testing, and a new test in src/test/recovery to ensure
that the behavior is as expected.

Author: Craig Ringer
Reviewed-By: Oleksii Kliukin, Andres Freund, Petr Jelínek
This commit is contained in:
Alvaro Herrera
2016-03-30 20:07:05 -03:00
parent 3b02ea4f07
commit 24c5f1a103
16 changed files with 789 additions and 30 deletions

View File

@@ -27,6 +27,10 @@
#include "access/xlogrecord.h"
#ifndef FRONTEND
#include "nodes/pg_list.h"
#endif
typedef struct XLogReaderState XLogReaderState;
/* Function type definition for the read_page callback */
@@ -160,11 +164,25 @@ struct XLogReaderState
/* beginning of the WAL record being read. */
XLogRecPtr currRecPtr;
/* timeline to read it from, 0 if a lookup is required */
TimeLineID currTLI;
/*
* Safe point to read to in currTLI. If currTLI is historical, then this
* is set to the end of the last whole segment that contains that TLI;
* if currTLI is ThisTimeLineID, this is InvalidXLogRecPtr. This is *not*
* the tliSwitchPoint.
*/
XLogRecPtr currTLIValidUntil;
/* Buffer for current ReadRecord result (expandable) */
char *readRecordBuf;
uint32 readRecordBufSize;
#ifndef FRONTEND
/* cached timeline history, only available in backend */
List *timelineHistory;
#endif
/* Buffer to hold error message */
char *errormsg_buf;
};