Fix head and tail confusion

head and tail got mixed up. Head is the last value inserted.
Add a reserved space to the queue
Compatible with recent versions of leveldb and db_key