Skip to content

Commit

Permalink
Use SS_IDLE state only for quorum waiting
Browse files Browse the repository at this point in the history
  • Loading branch information
petuhovskiy committed Dec 17, 2021
1 parent 5615c8c commit beb4421
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
23 changes: 12 additions & 11 deletions src/backend/replication/walproposer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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)
Expand All @@ -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);
}

/*
Expand Down Expand Up @@ -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)
{
/*
Expand Down Expand Up @@ -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;
}
Expand Down
7 changes: 1 addition & 6 deletions src/include/replication/walproposer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit beb4421

Please sign in to comment.