tdb: Make tdb robust against improper CLEAR_IF_FIRST restart