stephan-hof / pyrocksdb

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

method to close db? #32

Open alekibango opened 9 years ago

alekibango commented 9 years ago

Imho closing DB maybe should be part of python api.

    def _close_db(self):
        del self.db
        gc.collect()
stephan-hof commented 9 years ago

Hi, in general it would be possible to close the db by doing

del self.db
self.db = NULL

However, then all the other calls like 'put, delete, get, ......' must have a check for

if self.db == NULL:
    raise Exception("DB is closed")

Also all iterators and snapshots are invalid, which means they need also a check if their according DB is still valid.

I'm not sure if a 'close()' method justifies these many checks + complicating the code. If I would not do such checks, the program will just fail with a 'SEGFAULT', because the database pointer is not valid any more. From my point of view a 'close()' method should not lead to SEGFAULT if not used correctly. Instead I would expect proper exceptions like 'DB is closed'.

So for now I'm very reluctant to add this feature, but I'll keep this ticket open, so that other users of this wrapper could post their opinion here. If I see that many users need this function I'm going to add it.

Downchuck commented 8 years ago

I think this item can be closed - though it's a good documentation note.

alekibango commented 8 years ago

@stephan-hof thanks for explanation here and in my other similar issues too. it really helped, even if i didnt get what i asked for :)