From 7fdd5f5b337fe5da223ea08113653766e3537684 Mon Sep 17 00:00:00 2001 From: Abhishek Kona Date: Thu, 28 Mar 2013 13:13:35 -0700 Subject: [PATCH] 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 --- db/db_impl.cc | 10 ++++++++-- db/db_test.cc | 35 +++++++++++++++++------------------ util/storage_options.h | 4 ++++ 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/db/db_impl.cc b/db/db_impl.cc index 1679413759..b2cfe4d33a 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -2178,8 +2178,13 @@ Status DBImpl::MakeRoomForWrite(bool force) { assert(versions_->PrevLogNumber() == 0); uint64_t new_log_number = versions_->NewFileNumber(); unique_ptr 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 lfile; + soptions.DisableMmapWrites(); s = options.env->NewWritableFile(LogFileName(dbname, new_log_number), &lfile, soptions); if (s.ok()) { diff --git a/db/db_test.cc b/db/db_test.cc index 38f9605758..143a1fc5c6 100644 --- a/db/db_test.cc +++ b/db/db_test.cc @@ -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 { diff --git a/util/storage_options.h b/util/storage_options.h index 9f3ec8b039..54dfb23dc0 100644 --- a/util/storage_options.h +++ b/util/storage_options.h @@ -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_;