mirror of
https://github.com/google/leveldb.git
synced 2025-03-26 12:05:41 +08:00
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
This commit is contained in:
parent
1d0b101165
commit
c00e177f36
@ -893,10 +893,11 @@ Status DBImpl::DoCompactionWork(CompactionState* compact) {
|
|||||||
compact->smallest_snapshot = snapshots_.oldest()->sequence_number();
|
compact->smallest_snapshot = snapshots_.oldest()->sequence_number();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Iterator* input = versions_->MakeInputIterator(compact->compaction);
|
||||||
|
|
||||||
// Release mutex while we're actually doing the compaction work
|
// Release mutex while we're actually doing the compaction work
|
||||||
mutex_.Unlock();
|
mutex_.Unlock();
|
||||||
|
|
||||||
Iterator* input = versions_->MakeInputIterator(compact->compaction);
|
|
||||||
input->SeekToFirst();
|
input->SeekToFirst();
|
||||||
Status status;
|
Status status;
|
||||||
ParsedInternalKey ikey;
|
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) {
|
void DBImpl::GetApproximateSizes(const Range* range, int n, uint64_t* sizes) {
|
||||||
// TODO(opt): better implementation
|
// TODO(opt): better implementation
|
||||||
Version* v;
|
MutexLock l(&mutex_);
|
||||||
{
|
Version* v = versions_->current();
|
||||||
MutexLock l(&mutex_);
|
v->Ref();
|
||||||
versions_->current()->Ref();
|
|
||||||
v = versions_->current();
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
// Convert user_key into a corresponding internal key.
|
// 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);
|
sizes[i] = (limit >= start ? limit - start : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
v->Unref();
|
||||||
MutexLock l(&mutex_);
|
|
||||||
v->Unref();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default implementations of convenience methods that subclasses of DB
|
// Default implementations of convenience methods that subclasses of DB
|
||||||
|
@ -197,7 +197,7 @@ class DBImpl : public DB {
|
|||||||
|
|
||||||
ManualCompaction* manual_compaction_ GUARDED_BY(mutex_);
|
ManualCompaction* manual_compaction_ GUARDED_BY(mutex_);
|
||||||
|
|
||||||
VersionSet* const versions_;
|
VersionSet* const versions_ GUARDED_BY(mutex_);
|
||||||
|
|
||||||
// Have we encountered a background error in paranoid mode?
|
// Have we encountered a background error in paranoid mode?
|
||||||
Status bg_error_ GUARDED_BY(mutex_);
|
Status bg_error_ GUARDED_BY(mutex_);
|
||||||
|
Loading…
Reference in New Issue
Block a user