[RC][WIP] Retry on MySql deadlock errors

I've done an initial setup of a way to handle MySql deadlocks by retrying the transaction when using em->flush().
I've added 2 configuration variables, one to set how many times to retry and for how long to sleep between each try.

Let me know if this can be merged, is useless or need improvements.