@@ -193,9 +193,9 @@ feTimestampDifference(int64 start_time, int64 stop_time,
193193
194194static char const * const MtmReplicationModeName [] =
195195{
196- "recovered" , /* SLOT_CREATE_NEW: recovery of node is completed so drop old slot and restart replication from the current position in WAL */
197- "recovery" , /* SLOT_OPEN_EXISTED: perform recorvery of the node by applying all data from theslot from specified point */
198- "normal" /* SLOT_OPEN_ALWAYS: normal mode: use existed slot or create new one and start receiving data from it from the specified position */
196+ "recovered" , /* recovery of node is completed so drop old slot and restart replication from the current position in WAL */
197+ "recovery" , /* perform recorvery of the node by applying all data from theslot from specified point */
198+ "normal" /* normal mode: use existed slot or create new one and start receiving data from it from the specified position */
199199};
200200
201201static void
@@ -206,7 +206,7 @@ pglogical_receiver_main(Datum main_arg)
206206 PQExpBuffer query ;
207207 PGconn * conn ;
208208 PGresult * res ;
209- MtmSlotMode mode ;
209+ MtmReplicationMode mode ;
210210
211211 ByteBuffer buf ;
212212 XLogRecPtr originStartPos = 0 ;
@@ -251,7 +251,7 @@ pglogical_receiver_main(Datum main_arg)
251251 * Druing recovery we need to open only one replication slot from which node should receive all transactions.
252252 * Slots at other nodes should be removed
253253 */
254- mode = MtmReceiverSlotMode (nodeId );
254+ mode = MtmGetReplicationMode (nodeId );
255255 count = Mtm -> recoveryCount ;
256256
257257 /* Establish connection to remote server */
@@ -264,14 +264,19 @@ pglogical_receiver_main(Datum main_arg)
264264 }
265265
266266 query = createPQExpBuffer ();
267-
268- if (mode == SLOT_CREATE_NEW ) {
267+ #if 1 /* Do we need to recretate slot ? */
268+ if (mode == REPLMODE_RECOVERED ) { /* recreate slot */
269269 appendPQExpBuffer (query , "DROP_REPLICATION_SLOT \"%s\"" , slotName );
270270 res = PQexec (conn , query -> data );
271271 PQclear (res );
272272 resetPQExpBuffer (query );
273273 }
274- if (mode != SLOT_OPEN_EXISTED ) {
274+ #endif
275+ /* My original assumption was that we can perfrom recovery only fromm existed slot,
276+ * but unfortunately looks like slots can "disapear" together with WAL-sender.
277+ * So let's try to recreate slot always. */
278+ /* if (mode != REPLMODE_REPLICATION) */
279+ {
275280 appendPQExpBuffer (query , "CREATE_REPLICATION_SLOT \"%s\" LOGICAL \"%s\"" , slotName , MULTIMASTER_NAME );
276281 res = PQexec (conn , query -> data );
277282 if (PQresultStatus (res ) != PGRES_TUPLES_OK )
@@ -291,24 +296,28 @@ pglogical_receiver_main(Datum main_arg)
291296 }
292297
293298 /* Start logical replication at specified position */
294- StartTransactionCommand ();
295- originName = psprintf (MULTIMASTER_SLOT_PATTERN , nodeId );
296- originId = replorigin_by_name (originName , true);
297- if (originId == InvalidRepOriginId ) {
298- originId = replorigin_create (originName );
299- /*
300- * We are just creating new replication slot.
301- * It is assumed that state of local and remote nodes is the same at this moment.
302- * Them are either empty, either new node is synchronized using base_backup.
303- * So we assume that LSNs are the same for local and remote node
304- */
305- originStartPos = Mtm -> status == MTM_RECOVERY ? GetXLogInsertRecPtr () : 0 ;
306- MTM_LOG1 ("Start logical receiver at position %lx from node %d" , originStartPos , nodeId );
299+ if (mode == REPLMODE_RECOVERED ) {
300+ originStartPos = 0 ;
307301 } else {
308- originStartPos = replorigin_get_progress (originId , false);
309- MTM_LOG1 ("Restart logical receiver at position %lx with origin=%d from node %d" , originStartPos , originId , nodeId );
302+ StartTransactionCommand ();
303+ originName = psprintf (MULTIMASTER_SLOT_PATTERN , nodeId );
304+ originId = replorigin_by_name (originName , true);
305+ if (originId == InvalidRepOriginId ) {
306+ originId = replorigin_create (originName );
307+ /*
308+ * We are just creating new replication slot.
309+ * It is assumed that state of local and remote nodes is the same at this moment.
310+ * Them are either empty, either new node is synchronized using base_backup.
311+ * So we assume that LSNs are the same for local and remote node
312+ */
313+ originStartPos = Mtm -> status == MTM_RECOVERY ? GetXLogInsertRecPtr () : 0 ;
314+ MTM_LOG1 ("Start logical receiver at position %lx from node %d" , originStartPos , nodeId );
315+ } else {
316+ originStartPos = replorigin_get_progress (originId , false);
317+ MTM_LOG1 ("Restart logical receiver at position %lx with origin=%d from node %d" , originStartPos , originId , nodeId );
318+ }
319+ CommitTransactionCommand ();
310320 }
311- CommitTransactionCommand ();
312321
313322 appendPQExpBuffer (query , "START_REPLICATION SLOT \"%s\" LOGICAL %x/%x (\"startup_params_format\" '1', \"max_proto_version\" '%d', \"min_proto_version\" '%d', \"forward_changesets\" '1', \"mtm_replication_mode\" '%s')" ,
314323 slotName ,
0 commit comments