Fixed sql recovery logic.
- Get rid of clear failed and set failed since it was
  causing deadlocks.

#1831