Deadlock retries

Retry transaction on deadlock error.
We are only seeing deadlocks in the call to `record_appearance`, but the whole transaction is being rescued because we need to retry the entire transaction. After the deadlock, the transaction is basically stuck and needs to rollback. I'll add some code comments that attempt to communicate that.