sysown / proxysql

High-performance MySQL proxy with a GPL license.
http://www.proxysql.com
GNU General Public License v3.0
6.06k stars 983 forks source link

Add sticky backend query hint #4553

Open zsparal opened 6 months ago

zsparal commented 6 months ago

Background

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.

The change

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:

We support three different sticky modes:

Production experience

We (Mollie) have been running a patched version of proxysql in production since last August and it has been completely stable, while reducing the above-described problem in our systems.

Questions & notes

Fixes #4558

mirostauder commented 6 months ago

Automated message: PR pending admin approval for build testing

zsparal commented 5 months ago

@renecannao or @mirostauder Could you please take a look at this PR (and the related issue)? Do you think it is a feature that could benefit other users of ProxySQL?

Thank you 🙂

mirostauder commented 4 months ago

Can one of the admins verify this patch?

zsparal commented 4 months ago

Is there anything I can do to move this forward?

zsparal commented 3 weeks ago

@JavierJF I apologize for the follow-up, but I'm wondering if there's any update on reviewing this change? I believe it could be a valuable addition to ProxySQL, addressing real-world issues efficiently. Any feedback or discussion would be greatly appreciated.