rollback transaction on stat error

Instead of deleting everything, only rollback
the latest changes. Prevents losing previously generated
statistics
Merge branch '5084_rollback_on_fail'