Chaitanya Kumar Ch
Chaitanya Kumar Ch

Reputation: 309

SpringBoot HikariCP Maxscale select queries not sending to Slave

Standalone MaxScale is working fine. I used this link to test it. But when I run Spring Boot Data JPA with Maxscale, SELECT queries are sending to Master. I observed the long and found that Spring data starting transactions. Maxscale sending queries to Master when transactions are enabled. I tried with Spring "RoutingDataSource" by configuring readwrite and read only services at MaxScale. But it didn't solve the problem.

Upvotes: 0

Views: 364

Answers (1)

markusjm
markusjm

Reputation: 2562

By default readwritesplit will route all non-readonly transactions to the current master. This is done as it is not possible to know whether a transaction will modify a database or not. If the transaction is started with START TRANSACTION READ ONLY, the transaction will be routed to a slave.

You can enable optimistic_trx to route transactions to slaves even if they aren't started with START TRANSACTION READ ONLY. Note that this will slow down execution of transactions that do perform write operations as they are initially sent to a slave and moved to the master when the first write is detected.

Upvotes: 0

Related Questions