@@ -865,10 +865,13 @@ void MtmSendNotificationMessage(MtmTransState* ts, MtmMessageCode cmd)
865865
866866void MtmJoinTransaction (GlobalTransactionId * gtid , csn_t globalSnapshot )
867867{
868- MtmLock (LW_EXCLUSIVE );
869- MtmSyncClock (globalSnapshot );
870- MtmUnlock ();
871-
868+ if (globalSnapshot != INVALID_CSN ) {
869+ MtmLock (LW_EXCLUSIVE );
870+ MtmSyncClock (globalSnapshot );
871+ MtmUnlock ();
872+ } else {
873+ globalSnapshot = MtmTx .snapshot ;
874+ }
872875 if (!TransactionIdIsValid (gtid -> xid )) {
873876 /* In case of recovery InvalidTransactionId is passed */
874877 Assert (Mtm -> status == MTM_RECOVERY );
@@ -1877,6 +1880,14 @@ void MtmDropNode(int nodeId, bool dropSlot)
18771880 }
18781881 }
18791882}
1883+ static void
1884+ MtmOnProcExit (int code , Datum arg )
1885+ {
1886+ if (MtmReplicationNodeId >= 0 ) {
1887+ elog (WARNING , "WAL-sender to %d is terminated" , MtmReplicationNodeId );
1888+ MtmOnNodeDisconnect (MtmReplicationNodeId );
1889+ }
1890+ }
18801891
18811892static void
18821893MtmReplicationStartupHook (struct PGLogicalStartupHookArgs * args )
@@ -1923,13 +1934,17 @@ MtmReplicationStartupHook(struct PGLogicalStartupHookArgs* args)
19231934 elog (NOTICE , "Node %d start logical replication to node %d in normal mode" , MtmNodeId , MtmReplicationNodeId );
19241935 }
19251936 MtmUnlock ();
1937+ on_proc_exit (MtmOnProcExit , 0 );
19261938}
19271939
19281940static void
19291941MtmReplicationShutdownHook (struct PGLogicalShutdownHookArgs * args )
19301942{
1931- elog (WARNING , "Logical replication to node %d is stopped" , MtmReplicationNodeId );
1932- MtmOnNodeDisconnect (MtmReplicationNodeId );
1943+ if (MtmReplicationNodeId >= 0 ) {
1944+ elog (WARNING , "Logical replication to node %d is stopped" , MtmReplicationNodeId );
1945+ MtmOnNodeDisconnect (MtmReplicationNodeId );
1946+ MtmReplicationNodeId = -1 ; /* defuse on_proc_exit hook */
1947+ }
19331948}
19341949
19351950static bool
@@ -2167,7 +2182,8 @@ static bool MtmRunUtilityStmt(PGconn* conn, char const* sql, char **errmsg)
21672182 return ret ;
21682183}
21692184
2170- void MtmNoticeReceiver (void * i , const PGresult * res )
2185+ static void
2186+ MtmNoticeReceiver (void * i , const PGresult * res )
21712187{
21722188 char * notice = PQresultErrorMessage (res );
21732189 char * stripped_notice ;
0 commit comments