Do an optimization/issue-correcting step during opening the database

Optimization step detects broken databases, so it lowers chances of agents
hanging forever or segfaulting inside libtokyocabinet.
Don't provoke database corruption by mixing read/write and cursor operations