Use non-mmapd files for Write-Ahead Files

Summary:
Use non mmapd files for Write-Ahead log.
Earlier use of MMaped files. made the log iterator read ahead and miss records.
Now the reader and writer will point to the same physical location.

There is no perf regression :
./db_bench --benchmarks=fillseq --db=/dev/shm/mmap_test --num=$(million 20) --use_existing_db=0 --threads=2
with This diff :
fillseq      :      10.756 micros/op 185281 ops/sec;   20.5 MB/s
without this dif :
fillseq      :      11.085 micros/op 179676 ops/sec;   19.9 MB/s

Test Plan: unit test included

Reviewers: dhruba, heyongqiang

Reviewed By: heyongqiang

CC: leveldb

Differential Revision: https://reviews.facebook.net/D9741
This commit is contained in:
Abhishek Kona 2013-03-28 13:13:35 -07:00
parent 63f216ee0a
commit 7fdd5f5b33
3 changed files with 29 additions and 20 deletions

View File

@ -2178,8 +2178,13 @@ Status DBImpl::MakeRoomForWrite(bool force) {
assert(versions_->PrevLogNumber() == 0);
uint64_t new_log_number = versions_->NewFileNumber();
unique_ptr<WritableFile> lfile;
s = env_->NewWritableFile(LogFileName(dbname_, new_log_number), &lfile,
storage_options_);
StorageOptions soptions(storage_options_);
soptions.DisableMmapWrites();
s = env_->NewWritableFile(
LogFileName(dbname_, new_log_number),
&lfile,
soptions
);
if (!s.ok()) {
// Avoid chewing through file number space in a tight loop.
versions_->ReuseFileNumber(new_log_number);
@ -2394,6 +2399,7 @@ Status DB::Open(const Options& options, const std::string& dbname,
if (s.ok()) {
uint64_t new_log_number = impl->versions_->NewFileNumber();
unique_ptr<WritableFile> lfile;
soptions.DisableMmapWrites();
s = options.env->NewWritableFile(LogFileName(dbname, new_log_number),
&lfile, soptions);
if (s.ok()) {

View File

@ -2664,24 +2664,23 @@ TEST(DBTest, TransactionLogIteratorMoveOverZeroFiles) {
auto iter = OpenTransactionLogIter(0);
ExpectRecords(2, iter);
}
// Disabled currently as does not work with mmaped files.
//
// TEST(DBTest, TransactionLogIteratorStallAtLastRecord) {
// Options options = OptionsForLogIterTest();
// DestroyAndReopen(&options);
// Put("key1", DummyString(1024));
// auto iter = OpenTransactionLogIter(0);
// ASSERT_OK(iter->status());
// ASSERT_TRUE(iter->Valid());
// iter->Next();
// ASSERT_TRUE(!iter->Valid());
// ASSERT_OK(iter->status());
// Put("key2", DummyString(1024));
// iter->Next();
// ASSERT_OK(iter->status());
// ASSERT_TRUE(iter->Valid());
// }
//
TEST(DBTest, TransactionLogIteratorStallAtLastRecord) {
Options options = OptionsForLogIterTest();
DestroyAndReopen(&options);
Put("key1", DummyString(1024));
auto iter = OpenTransactionLogIter(0);
ASSERT_OK(iter->status());
ASSERT_TRUE(iter->Valid());
iter->Next();
ASSERT_TRUE(!iter->Valid());
ASSERT_OK(iter->status());
Put("key2", DummyString(1024));
iter->Next();
ASSERT_OK(iter->status());
ASSERT_TRUE(iter->Valid());
}
TEST(DBTest, ReadCompaction) {
std::string value(4096, '4'); // a string of size 4K
{

View File

@ -50,6 +50,10 @@ class StorageOptions : public EnvOptions {
bool UseMmapWrites() const { return use_mmap_writes_; }
bool UseReadaheadCompactions() const { return readahead_compactions_;}
void DisableMmapWrites() {
use_mmap_writes_ = false;
}
private:
bool data_in_os_;
bool fs_readahead_;