@@ -193,9 +193,9 @@ feTimestampDifference(int64 start_time, int64 stop_time,
193
193
194
194
static char const * const MtmReplicationModeName [] =
195
195
{
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 */
199
199
};
200
200
201
201
static void
@@ -206,7 +206,7 @@ pglogical_receiver_main(Datum main_arg)
206
206
PQExpBuffer query ;
207
207
PGconn * conn ;
208
208
PGresult * res ;
209
- MtmSlotMode mode ;
209
+ MtmReplicationMode mode ;
210
210
211
211
ByteBuffer buf ;
212
212
XLogRecPtr originStartPos = 0 ;
@@ -251,7 +251,7 @@ pglogical_receiver_main(Datum main_arg)
251
251
* Druing recovery we need to open only one replication slot from which node should receive all transactions.
252
252
* Slots at other nodes should be removed
253
253
*/
254
- mode = MtmReceiverSlotMode (nodeId );
254
+ mode = MtmGetReplicationMode (nodeId );
255
255
count = Mtm -> recoveryCount ;
256
256
257
257
/* Establish connection to remote server */
@@ -264,14 +264,19 @@ pglogical_receiver_main(Datum main_arg)
264
264
}
265
265
266
266
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 */
269
269
appendPQExpBuffer (query , "DROP_REPLICATION_SLOT \"%s\"" , slotName );
270
270
res = PQexec (conn , query -> data );
271
271
PQclear (res );
272
272
resetPQExpBuffer (query );
273
273
}
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
+ {
275
280
appendPQExpBuffer (query , "CREATE_REPLICATION_SLOT \"%s\" LOGICAL \"%s\"" , slotName , MULTIMASTER_NAME );
276
281
res = PQexec (conn , query -> data );
277
282
if (PQresultStatus (res ) != PGRES_TUPLES_OK )
@@ -291,24 +296,28 @@ pglogical_receiver_main(Datum main_arg)
291
296
}
292
297
293
298
/* 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 ;
307
301
} 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 ();
310
320
}
311
- CommitTransactionCommand ();
312
321
313
322
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')" ,
314
323
slotName ,
0 commit comments