stephan-hof / pyrocksdb

Python bindings for RocksDB
BSD 3-Clause "New" or "Revised" License
150 stars 169 forks source link

method to clear db? #33

Closed alekibango closed 9 years ago

alekibango commented 9 years ago

It would be nice to have really fast method to delete all db contents, which can be runned while db is opened, from python. For example for unittesting.

db.clear() would be nice name for that.

i do not like the idea of running rm -rf from shell, and deleting every key yielded from list of keys is not nice too.

stephan-hof commented 9 years ago

Hi,

unfortunately rocksdb itself does not provide a method to 'drop' all contents from a open DB. The only method I have seen is DestroyDB, but it only works on a closed DB. In fact DestroyDB is more or less doing a shutil.rmtree(path).

However all these methods (DestroyDB, shutil.rmtree, rm -rf) expect that the database is already closed. I explained the consequences of having a close() method in pyrocksdb here: #32

For unittesting I'm using the 'iterate over all keys and delete each one by one'. I agree for a big production DB, this is not very nice.

If you really need this feature "drop all contents while the DB is open", you should ask the rocksdb guys to add this to the C++ wrapper. Then I can happily/easily wrap this new method.