Re: PHP - Load Balancing
Posted by: Rick James
Date: July 01, 2016 11:53PM

The "trap":

Suppose you use a SELECT to see if there is a record, and it says there is not.

Then you proceed to do an INSERT, but get "duplicate key".

WTF? Answer...

If the SELECT went to a slave and that slave was "behind" on replication, it may not yet see that someone else already inserted the record.

This is called a "critical read". Such a SELECT must be sent to the Master (or have some assurance that the slave is up to date). Really, it should be done something like this, all to the Master:

if ...

(There are other examples that don't need FOR UPDATE or even a transaction, but this one should be easy to understand.)

Options: ReplyQuote

Written By
May 30, 2016 12:02AM
May 31, 2016 09:32PM
Re: PHP - Load Balancing
July 01, 2016 11:53PM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.