Skip to content

Commit 3f5cc5d

Browse files
committed
Use InstrumentedMutexLock as much as possible
1 parent df954a2 commit 3f5cc5d

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

db/compaction/compaction_job.cc

+15-15
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ void CompactionJob::AcquireSubcompactionResources(
321321
->write_controller()
322322
->NeedSpeedupCompaction())
323323
.max_compactions;
324-
db_mutex_->Lock();
324+
InstrumentedMutexLock l(db_mutex_);
325325
// Apply min function first since We need to compute the extra subcompaction
326326
// against compaction limits. And then try to reserve threads for extra
327327
// subcompactions. The actual number of reserved threads could be less than
@@ -346,7 +346,6 @@ void CompactionJob::AcquireSubcompactionResources(
346346
} else {
347347
*bg_compaction_scheduled_ += extra_num_subcompaction_threads_reserved_;
348348
}
349-
db_mutex_->Unlock();
350349
}
351350

352351
void CompactionJob::ShrinkSubcompactionResources(uint64_t num_extra_resources) {
@@ -380,19 +379,20 @@ void CompactionJob::ReleaseSubcompactionResources() {
380379
if (extra_num_subcompaction_threads_reserved_ == 0) {
381380
return;
382381
}
383-
db_mutex_->Lock();
384-
// The number of reserved threads becomes larger than 0 only if the
385-
// compaction prioity is round robin and there is no sufficient
386-
// sub-compactions available
387-
388-
// The scheduled compaction must be no less than 1 + extra number
389-
// subcompactions using acquired resources since this compaction job has not
390-
// finished yet
391-
assert(*bg_bottom_compaction_scheduled_ >=
392-
1 + extra_num_subcompaction_threads_reserved_ ||
393-
*bg_compaction_scheduled_ >=
394-
1 + extra_num_subcompaction_threads_reserved_);
395-
db_mutex_->Unlock();
382+
{
383+
InstrumentedMutexLock l(db_mutex_);
384+
// The number of reserved threads becomes larger than 0 only if the
385+
// compaction prioity is round robin and there is no sufficient
386+
// sub-compactions available
387+
388+
// The scheduled compaction must be no less than 1 + extra number
389+
// subcompactions using acquired resources since this compaction job has not
390+
// finished yet
391+
assert(*bg_bottom_compaction_scheduled_ >=
392+
1 + extra_num_subcompaction_threads_reserved_ ||
393+
*bg_compaction_scheduled_ >=
394+
1 + extra_num_subcompaction_threads_reserved_);
395+
}
396396
ShrinkSubcompactionResources(extra_num_subcompaction_threads_reserved_);
397397
}
398398

0 commit comments

Comments
 (0)