-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
Add missing mutex when reading from shared variable bg_bottom_compaction_scheduled_, bg_compaction_scheduled_ #10610
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -321,6 +321,7 @@ void CompactionJob::AcquireSubcompactionResources( | |
->write_controller() | ||
->NeedSpeedupCompaction()) | ||
.max_compactions; | ||
db_mutex_->Lock(); | ||
// Apply min function first since We need to compute the extra subcompaction | ||
// against compaction limits. And then try to reserve threads for extra | ||
// subcompactions. The actual number of reserved threads could be less than | ||
|
@@ -329,7 +330,6 @@ void CompactionJob::AcquireSubcompactionResources( | |
std::max(max_db_compactions - *bg_compaction_scheduled_ - | ||
*bg_bottom_compaction_scheduled_, | ||
0); | ||
db_mutex_->Lock(); | ||
// Reservation only supports backgrdoun threads of which the priority is | ||
// between BOTTOM and HIGH. Need to degrade the priority to HIGH if the | ||
// origin thread_pri_ is higher than that. Similar to ReleaseThreads(). | ||
|
@@ -380,6 +380,7 @@ void CompactionJob::ReleaseSubcompactionResources() { | |
if (extra_num_subcompaction_threads_reserved_ == 0) { | ||
return; | ||
} | ||
db_mutex_->Lock(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately I can't easily do InstrumentedMutexLock for this one cuz the function right after its unlock "ShrinkSubcompactionResources(extra_num_subcompaction_threads_reserved_);" but before the scope ends need to acquire lock again. So I won't be fixing this one. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about {
InstrumentedMutexLock (db_mutex_);
assert(...)
}
ShrinkSubcompactionresrouce(); Furthermore, mutex lock-unlock is not needed if in opt mode, but if we differentiate between debug and opt mode, there may be a gap in test coverage, thus I am fine with current. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got you - yeah I can change to your suggested version! This is the easy way that I didn't think of! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
// The number of reserved threads becomes larger than 0 only if the | ||
// compaction prioity is round robin and there is no sufficient | ||
// sub-compactions available | ||
|
@@ -391,6 +392,7 @@ void CompactionJob::ReleaseSubcompactionResources() { | |
1 + extra_num_subcompaction_threads_reserved_ || | ||
*bg_compaction_scheduled_ >= | ||
1 + extra_num_subcompaction_threads_reserved_); | ||
db_mutex_->Unlock(); | ||
ShrinkSubcompactionResources(extra_num_subcompaction_threads_reserved_); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use
InstrumentedMutexLock
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.