summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Mumford <cmumford@google.com>2019-05-15 13:13:13 -0700
committerChris Mumford <cmumford@google.com>2019-05-16 12:07:21 -0700
commitc00e177f3613068eda4bff4abfbd3bd4165a86e8 (patch)
tree3ad063683b3affd5eb4bad8c94aed553a38454ec
parent1d0b101165ddd34f26cc5c62b76f2a2e0d622483 (diff)
downloadleveldb-c00e177f3613068eda4bff4abfbd3bd4165a86e8.tar.gz
Guard DBImpl::versions_ by mutex_.
mutex_ was already acquired before accessing DBImpl::versions_ in all but one place: DBImpl::GetApproximateSizes. This change requires mutex_ to be held before accessing versions_. PiperOrigin-RevId: 248390814
-rw-r--r--db/db_impl.cc17
-rw-r--r--db/db_impl.h2
2 files changed, 7 insertions, 12 deletions
diff --git a/db/db_impl.cc b/db/db_impl.cc
index 067c67d..94b5d4c 100644
--- a/db/db_impl.cc
+++ b/db/db_impl.cc
@@ -893,10 +893,11 @@ Status DBImpl::DoCompactionWork(CompactionState* compact) {
compact->smallest_snapshot = snapshots_.oldest()->sequence_number();
}
+ Iterator* input = versions_->MakeInputIterator(compact->compaction);
+
// Release mutex while we're actually doing the compaction work
mutex_.Unlock();
- Iterator* input = versions_->MakeInputIterator(compact->compaction);
input->SeekToFirst();
Status status;
ParsedInternalKey ikey;
@@ -1433,12 +1434,9 @@ bool DBImpl::GetProperty(const Slice& property, std::string* value) {
void DBImpl::GetApproximateSizes(const Range* range, int n, uint64_t* sizes) {
// TODO(opt): better implementation
- Version* v;
- {
- MutexLock l(&mutex_);
- versions_->current()->Ref();
- v = versions_->current();
- }
+ MutexLock l(&mutex_);
+ Version* v = versions_->current();
+ v->Ref();
for (int i = 0; i < n; i++) {
// Convert user_key into a corresponding internal key.
@@ -1449,10 +1447,7 @@ void DBImpl::GetApproximateSizes(const Range* range, int n, uint64_t* sizes) {
sizes[i] = (limit >= start ? limit - start : 0);
}
- {
- MutexLock l(&mutex_);
- v->Unref();
- }
+ v->Unref();
}
// Default implementations of convenience methods that subclasses of DB
diff --git a/db/db_impl.h b/db/db_impl.h
index a3f1ed1..685735c 100644
--- a/db/db_impl.h
+++ b/db/db_impl.h
@@ -197,7 +197,7 @@ class DBImpl : public DB {
ManualCompaction* manual_compaction_ GUARDED_BY(mutex_);
- VersionSet* const versions_;
+ VersionSet* const versions_ GUARDED_BY(mutex_);
// Have we encountered a background error in paranoid mode?
Status bg_error_ GUARDED_BY(mutex_);