Skip to content

Conversation

@smst-jeff
Copy link

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.

@smst-jeff smst-jeff requested a review from a team as a code owner February 11, 2026 00:34
@smst-jeff smst-jeff requested review from a team and Copilot and removed request for a team February 11, 2026 03:48
Copy link

Copilot AI left a 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 rows was not being closed in the GetAll method

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.

Comment on lines 74 to 76
first := rr.current
for c := first; c != first; c = c.next {
c.db.Close()
Copy link

Copilot AI Feb 11, 2026

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.

Suggested change
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
}

Copilot uses AI. Check for mistakes.
smst-jeff and others added 4 commits February 10, 2026 19:51
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant