From beb44217603d34cbd2d2e93e974a7e5af99897b5 Mon Sep 17 00:00:00 2001 From: Arthur Petukhovsky Date: Fri, 17 Dec 2021 17:48:18 +0300 Subject: [PATCH] Use SS_IDLE state only for quorum waiting --- src/backend/replication/walproposer.c | 23 ++++++++++++----------- src/include/replication/walproposer.h | 7 +------ 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/backend/replication/walproposer.c b/src/backend/replication/walproposer.c index 788c3c2bfa4..59ac8b9ee8a 100644 --- a/src/backend/replication/walproposer.c +++ b/src/backend/replication/walproposer.c @@ -745,7 +745,7 @@ BroadcastMessage(WalMessage *msg) { for (int i = 0; i < n_walkeepers; i++) { - if ((walkeeper[i].state == SS_IDLE || walkeeper[i].state == SS_ACTIVE) && walkeeper[i].currMsg == NULL) + if (walkeeper[i].state == SS_ACTIVE && walkeeper[i].currMsg == NULL) { SendMessageToNode(i, msg); } @@ -1148,7 +1148,7 @@ SendProposerElected(WalKeeper *wk) } /* - * Start streaming to safekeeper wk. + * Start streaming to safekeeper wk, always updates state to SS_ACTIVE. */ static void StartStreaming(WalKeeper *wk) @@ -1168,7 +1168,10 @@ StartStreaming(WalKeeper *wk) return; } } - wk->state = SS_IDLE; /* nothing to send yet, safekeeper is recovered */ + + /* nothing to send yet, waiting for the next message */ + wk->state = SS_ACTIVE; + UpdateEventSet(wk, WL_SOCKET_READABLE); } /* @@ -1763,6 +1766,12 @@ AdvancePollState(int i, uint32 events) SendProposerElected(&walkeeper[i]); } + /* + * The proposer has been elected, and there will be no quorum waiting + * after this point. There will be no safekeeper with state SS_IDLE + * also, because that state is used only for quorum waiting. + */ + if (syncSafekeepers) { /* @@ -1820,14 +1829,6 @@ AdvancePollState(int i, uint32 events) if (!RecvAppendResponses(wk)) return; - if (wk->currMsg == NULL && wk->ackMsg == NULL) - { - wk->state = SS_IDLE; - UpdateEventSet(wk, WL_SOCKET_READABLE); /* Idle states wait for - * read-ready */ - break; - } - UpdateEventSet(wk, WL_SOCKET_READABLE | (wk->currMsg == NULL ? 0 : WL_SOCKET_WRITEABLE)); break; } diff --git a/src/include/replication/walproposer.h b/src/include/replication/walproposer.h index dfb25347031..e2d1983b24b 100644 --- a/src/include/replication/walproposer.h +++ b/src/include/replication/walproposer.h @@ -70,10 +70,7 @@ typedef enum /* * WAL safekeeper state * - * States are listed here in the order that they're executed - with the only - * exception occuring from the "send WAL" cycle, which loops as: - * - * SS_IDLE -> SS_ACTIVE -> SS_IDLE + * States are listed here in the order that they're executed. * * Most states, upon failure, will move back to SS_OFFLINE by calls to * ResetConnection or ShutdownConnection. @@ -163,8 +160,6 @@ typedef enum /* * Active phase, when we acquired quorum and have WAL to send or feedback * to read. - * - * Moves to SS_IDLE when we have nothing to do. */ SS_ACTIVE, } WalKeeperState;