Add Support for Querying Against Read Replicas#70
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds support for querying against read replicas in a round-robin fashion, allowing applications to distribute read operations across multiple database connections.
Changes:
- Added read replica infrastructure with circular linked list implementation for round-robin connection selection
- Implemented new query methods (
QueryRR,QueryRowRR,GetRR,GetAllRR) that execute against read replicas - Fixed a resource leak where
rowswas not being closed in theGetAllmethod
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| read_replicas.go | Implements core read replica functionality with thread-safe round-robin connection management |
| read_replicas_test.go | Comprehensive unit tests for read replica add and next operations |
| sequel.go | Adds read replica field to DB struct, new RR query methods, and fixes missing rows.Close() |
| sequel_test.go | Integration tests for read replica query operations with multiple database connections |
| main_test.go | Refactors test setup to create three database containers (one master, two read replicas) |
| testdata/init-db-rr.sh | Initialization script for read replica test databases with sample data |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
azazeal
left a comment
There was a problem hiding this comment.
Not 100% sure but, perhaps, a (*DB) ReadReplica() *ReadReplica function that, returns a strongly typed object, derived from DB, that only exposes read-replica compatible commands, might not be a bad idea. It'd probably also help with the RR suffixees.
main_test.go
Outdated
| func TestMain(m *testing.M) { | ||
| ctx := context.Background() | ||
| cleanups, err := createPostgresContainers(ctx) | ||
| defer func() { |
There was a problem hiding this comment.
These defer'd statements won't execute due to os.Exit.
I think that's a good idea. It'll prevent accidentally using the primary. Queued. |
This PR adds support for querying against read replicas, in a round-robin fashion.
This PR also cleans up some comments and closes a rows resource that was never closed.