rkv icon indicating copy to clipboard operation
rkv copied to clipboard

Make sure there is no parallel file write by `write_to_disk`

Open saschanaz opened this issue 2 years ago • 0 comments

More details here: https://bugzilla.mozilla.org/show_bug.cgi?id=1807010#c2

rkv's safe mode protects the in-memory database contents with an RwLock<EnvironmentDbs> (https://github.com/mozilla/rkv/blob/c5a7594c830903f59eb28c7e32daa8200744323e/src/backend/impl_safe/environment.rs#L234-L236), but that lock is released in https://github.com/mozilla/rkv/blob/c5a7594c830903f59eb28c7e32daa8200744323e/src/backend/impl_safe/transaction.rs#L192, before flushing the contents to disk. So, even if (2) weren't a factor, multiple calls to EnvironmentImpl.write_to_disk() from different task queues could still race with each other.

I wonder we can mitigate this issue by adding a separate lock solely for this write_to_disk() and wait for the lock for each write.

saschanaz avatar Jan 26 '23 11:01 saschanaz