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

Commit fb58fcd

Browse files
knizhnikkelvich
authored andcommitted
more price handling of recovery mode
1 parent 734b737 commit fb58fcd

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

multimaster.c

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1881,12 +1881,23 @@ static void
18811881
MtmReplicationStartupHook(struct PGLogicalStartupHookArgs* args)
18821882
{
18831883
ListCell *param;
1884+
bool recoveryCompleted = false;
18841885
MtmIsRecoverySession = false;
18851886
foreach(param, args->in_params)
18861887
{
18871888
DefElem *elem = lfirst(param);
18881889
if (strcmp("mtm_replication_mode", elem->defname) == 0) {
1889-
MtmIsRecoverySession = elem->arg != NULL && strVal(elem->arg) != NULL && strcmp(strVal(elem->arg), "recovery") == 0;
1890+
if (elem->arg != NULL && strVal(elem->arg) != NULL) {
1891+
if (strcmp(strVal(elem->arg), "recovery") == 0) {
1892+
MtmIsRecoverySession = true;
1893+
} else if (strcmp(strVal(elem->arg), "recovered") == 0) {
1894+
recoveryCompleted = true;
1895+
} else if (strcmp(strVal(elem->arg), "normal") != 0) {
1896+
elog(ERROR, "Illegal recovery mode %s", strVal(elem->arg));
1897+
}
1898+
} else {
1899+
elog(ERROR, "Replication mode is not specified");
1900+
}
18901901
break;
18911902
}
18921903
}
@@ -1899,10 +1910,14 @@ MtmReplicationStartupHook(struct PGLogicalStartupHookArgs* args)
18991910
MtmCheckQuorum();
19001911
}
19011912
} else if (BIT_CHECK(Mtm->disabledNodeMask, MtmReplicationNodeId-1)) {
1902-
elog(WARNING, "Node %d consider that recovery of node %d is completed: start normal replication", MtmNodeId, MtmReplicationNodeId);
1903-
BIT_CLEAR(Mtm->disabledNodeMask, MtmReplicationNodeId-1);
1904-
Mtm->nNodes += 1;
1905-
MtmCheckQuorum();
1913+
if (recoveryCompleted) {
1914+
elog(WARNING, "Node %d consider that recovery of node %d is completed: start normal replication", MtmNodeId, MtmReplicationNodeId);
1915+
BIT_CLEAR(Mtm->disabledNodeMask, MtmReplicationNodeId-1);
1916+
Mtm->nNodes += 1;
1917+
MtmCheckQuorum();
1918+
} else {
1919+
elog(ERROR, "Disabled node %d tries to reconnect without recovery", MtmReplicationNodeId);
1920+
}
19061921
} else {
19071922
elog(NOTICE, "Node %d start logical replication to node %d in normal mode", MtmNodeId, MtmReplicationNodeId);
19081923
}

pglogical_receiver.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,13 @@ feTimestampDifference(int64 start_time, int64 stop_time,
196196
}
197197
}
198198

199+
static char const* const MtmReplicationModeName[] =
200+
{
201+
"recovered", /* SLOT_CREATE_NEW: recovery of node is completed so drop old slot and restart replication from the current position in WAL */
202+
"recovery", /* SLOT_OPEN_EXISTED: perform recorvery of the node by applying all data from theslot from specified point */
203+
"normal" /* SLOT_OPEN_ALWAYS: normal mode: use existeed slot or create new one and start receiving data from it from the specified position */
204+
};
205+
199206
static void
200207
pglogical_receiver_main(Datum main_arg)
201208
{
@@ -298,7 +305,7 @@ pglogical_receiver_main(Datum main_arg)
298305
(uint32) originStartPos,
299306
MULTIMASTER_MAX_PROTO_VERSION,
300307
MULTIMASTER_MIN_PROTO_VERSION,
301-
mode == SLOT_OPEN_EXISTED ? "recovery" : "normal"
308+
MtmReplicationModeName[mode]
302309
);
303310
res = PQexec(conn, query->data);
304311
if (PQresultStatus(res) != PGRES_COPY_BOTH)

0 commit comments

Comments
 (0)