Skip to content
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

Add sticky backend query hint #4553

Open
wants to merge 1 commit into
base: v2.x
Choose a base branch
from
Open

Commits on May 22, 2024

  1. Add sticky backend query hint

    Sometimes we want to make sure that queries in a single connection all hit the same DB replica. This helps us remain in a consistent state in the face of small replication delays between the different hosts. In many cases, it's preferable to read a consistent state from a single replica, even if that replica might not contain the most up to date version of the world.
    
    For example, let's say that we quickly insert two records (A and B) into the database and B causally depends on A. Once the application reads B, it assumes that A already exists and complains if it does not find it. This feature ensures read consistency by making sure that the application talks to the same replica during the lifetime of the connection.
    
    Sticky backends are disabled by default, and can be enabled by using the `/* sticky_backend=1 */` query hint. This is then persisted for the entire session, so the client only has to set the value once. The setting takes effect with the current query being executed:
      - when enabling sticky backends a load-balanced server will be selected for the query and the following queries will be executed against the same server
      - when disabling sticky backends, this and all subsequent queries will be executed against a load-balanced server
    
    We support three different sticky modes:
      - 0: no sticky backends (default)
      - 1: stick to the same replica as long as it is alive
      - 2: strict sticky, if the sticky replica is not alive no other replica will be chosen until it errors out
    zsoltparal-mollie committed May 22, 2024
    Configuration menu
    Copy the full SHA
    c5ba795 View commit details
    Browse the repository at this point in the history