Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit dc4fb75

Browse files
knizhnikkelvich
authored andcommitted
handle exit of wal-sender
1 parent 3cdb373 commit dc4fb75

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

multimaster.c

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -864,10 +864,13 @@ void MtmSendNotificationMessage(MtmTransState* ts, MtmMessageCode cmd)
864864

865865
void MtmJoinTransaction(GlobalTransactionId* gtid, csn_t globalSnapshot)
866866
{
867-
MtmLock(LW_EXCLUSIVE);
868-
MtmSyncClock(globalSnapshot);
869-
MtmUnlock();
870-
867+
if (globalSnapshot != INVALID_CSN) {
868+
MtmLock(LW_EXCLUSIVE);
869+
MtmSyncClock(globalSnapshot);
870+
MtmUnlock();
871+
} else {
872+
globalSnapshot = MtmTx.snapshot;
873+
}
871874
if (!TransactionIdIsValid(gtid->xid)) {
872875
/* In case of recovery InvalidTransactionId is passed */
873876
Assert(Mtm->status == MTM_RECOVERY);
@@ -1876,6 +1879,14 @@ void MtmDropNode(int nodeId, bool dropSlot)
18761879
}
18771880
}
18781881
}
1882+
static void
1883+
MtmOnProcExit(int code, Datum arg)
1884+
{
1885+
if (MtmReplicationNodeId >= 0) {
1886+
elog(WARNING, "WAL-sender to %d is terminated", MtmReplicationNodeId);
1887+
MtmOnNodeDisconnect(MtmReplicationNodeId);
1888+
}
1889+
}
18791890

18801891
static void
18811892
MtmReplicationStartupHook(struct PGLogicalStartupHookArgs* args)
@@ -1922,13 +1933,17 @@ MtmReplicationStartupHook(struct PGLogicalStartupHookArgs* args)
19221933
elog(NOTICE, "Node %d start logical replication to node %d in normal mode", MtmNodeId, MtmReplicationNodeId);
19231934
}
19241935
MtmUnlock();
1936+
on_proc_exit(MtmOnProcExit, 0);
19251937
}
19261938

19271939
static void
19281940
MtmReplicationShutdownHook(struct PGLogicalShutdownHookArgs* args)
19291941
{
1930-
elog(WARNING, "Logical replication to node %d is stopped", MtmReplicationNodeId);
1931-
MtmOnNodeDisconnect(MtmReplicationNodeId);
1942+
if (MtmReplicationNodeId >= 0) {
1943+
elog(WARNING, "Logical replication to node %d is stopped", MtmReplicationNodeId);
1944+
MtmOnNodeDisconnect(MtmReplicationNodeId);
1945+
MtmReplicationNodeId = -1; /* defuse on_proc_exit hook */
1946+
}
19321947
}
19331948

19341949
static bool
@@ -2166,7 +2181,8 @@ static bool MtmRunUtilityStmt(PGconn* conn, char const* sql, char **errmsg)
21662181
return ret;
21672182
}
21682183

2169-
void MtmNoticeReceiver(void *i, const PGresult *res)
2184+
static void
2185+
MtmNoticeReceiver(void *i, const PGresult *res)
21702186
{
21712187
char *notice = PQresultErrorMessage(res);
21722188
char *stripped_notice;

0 commit comments

Comments
 (0)