mirror of https://github.com/facebook/rocksdb.git
Fix a data race in DBImpl::RenameTempFileToOptionsFile (#12347)
Summary: Pull Request resolved: https://github.com/facebook/rocksdb/pull/12347 `DBImpl::disable_delete_obsolete_files_` should only be accessed while holding the DB mutex to prevent data races. There's a piece of logic in `DBImpl::RenameTempFileToOptionsFile` where this synchronization was previously missing. The patch fixes this issue similarly to how it's handled in `DisableFileDeletions` and `EnableFileDeletions`, that is, by saving the counter value while holding the mutex and then performing the actual file deletion outside the critical section. Note: this PR only fixes the race itself; as a followup, we can also look into cleaning up and optimizing the file deletion logic (which is currently inefficient on multiple different levels). Reviewed By: jowlyzhang Differential Revision: D53675153 fbshipit-source-id: 5358e894ee6829d3edfadac50a93d97f8819e481
This commit is contained in:
parent
395d24f0fa
commit
de1e3ff6ea
|
@ -5551,16 +5551,23 @@ Status DBImpl::RenameTempFileToOptionsFile(const std::string& file_name) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (s.ok()) {
|
||||
InstrumentedMutexLock l(&mutex_);
|
||||
versions_->options_file_number_ = options_file_number;
|
||||
versions_->options_file_size_ = options_file_size;
|
||||
int my_disable_delete_obsolete_files;
|
||||
|
||||
{
|
||||
InstrumentedMutexLock l(&mutex_);
|
||||
versions_->options_file_number_ = options_file_number;
|
||||
versions_->options_file_size_ = options_file_size;
|
||||
my_disable_delete_obsolete_files = disable_delete_obsolete_files_;
|
||||
}
|
||||
|
||||
if (!my_disable_delete_obsolete_files) {
|
||||
// TODO: Should we check for errors here?
|
||||
DeleteObsoleteOptionsFiles().PermitUncheckedError();
|
||||
}
|
||||
}
|
||||
|
||||
if (0 == disable_delete_obsolete_files_) {
|
||||
// TODO: Should we check for errors here?
|
||||
DeleteObsoleteOptionsFiles().PermitUncheckedError();
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Fixed a data race in `DBImpl::RenameTempFileToOptionsFile`.
|
Loading…
Reference in New Issue