Skip to content

Load balancer tweaks #180

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

Merged
merged 8 commits into from
May 22, 2025
Merged

Load balancer tweaks #180

merged 8 commits into from
May 22, 2025

Conversation

levkk
Copy link
Collaborator

@levkk levkk commented May 21, 2025

Description

  • Add read_write_split configuration option. If set to include_primary, the primary will be used for read queries. If set to exclude_primary, only replicas will be used for read queries.
  • Fix Golang simple protocol with admin database (missing parameter).
  • Respond with EmptyQueryResponse when client sends an empty query instead of an error.
  • More tests.

Copy link

jazzberry-ai bot commented May 21, 2025

Bug Report

Incorrect quoting in SET command for enum values.|High|The TestRoundRobinWithPrimary test in integration/go/go_pgx/load_balancer_test.go uses the command SET load_balancing_strategy TO 'round_robin'.|This will result in the value being deserialized as a string containing single quotes, which is incorrect.|

Comments? Email us. Your free trial ends in 7 days.

@levkk levkk requested a review from Copilot May 21, 2025 18:25
Copy link
Contributor

@Copilot 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

A set of updates to introduce and wire up a new read/write split configuration, improve Go simple protocol support, and expand test coverage.

  • Add read_write_split config option to direct reads to primary or only replicas, and propagate it through Shard and Cluster.
  • Refactor the admin SET command JSON parsing and include the new read_write_split parameter.
  • Enhance Go integration tests: fix simple-protocol parameter handling and add new load-balancer tests.

Reviewed Changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pgdog/src/net/parameter.rs Return zero when no mutable params to avoid non-deterministic hash
pgdog/src/net/messages/parameter_status.rs Add standard_conforming_strings to default parameter status
pgdog/src/config/mod.rs Introduce ReadWriteSplit enum and default on General
pgdog/src/backend/pool/shard.rs Wire up rw_split field for read routing
pgdog/src/backend/pool/replicas.rs Clean up LoadBalancingStrategy imports and match arms
pgdog/src/backend/pool/cluster.rs Pass rw_split through cluster and shards
pgdog/src/admin/set.rs Extend SET command for read_write_split and JSON parsing
integration/go/go_pgx/pg_tests_test.go Fix simple protocol tests to use pgtype.Numeric and assert errors
integration/go/go_pgx/load_balancer_test.go Add end-to-end load balancer tests for read/write routing
integration/go/go_pgx/go.mod Bump various Go dependencies
Comments suppressed due to low confidence (2)

pgdog/src/backend/pool/shard.rs:1

  • Update this module-level doc comment to mention the new rw_split field and how it affects read routing behavior.
//! A shard is a collection of replicas and a primary.

pgdog/src/net/messages/parameter_status.rs:66

  • Consider adding a unit test to verify that standard_conforming_strings appears in the default ParameterStatus list.
ParameterStatus {

#[serde(default)]
pub read_write_strategy: ReadWriteStrategy,
/// Read write split.
Copy link
Preview

Copilot AI May 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expand this doc comment to explain the read_write_split option semantics, e.g. whether the primary will be included or excluded for read queries.

Suggested change
/// Read write split.
/// Determines whether read queries are split from write queries.
/// When enabled, read queries may be routed to replicas, while write queries
/// are always routed to the primary database. The primary database may or may not
/// be included in the pool of nodes handling read queries, depending on the
/// specific configuration of the load balancing strategy.

Copilot uses AI. Check for mistakes.

assert.NoError(t, err)
defer conn.Close(context.Background())

rows, err := conn.Query(context.Background(), command, pgx.QueryExecModeSimpleProtocol)
Copy link
Preview

Copilot AI May 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an assert.NoError(t, err) after this query to catch any errors during the admin command execution.

Suggested change
rows, err := conn.Query(context.Background(), command, pgx.QueryExecModeSimpleProtocol)
rows, err := conn.Query(context.Background(), command, pgx.QueryExecModeSimpleProtocol)
assert.NoError(t, err)

Copilot uses AI. Check for mistakes.

@levkk levkk marked this pull request as ready for review May 21, 2025 20:15
Copy link

jazzberry-ai bot commented May 21, 2025

Bug Report

Name Severity Example test case Description
SHOW STATS reports wrong transaction count High Run SHOW STATS after executing queries within a transaction. The SHOW STATS command reports transaction count as the sum of BEGIN, COMMIT, ROLLBACK, and SELECT queries within a transaction, rather than only the number of transactions.

Comments? Email us. Your free trial ends in 7 days.

Copy link

jazzberry-ai bot commented May 22, 2025

Bug Report

Name Severity Example test case Description
Missing test case for read_write_split = "include_primary" Medium Add a new test case to integration/load_balancer/pgx/read_write_split_test.go that sets read_write_split = "include_primary" in integration/load_balancer/pgdog.toml and verifies that read queries are distributed between the primary and replica servers. The current integration tests only test the exclude_primary case for the read_write_split configuration option. A test case is needed for the include_primary case to ensure that read queries are correctly distributed between the primary and replica servers when this option is enabled. Without this test case, we cannot be sure that the load balancing is working correctly for include_primary.

Comments? Email us. Your free trial ends in 7 days.

Copy link

jazzberry-ai bot commented May 22, 2025

Reviewing... 🍎
Questions? Email us.

@levkk levkk merged commit 4b932e6 into main May 22, 2025
4 checks passed
@levkk levkk deleted the levkk-avoid-primary branch May 22, 2025 01:30
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