summaryrefslogtreecommitdiff
path: root/db/db_impl.cc
diff options
context:
space:
mode:
authorgabor@google.com <gabor@google.com@62dab493-f737-651d-591e-8d6aee1b9529>2011-08-22 21:08:51 +0000
committergabor@google.com <gabor@google.com@62dab493-f737-651d-591e-8d6aee1b9529>2011-08-22 21:08:51 +0000
commite3584f9c28833ec0530b39540ffd406ee41dbc3a (patch)
treee68d1bb6e1e2ad1c2a9acfa6ae26cf2d691055e7 /db/db_impl.cc
parentab323f7e1ec53749653967e7d6a2fa1c922334f2 (diff)
downloadleveldb-e3584f9c28833ec0530b39540ffd406ee41dbc3a.tar.gz
Bugfix for issue 33; reduce lock contention in Get(), parallel benchmarks.
- Fix for issue 33 (non-null-terminated result from leveldb_property_value()) - Support for running multiple instances of a benchmark in parallel. - Reduce lock contention on Get(): (1) Do not hold the lock while searching memtables. (2) Shard block and table caches 16-ways. Benchmark for evaluating this change: $ db_bench --benchmarks=fillseq1,readrandom --threads=$n (fillseq1 is a small hack to make sure fillseq runs once regardless of number of threads specified on the command line). git-svn-id: https://leveldb.googlecode.com/svn/trunk@49 62dab493-f737-651d-591e-8d6aee1b9529
Diffstat (limited to 'db/db_impl.cc')
-rw-r--r--db/db_impl.cc36
1 files changed, 23 insertions, 13 deletions
diff --git a/db/db_impl.cc b/db/db_impl.cc
index fff4eaf..c4c6a61 100644
--- a/db/db_impl.cc
+++ b/db/db_impl.cc
@@ -989,27 +989,37 @@ Status DBImpl::Get(const ReadOptions& options,
snapshot = versions_->LastSequence();
}
- // First look in the memtable, then in the immutable memtable (if any).
- LookupKey lkey(key, snapshot);
- if (mem_->Get(lkey, value, &s)) {
- return s;
- }
- if (imm_ != NULL && imm_->Get(lkey, value, &s)) {
- return s;
- }
-
- // Not in memtable(s); try live files in level order
+ MemTable* mem = mem_;
+ MemTable* imm = imm_;
Version* current = versions_->current();
+ mem->Ref();
+ if (imm != NULL) imm->Ref();
current->Ref();
+
+ bool have_stat_update = false;
Version::GetStats stats;
- { // Unlock while reading from files
+
+ // Unlock while reading from files and memtables
+ {
mutex_.Unlock();
- s = current->Get(options, lkey, value, &stats);
+ // First look in the memtable, then in the immutable memtable (if any).
+ LookupKey lkey(key, snapshot);
+ if (mem_->Get(lkey, value, &s)) {
+ // Done
+ } else if (imm_ != NULL && imm_->Get(lkey, value, &s)) {
+ // Done
+ } else {
+ s = current->Get(options, lkey, value, &stats);
+ have_stat_update = true;
+ }
mutex_.Lock();
}
- if (current->UpdateStats(stats)) {
+
+ if (have_stat_update && current->UpdateStats(stats)) {
MaybeScheduleCompaction();
}
+ mem->Unref();
+ if (imm != NULL) imm->Unref();
current->Unref();
return s;
}