Changing the script so reconnections to the master also works following a failover #2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changing the script so a connection directed to a master reconnects upon failure (due to failover/switchover). The problem, as I left wrote as a comment in the code, 'a recently promoted/demoted server may still be transitioning and initially reply with the previous role' - that's valid both ways. For example, note how it switches to "read-mode" just after failing over:
It is more critical when doing reads and then the replica is promoted as master and does a write (!):
I'm sending the pull request but I'm not 100% confident this is the way.
Alternatively, we can put a "sleep" of a few seconds to avoid this - unless there is a different/transparent way we can prevent writes to a read-only connection (to port 5001).