Prevent busy writebatch loop in Obs_storage.
Revamp writebatch loop for clarity and correctness.

* possible busy loop on close
* memleak
* stack munching
Must no wait for write batch commit if not dirty.

Fixes lock on e.g. empty transactions or transactions where keys/columns from
non-existent tables are deleted.