When flushing mem tables, create iterators out of mutex

Summary:
creating new iterators of mem tables can be expensive. Move them out of mutex.
DBImpl::WriteLevel0Table()'s mems seems to be a local vector and is only used by flushing. memtables to flush are also immutable, so it should be safe to do so.

Test Plan: make all check

Reviewers: haobo, dhruba, kailiu

Reviewed By: dhruba

CC: igor, leveldb

Differential Revision: https://reviews.facebook.net/D14577
This commit is contained in:
Siying Dong 2013-12-10 20:03:27 -08:00
parent 3c02c363b3
commit 95a411d853

View File

@ -1054,6 +1054,14 @@ Status DBImpl::WriteLevel0Table(std::vector<MemTable*> &mems, VersionEdit* edit,
*filenumber = meta.number;
pending_outputs_.insert(meta.number);
const SequenceNumber newest_snapshot = snapshots_.GetNewest();
const SequenceNumber earliest_seqno_in_memtable =
mems[0]->GetFirstSequenceNumber();
Version* base = versions_->current();
base->Ref(); // it is likely that we do not need this reference
Status s;
{
mutex_.Unlock();
std::vector<Iterator*> list;
for (MemTable* m : mems) {
Log(options_.info_log,
@ -1063,18 +1071,9 @@ Status DBImpl::WriteLevel0Table(std::vector<MemTable*> &mems, VersionEdit* edit,
}
Iterator* iter = NewMergingIterator(env_, &internal_comparator_, &list[0],
list.size());
const SequenceNumber newest_snapshot = snapshots_.GetNewest();
const SequenceNumber earliest_seqno_in_memtable =
mems[0]->GetFirstSequenceNumber();
Log(options_.info_log,
"Level-0 flush table #%lu: started",
(unsigned long)meta.number);
Version* base = versions_->current();
base->Ref(); // it is likely that we do not need this reference
Status s;
{
mutex_.Unlock();
// We skip compression if universal compression is used and the size
// threshold is set for compression.
bool enable_compression = (options_.compaction_style
@ -1085,15 +1084,15 @@ Status DBImpl::WriteLevel0Table(std::vector<MemTable*> &mems, VersionEdit* edit,
user_comparator(), newest_snapshot,
earliest_seqno_in_memtable, enable_compression);
LogFlush(options_.info_log);
mutex_.Lock();
}
base->Unref();
delete iter;
Log(options_.info_log, "Level-0 flush table #%lu: %lu bytes %s",
(unsigned long) meta.number,
(unsigned long) meta.file_size,
s.ToString().c_str());
delete iter;
mutex_.Lock();
}
base->Unref();
// re-acquire the most current version
base = versions_->current();