Some retry code for the db.