From ad05cbb182c2ca869f262b097898d5c270fae7ed Mon Sep 17 00:00:00 2001 From: Zhongyi Xie Date: Mon, 26 Feb 2018 14:46:12 -0800 Subject: [PATCH] DB:Open should fail on tmpfs when use_direct_reads=true Summary: Before: > $ TEST_TMPDIR=/dev/shm ./db_bench -use_direct_reads=true -benchmarks=readrandomwriterandom -num=10000000 -reads=100000 -write_buffer_size=1048576 -target_file_size_base=1048576 -max_bytes_for_level_base=4194304 -max_background_jobs=12 -readwritepercent=50 -key_size=16 -value_size=48 -threads=32 DB path: [/dev/shm/dbbench] put error: IO error: While open a file for random read: /dev/shm/dbbench/000007.sst: Invalid argument put error: IO error: While open a file for random read: /dev/shm/dbbench/000007.sst: Invalid argument put error: IO error: While open a file for random read: /dev/shm/dbbench/000007.sst: Invalid argument put error: IO error: While open a file for random read: /dev/shm/dbbench/000007.sst: Invalid argument put error: IO error: While open a file for random read: /dev/shm/dbbench/000007.sst: Invalid argument put error: IO error: While open a file for random read: /dev/shm/dbbench/000007.sst: Invalid argument put error: IO error: While open a file for random read: /dev/shm/dbbench/000007.sst: Invalid argument put error: IO error: While open a file for random read: /dev/shm/dbbench/000007.sst: Invalid argument put error: IO error: While open a file for random read: /dev/shm/dbbench/000007.sst: Invalid argument db_bench: tpp.c:84: __pthread_tpp_change_priority: Assertion `new_prio == -1 || (new_prio >= fifo_min_prio && new_prio <= fifo_max_prio)' failed. put error: IO error: While open a file for random read: /dev/shm/dbbench/000007.sst: Invalid argument put error: IO error: While open a file for random read: /dev/shm/dbbench/000007.sst: Invalid argument After: > TEST_TMPDIR=/dev/shm ./db_bench -use_direct_reads=true -benchmarks=readrandomwriterandom -num=10000000 -reads=100000 -write_buffer_size=1048576 -target_file_size_base=1048576 -max_bytes_for_level_base=4194304 -max_background_jobs=12 -readwritepercent=50 -key_size=16 -value_size=48 -threads=32 Initializing RocksDB Options from the specified file Initializing RocksDB Options from command-line flags open error: Not implemented: Direct I/O is not supported by the specified DB. Closes https://github.com/facebook/rocksdb/pull/3539 Differential Revision: D7082658 Pulled By: miasantreble fbshipit-source-id: f9d9c6ec3b5e9e049cab52154940ee101ba4d342 --- db/db_impl_open.cc | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/db/db_impl_open.cc b/db/db_impl_open.cc index c9487b2b7..047a17b21 100644 --- a/db/db_impl_open.cc +++ b/db/db_impl_open.cc @@ -356,6 +356,29 @@ Status DBImpl::Recover( assert(s.IsIOError()); return s; } + // Verify compatibility of env_options_ and filesystem + { + unique_ptr idfile; + EnvOptions customized_env(env_options_); + customized_env.use_direct_reads |= + immutable_db_options_.use_direct_io_for_flush_and_compaction; + s = env_->NewRandomAccessFile(IdentityFileName(dbname_), &idfile, + customized_env); + if (!s.ok()) { + const char* error_msg = s.ToString().c_str(); + // Check if unsupported Direct I/O is the root cause + customized_env.use_direct_reads = false; + s = env_->NewRandomAccessFile(IdentityFileName(dbname_), &idfile, + customized_env); + if (s.ok()) { + return Status::InvalidArgument( + "Direct I/O is not supported by the specified DB."); + } else { + return Status::InvalidArgument( + "Found options incompatible with filesystem", error_msg); + } + } + } } Status s = versions_->Recover(column_families, read_only);