-
Notifications
You must be signed in to change notification settings - Fork 1
Add Support for Querying Against Read Replicas #70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| first := rr.current | ||
| for c := first; c != first; c = c.next { | ||
| c.db.Close() |
Copilot
AI
Feb 11, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The loop condition c != first will never be true on the first iteration since c is initialized to first. This means the loop will never execute and connections will not be closed. The condition should check if c.next != first or restructure to use a do-while pattern.
| first := rr.current | |
| for c := first; c != first; c = c.next { | |
| c.db.Close() | |
| if rr.current == nil { | |
| return | |
| } | |
| first := rr.current | |
| for c := first; ; c = c.next { | |
| c.db.Close() | |
| if c.next == first { | |
| break | |
| } |
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>
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.