Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Expose wait_for_compact #841

Merged

Conversation

zaidoon1
Copy link
Contributor

@zaidoon1 zaidoon1 commented Dec 2, 2023

No description provided.

@zaidoon1 zaidoon1 force-pushed the zaidoon/expose-wait-for-compact branch 2 times, most recently from d1b82d6 to e3b78c6 Compare December 2, 2023 11:03
/// comments in DB::Close() for details.
///
/// Default: false
pub fn set_close_db(&mut self, v: bool) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this method shouldn't be exposed, or alternatively should be marked unsafe? It allows the underlying database to be closed without dropping the DB object, and RocksDB is pretty light on guarantees about continuing to use a DB after it was closed.

https://github.com/facebook/rocksdb/blob/c96d9a0fbbfd2215e7ae88af8a13b94109a349b5/include/rocksdb/db.h#L345

Regardless of the return status, the DB must be freed.

From the wiki:

Q: Is it safe to close RocksDB while another thread is issuing read, write or manual compaction requests?

A: No. The users of RocksDB need to make sure all functions have finished before they close RocksDB. You can speed up the waiting by calling CancelAllBackgroundWork().

Looking at the implementation, there is a closed_ flag in RocksDB but it is only checked in Close and in the destructor

https://github.com/facebook/rocksdb/blob/c96d9a0fbbfd2215e7ae88af8a13b94109a349b5/db/db_impl/db_impl.cc#L5136

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another safe alternative would be remove this and add a pub fn wait_for_compact_and_close(self, opts: &WaitForCompactOptions) -> Result<(), Error> method that consumes the DB instance

Copy link
Contributor Author

@zaidoon1 zaidoon1 Dec 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm, ok for the time being, I'm going to remove set_close_db as I don't need it. We can revisit if someone needs this option

@zaidoon1 zaidoon1 force-pushed the zaidoon/expose-wait-for-compact branch from 10850d4 to 6d7fe89 Compare December 12, 2023 06:41
@aleksuss aleksuss merged commit dcf7ee0 into rust-rocksdb:master Dec 12, 2023
7 checks passed
zaidoon1 added a commit to zaidoon1/rust-speedb that referenced this pull request Feb 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants