delayed_job_active_record
delayed_job_active_record copied to clipboard
Statement unsafe for statement based replication
When running against MySQL >= 5.1 with STATEMENT based replication the MySQL server logs the following error:
150514 22:59:37 [Warning] Statement may not be safe to log in statement format. Statement: UPDATE delayed_jobs
SET locked_at
= '2015-05-14 22:59:38', locked_by
= 'host:job1-dev.test.host' pid:24358' WHERE ((run_at <= '2015-05-14 22:59:38' AND (locked_at IS NULL OR locked_at < '2015-05-14 22:39:38') OR locked_by = 'host:job1-dev.test.host pid:24358') AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT 1
This is due to non deterministic behaviour of this statement on the master and slave due to the limit 1 and the potential for rows to be returned in a different order.
Appending the id field to the order by will resolve the issue because this field is unique, so rows will always be returned in the same order on the slave as on the master.