feat: add proxy topology mode for SPQR-compatible routing - #33
Open
Denchick wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
PostgresKit currently assumes that every connection string represents an individual node in a PostgreSQL primary/replica cluster.
To determine each node's role, it periodically executes:
SELECT pg_is_in_recovery();A
falseresult identifies a primary, whiletrueidentifies a replica.This assumption does not work for SPQR. The supplied endpoints represent equivalent SPQR router instances rather than individual PostgreSQL nodes. A router can accept both read and write queries and forward them to the appropriate backend.
SPQR routers report themselves as primary for
pg_is_in_recovery(). Therefore, when several router endpoints are configured, PostgresKit classifies all of them as primaries and may report:or:
Having multiple endpoints classified as “masters” is normal for an SPQR deployment: these are equivalent router instances, not multiple writable PostgreSQL primary nodes. The warnings are produced by PostgresKit because its primary/replica topology model does not match the actual SPQR topology.
Suppressing status logs does not solve the problem because it only hides the warnings while leaving the incorrect routing model in place.
Solution
This PR adds an optional dispatcher topology mode:
In
proxymode, PostgresKit:SELECT 1instead ofpg_is_in_recovery()for health checks;db.primaryanddb.replica;Backward compatibility
primary-replicaremains the default topology mode. WhentopologyModeis omitted, the existing health checks, routing behavior, warnings, and errors remain unchanged.Testing
Added tests covering:
db.primaryanddb.replica;