Mariadb – How Maxscale deals with “Select for update transactions”

mariadbmaxscalereplication

We are facing intermitent deadlock issues that doesnt got reflected in the maxscale log nor the mariadb log. Only in the applications triying to do sql transactions in the database.

We use mostly readwritesplit with 2 nodes (yes, i know, bad design) and we dont know exactly how maxscale deals with the select for update queries.

  1. to the slave, because is a read query (select)
  2. to the master, because is a write query (update)

Maxscale version 2.1.16, MariaDB 2.1.29

Thanks!

Best Answer

It would be routed to the master, because SELECT ... FOR UPDATE is only a part of a transaction, and according to the MaxScale 2.1 readwritesplit documentation, "all statements within an open transaction" are routed to the master.

You should be able to verify this with a query like this, which should consistently give you the hostname of the master:

START TRANSACTION;
SELECT * FROM t1 WHERE id = 1 FOR UPDATE;
SELECT @@hostname;
COMMIT;