diff --git a/db/builder.cc b/db/builder.cc index afeafba2ec9159ee2fa70cedde805bc46827ae24..2b7c5928321640bd21b612de843a41f16360696d 100644 --- a/db/builder.cc +++ b/db/builder.cc @@ -19,7 +19,7 @@ namespace leveldb { Status BuildTable(const std::string& dbname, Env* env, const Options& options, - const StorageOptions& soptions, + const EnvOptions& soptions, TableCache* table_cache, Iterator* iter, FileMetaData* meta, diff --git a/db/builder.h b/db/builder.h index 3c076eafa038e2ad7854ed27d5753c8b00ca0fd4..32cc6e76d4ea55052d0ddb7ac1c2e2d4da074789 100644 --- a/db/builder.h +++ b/db/builder.h @@ -8,7 +8,6 @@ #include "leveldb/comparator.h" #include "leveldb/status.h" #include "leveldb/types.h" -#include "util/storage_options.h" namespace leveldb { @@ -16,6 +15,7 @@ struct Options; struct FileMetaData; class Env; +class EnvOptions; class Iterator; class TableCache; class VersionEdit; @@ -28,7 +28,7 @@ class VersionEdit; extern Status BuildTable(const std::string& dbname, Env* env, const Options& options, - const StorageOptions& soptions, + const EnvOptions& soptions, TableCache* table_cache, Iterator* iter, FileMetaData* meta, diff --git a/db/db_bench.cc b/db/db_bench.cc index c743f4f2bc585bc1ab10e3a6ed9692292bea5af8..7105e0cdbf92c71b89fc006c421759f78bc12821 100644 --- a/db/db_bench.cc +++ b/db/db_bench.cc @@ -1157,7 +1157,6 @@ unique_ptr GenerateKeyFromInt(int v, const char* suffix = "") options.allow_readahead = FLAGS_use_fsreadahead; options.allow_mmap_reads = FLAGS_use_mmap_reads; options.allow_mmap_writes = FLAGS_use_mmap_writes; - options.allow_readahead_compactions = FLAGS_use_readahead_compactions; options.advise_random_on_open = FLAGS_advise_random_on_open; options.access_hint_on_compaction_start = FLAGS_compaction_fadvice; @@ -1714,7 +1713,7 @@ unique_ptr GenerateKeyFromInt(int v, const char* suffix = "") void HeapProfile() { char fname[100]; - StorageOptions soptions; + EnvOptions soptions; snprintf(fname, sizeof(fname), "%s/heap-%04d", FLAGS_db, ++heap_counter_); unique_ptr file; Status s = FLAGS_env->NewWritableFile(fname, &file, soptions); @@ -1742,12 +1741,9 @@ int main(int argc, char** argv) { leveldb::Options().max_background_compactions; // Compression test code above refers to FLAGS_block_size FLAGS_block_size = leveldb::Options().block_size; - FLAGS_use_os_buffer = leveldb::StorageOptions().UseOsBuffer(); - FLAGS_use_fsreadahead = leveldb::StorageOptions().UseReadahead(); - FLAGS_use_mmap_reads = leveldb::StorageOptions().UseMmapReads(); - FLAGS_use_mmap_writes = leveldb::StorageOptions().UseMmapWrites(); - FLAGS_use_readahead_compactions = - leveldb::StorageOptions().UseReadaheadCompactions(); + FLAGS_use_os_buffer = leveldb::EnvOptions().use_os_buffer; + FLAGS_use_mmap_reads = leveldb::EnvOptions().use_mmap_reads; + FLAGS_use_mmap_writes = leveldb::EnvOptions().use_mmap_writes; std::string default_db_path; diff --git a/db/db_impl.cc b/db/db_impl.cc index 37e22b0052bb48fd9aa92f571e6981a7e85a52d3..9726a7166f51f533e9736ce4fd1813ce92f0e899 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -2393,8 +2393,8 @@ Status DBImpl::MakeRoomForWrite(bool force) { assert(versions_->PrevLogNumber() == 0); uint64_t new_log_number = versions_->NewFileNumber(); unique_ptr lfile; - StorageOptions soptions(storage_options_); - soptions.DisableMmapWrites(); + EnvOptions soptions(storage_options_); + soptions.use_mmap_writes = false; s = env_->NewWritableFile( LogFileName(dbname_, new_log_number), &lfile, @@ -2668,7 +2668,7 @@ DB::~DB() { } Status DB::Open(const Options& options, const std::string& dbname, DB** dbptr) { *dbptr = nullptr; - StorageOptions soptions; + EnvOptions soptions; if (options.block_cache != nullptr && options.no_block_cache) { return Status::InvalidArgument( @@ -2686,7 +2686,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(); + soptions.use_mmap_writes = false; s = options.env->NewWritableFile(LogFileName(dbname, new_log_number), &lfile, soptions); if (s.ok()) { diff --git a/db/db_impl.h b/db/db_impl.h index 321eb79b0c7fb88855ea441de4b02c800f2f6ca3..ca00953378dca25c18212ff1a06545ea5fed3aed 100644 --- a/db/db_impl.h +++ b/db/db_impl.h @@ -366,7 +366,7 @@ class DBImpl : public DB { SequenceNumber last_flushed_sequence_; // The options to access storage files - const StorageOptions storage_options_; + const EnvOptions storage_options_; // No copying allowed DBImpl(const DBImpl&); diff --git a/db/db_test.cc b/db/db_test.cc index 62da02171dac6fdbc789989a4c5548ab21744f2f..7ce4ac4198be65b904927bc6b3c2acc4469eb29c 100644 --- a/db/db_test.cc +++ b/db/db_test.cc @@ -20,7 +20,6 @@ #include "util/mutexlock.h" #include "util/testharness.h" #include "util/testutil.h" -#include "util/storage_options.h" #include "utilities/merge_operators.h" namespace leveldb { @@ -606,7 +605,7 @@ TEST(DBTest, LevelLimitReopen) { TEST(DBTest, Preallocation) { const std::string src = dbname_ + "/alloc_test"; unique_ptr srcfile; - const StorageOptions soptions; + const EnvOptions soptions; ASSERT_OK(env_->NewWritableFile(src, &srcfile, soptions)); srcfile->SetPreallocationBlockSize(1024 * 1024); @@ -2383,7 +2382,7 @@ TEST(DBTest, BloomFilter) { TEST(DBTest, SnapshotFiles) { Options options = CurrentOptions(); - const StorageOptions soptions; + const EnvOptions soptions; options.write_buffer_size = 100000000; // Large write buffer Reopen(&options); @@ -3299,7 +3298,7 @@ void BM_LogAndApply(int iters, int num_base_files) { InternalKeyComparator cmp(BytewiseComparator()); Options options; - StorageOptions sopt; + EnvOptions sopt; VersionSet vset(dbname, &options, sopt, nullptr, &cmp); ASSERT_OK(vset.Recover()); VersionEdit vbase(vset.NumberLevels()); diff --git a/db/repair.cc b/db/repair.cc index b505b1a996e42195e5b0dae84f1a0962f979ebbe..d1c0c45255e460ab89e66640544b0c90488eacd3 100644 --- a/db/repair.cc +++ b/db/repair.cc @@ -105,7 +105,7 @@ class Repairer { std::vector logs_; std::vector tables_; uint64_t next_file_number_; - const StorageOptions storage_options_; + const EnvOptions storage_options_; Status FindFiles() { std::vector filenames; diff --git a/db/table_cache.cc b/db/table_cache.cc index 90b64b0a53c26dc5092631299807d324765409b3..d7afa0a557b530749065afaacc61c8da20ff265b 100644 --- a/db/table_cache.cc +++ b/db/table_cache.cc @@ -26,7 +26,7 @@ static void UnrefEntry(void* arg1, void* arg2) { TableCache::TableCache(const std::string& dbname, const Options* options, - const StorageOptions& storage_options, + const EnvOptions& storage_options, int entries) : env_(options->env), dbname_(dbname), diff --git a/db/table_cache.h b/db/table_cache.h index 83644b1dadcd7366d2893774e86b4886ee7273fc..c3996a3cc56fbfed7401da26bcd4847f33b910f9 100644 --- a/db/table_cache.h +++ b/db/table_cache.h @@ -14,7 +14,6 @@ #include "leveldb/cache.h" #include "port/port.h" #include "table/table.h" -#include "util/storage_options.h" namespace leveldb { @@ -23,7 +22,7 @@ class Env; class TableCache { public: TableCache(const std::string& dbname, const Options* options, - const StorageOptions& storage_options, int entries); + const EnvOptions& storage_options, int entries); ~TableCache(); // Return an iterator for the specified file number (the corresponding @@ -58,7 +57,7 @@ class TableCache { Env* const env_; const std::string dbname_; const Options* options_; - const StorageOptions& storage_options_; + const EnvOptions& storage_options_; std::shared_ptr cache_; Status FindTable(const EnvOptions& toptions, diff --git a/db/transaction_log_iterator_impl.cc b/db/transaction_log_iterator_impl.cc index 0b1f47d728f5eb0327e9413f5a30074c328cb441..f8e4f8b26a98122b268dec926b8cb2870e83fbe4 100644 --- a/db/transaction_log_iterator_impl.cc +++ b/db/transaction_log_iterator_impl.cc @@ -7,7 +7,7 @@ namespace leveldb { TransactionLogIteratorImpl::TransactionLogIteratorImpl( const std::string& dbname, const Options* options, - const StorageOptions& soptions, + const EnvOptions& soptions, SequenceNumber& seq, std::unique_ptr> files, SequenceNumber const * const lastFlushedSequence) : diff --git a/db/transaction_log_iterator_impl.h b/db/transaction_log_iterator_impl.h index 90fd1fcf05c1da19cb3baef8987fb9e543472c22..faf07f43fb3ec1cf411ca8a8dc8706b6e2467773 100644 --- a/db/transaction_log_iterator_impl.h +++ b/db/transaction_log_iterator_impl.h @@ -10,7 +10,6 @@ #include "leveldb/transaction_log_iterator.h" #include "db/log_file.h" #include "db/log_reader.h" -#include "util/storage_options.h" namespace leveldb { @@ -26,7 +25,7 @@ class TransactionLogIteratorImpl : public TransactionLogIterator { public: TransactionLogIteratorImpl(const std::string& dbname, const Options* options, - const StorageOptions& soptions, + const EnvOptions& soptions, SequenceNumber& seqNum, std::unique_ptr> files, SequenceNumber const * const lastFlushedSequence); @@ -42,7 +41,7 @@ class TransactionLogIteratorImpl : public TransactionLogIterator { private: const std::string& dbname_; const Options* options_; - const StorageOptions& soptions_; + const EnvOptions& soptions_; const uint64_t startingSequenceNumber_; std::unique_ptr> files_; bool started_; diff --git a/db/version_set.cc b/db/version_set.cc index c1d81f48b0b97addbf322269eff22924c23132bd..57db906c5b24620701bf20232b01d8cf92b8d73f 100644 --- a/db/version_set.cc +++ b/db/version_set.cc @@ -198,7 +198,7 @@ static Iterator* GetFileIterator(void* arg, } Iterator* Version::NewConcatenatingIterator(const ReadOptions& options, - const StorageOptions& soptions, + const EnvOptions& soptions, int level) const { return NewTwoLevelIterator( new LevelFileNumIterator(vset_->icmp_, &files_[level]), @@ -206,7 +206,7 @@ Iterator* Version::NewConcatenatingIterator(const ReadOptions& options, } void Version::AddIterators(const ReadOptions& options, - const StorageOptions& soptions, + const EnvOptions& soptions, std::vector* iters) { // Merge all level zero files together since they may overlap for (size_t i = 0; i < files_[0].size(); i++) { @@ -971,7 +971,7 @@ class VersionSet::Builder { VersionSet::VersionSet(const std::string& dbname, const Options* options, - const StorageOptions& storage_options, + const EnvOptions& storage_options, TableCache* table_cache, const InternalKeyComparator* cmp) : env_(options->env), diff --git a/db/version_set.h b/db/version_set.h index c596a58570cb6e3c1bcb35bbb1197bf7d279583b..ba924126f4f0583392ccfac0030f77d265a1f3c1 100644 --- a/db/version_set.h +++ b/db/version_set.h @@ -63,7 +63,7 @@ class Version { // Append to *iters a sequence of iterators that will // yield the contents of this Version when merged together. // REQUIRES: This version has been saved (see VersionSet::SaveTo) - void AddIterators(const ReadOptions&, const StorageOptions& soptions, + void AddIterators(const ReadOptions&, const EnvOptions& soptions, std::vector* iters); // Lookup the value for key. If found, store it in *val and @@ -138,7 +138,7 @@ class Version { class LevelFileNumIterator; Iterator* NewConcatenatingIterator(const ReadOptions&, - const StorageOptions& soptions, + const EnvOptions& soptions, int level) const; VersionSet* vset_; // VersionSet to which this Version belongs @@ -207,7 +207,7 @@ class VersionSet { public: VersionSet(const std::string& dbname, const Options* options, - const StorageOptions& storage_options, + const EnvOptions& storage_options, TableCache* table_cache, const InternalKeyComparator*); ~VersionSet(); @@ -458,11 +458,11 @@ class VersionSet { uint64_t last_observed_manifest_size_; // storage options for all reads and writes except compactions - const StorageOptions& storage_options_; + const EnvOptions& storage_options_; // storage options used for compactions. This is a copy of // storage_options_ but with readaheads set to readahead_compactions_. - const StorageOptions storage_options_compactions_; + const EnvOptions storage_options_compactions_; // No copying allowed VersionSet(const VersionSet&); diff --git a/helpers/memenv/memenv_test.cc b/helpers/memenv/memenv_test.cc index b58e22dbd515f705a5bc847a4e81355cf0ef743b..1c6dd1509154edee39042c8009df44504522579f 100644 --- a/helpers/memenv/memenv_test.cc +++ b/helpers/memenv/memenv_test.cc @@ -8,7 +8,6 @@ #include "leveldb/db.h" #include "leveldb/env.h" #include "util/testharness.h" -#include "util/storage_options.h" #include #include #include @@ -18,7 +17,7 @@ namespace leveldb { class MemEnvTest { public: Env* env_; - const StorageOptions soptions_; + const EnvOptions soptions_; MemEnvTest() : env_(NewMemEnv(Env::Default())) { diff --git a/include/leveldb/env.h b/include/leveldb/env.h index a3e33d6c158b8590192eab3109e1b71c6e19f2e0..7d70ef8f599c979dec94e03e56965c11ba6fa420 100644 --- a/include/leveldb/env.h +++ b/include/leveldb/env.h @@ -23,16 +23,40 @@ namespace leveldb { class FileLock; -class EnvOptions; class Logger; class RandomAccessFile; class SequentialFile; class Slice; class WritableFile; +class Options; using std::unique_ptr; using std::shared_ptr; + +// Options while opening a file to read/write +struct EnvOptions { + + // construct with default Options + EnvOptions(); + + // construct from Options + EnvOptions(const Options& options); + + // If true, then allow caching of data in environment buffers + bool use_os_buffer; + + // If true, then use mmap to read data + bool use_mmap_reads; + + // If true, then use mmap to write data + bool use_mmap_writes; + + // If true, set the FD_CLOEXEC on open fd. + bool set_fd_cloexec; + +}; + class Env { public: Env() { } @@ -375,27 +399,6 @@ class FileLock { void operator=(const FileLock&); }; -// Options while opening a file to read/write -class EnvOptions { - public: - virtual ~EnvOptions() {} - - // If true, then allow caching of data in environment buffers - virtual bool UseOsBuffer() const = 0; - - // If true, then allow the environment to readahead data - virtual bool UseReadahead() const = 0; - - // If true, then use mmap to read data - virtual bool UseMmapReads() const = 0; - - // If true, then use mmap to write data - virtual bool UseMmapWrites() const = 0; - - // If true, set the FD_CLOEXEC on open fd. - virtual bool IsFDCloseOnExec() const = 0; -}; - // Log the specified data to *info_log if info_log is non-nullptr. extern void Log(const shared_ptr& info_log, const char* format, ...) # if defined(__GNUC__) || defined(__clang__) diff --git a/include/leveldb/options.h b/include/leveldb/options.h index d25b26f9002be3d4e9fdaba7ccb89d6ee0c1603a..92b9d3726b374946ac51dbd21fd95cc2d581655a 100644 --- a/include/leveldb/options.h +++ b/include/leveldb/options.h @@ -409,11 +409,13 @@ struct Options { // Reading a single block from a file can cause the OS/FS to start // readaheads of other blocks from the file. Default: true + // Note: Deprecated bool allow_readahead; // The reads triggered by compaction allows data to be readahead // by the OS/FS. This overrides the setting of 'allow_readahead' // for compaction-reads. Default: true + // Note: Deprecated bool allow_readahead_compactions; // Allow the OS to mmap file for reading. Default: false diff --git a/table/table_test.cc b/table/table_test.cc index 5770eacb550130fe586d6d92bbad178c4f532807..a2bba940dc9cd4e160cf2b374f2a687f8eef26fc 100644 --- a/table/table_test.cc +++ b/table/table_test.cc @@ -293,7 +293,7 @@ class TableConstructor: public Constructor { TableConstructor(); static uint64_t cur_uniq_id_; - const StorageOptions soptions; + const EnvOptions soptions; }; uint64_t TableConstructor::cur_uniq_id_ = 1; diff --git a/tools/db_stress.cc b/tools/db_stress.cc index 791ff25c16af76f5fe34d1802045281c4c23a816..571d690ebf9808f70e2cdc374121921fec43ceac 100644 --- a/tools/db_stress.cc +++ b/tools/db_stress.cc @@ -177,10 +177,6 @@ static uint32_t FLAGS_log2_keys_per_lock = 2; // implies 2^2 keys per lock // Percentage of times we want to purge redundant keys in memory before flushing static uint32_t FLAGS_purge_redundant_percent = 50; -extern bool useOsBuffer; -extern bool useFsReadAhead; -extern bool useMmapRead; - namespace leveldb { class StressTest; @@ -1069,15 +1065,6 @@ int main(int argc, char** argv) { } else if (sscanf(argv[i], "--verify_checksum=%d%c", &n, &junk) == 1 && (n == 0 || n == 1)) { FLAGS_verify_checksum = n; - } else if (sscanf(argv[i], "--bufferedio=%d%c", &n, &junk) == 1 && - (n == 0 || n == 1)) { - useOsBuffer = n; - } else if (sscanf(argv[i], "--mmap_read=%d%c", &n, &junk) == 1 && - (n == 0 || n == 1)) { - useMmapRead = n; - } else if (sscanf(argv[i], "--readhead=%d%c", &n, &junk) == 1 && - (n == 0 || n == 1)) { - useFsReadAhead = n; } else if (sscanf(argv[i], "--statistics=%d%c", &n, &junk) == 1 && (n == 0 || n == 1)) { if (n == 1) { diff --git a/tools/sst_dump.cc b/tools/sst_dump.cc index b606fa51de7f6b64838eba851c32bc405e05a83a..27afe437ee7a1f60c28c83e6bd774e603769b1a9 100644 --- a/tools/sst_dump.cc +++ b/tools/sst_dump.cc @@ -34,7 +34,7 @@ private: uint64_t read_num_; bool verify_checksum_; bool output_hex_; - StorageOptions soptions_; + EnvOptions soptions_; }; SstFileReader::SstFileReader(std::string file_path, diff --git a/util/env.cc b/util/env.cc index 830a144bd235219531ec2ef7fb62ed62eb101c5d..c17389a3de1e3de5aec5d273e15b5a841f0420cd 100644 --- a/util/env.cc +++ b/util/env.cc @@ -3,7 +3,7 @@ // found in the LICENSE file. See the AUTHORS file for names of contributors. #include "leveldb/env.h" -#include "util/storage_options.h" +#include "leveldb/options.h" namespace leveldb { @@ -47,7 +47,7 @@ static Status DoWriteStringToFile(Env* env, const Slice& data, const std::string& fname, bool should_sync) { unique_ptr file; - StorageOptions soptions; + EnvOptions soptions; Status s = env->NewWritableFile(fname, &file, soptions); if (!s.ok()) { return s; @@ -73,7 +73,7 @@ Status WriteStringToFileSync(Env* env, const Slice& data, } Status ReadFileToString(Env* env, const std::string& fname, std::string* data) { - StorageOptions soptions; + EnvOptions soptions; data->clear(); unique_ptr file; Status s = env->NewSequentialFile(fname, &file, soptions); @@ -100,4 +100,25 @@ Status ReadFileToString(Env* env, const std::string& fname, std::string* data) { EnvWrapper::~EnvWrapper() { } +namespace { // anonymous namespace + +void AssignEnvOptions(EnvOptions* env_options, const Options& options) { + env_options->use_os_buffer = options.allow_os_buffer; + env_options->use_mmap_reads = options.allow_mmap_reads; + env_options->use_mmap_writes = options.allow_mmap_writes; + env_options->set_fd_cloexec = options.is_fd_close_on_exec; +} + +} + +EnvOptions::EnvOptions(const Options& options) { + AssignEnvOptions(this, options); +} + +EnvOptions::EnvOptions() { + Options options; + AssignEnvOptions(this, options); +} + + } // namespace leveldb diff --git a/util/env_posix.cc b/util/env_posix.cc index 3c111bca3181f6801d9182b3bf08828c520b4dbb..1388566c5e7e4fbd764bca33d99de7b6fa46b248 100644 --- a/util/env_posix.cc +++ b/util/env_posix.cc @@ -45,11 +45,6 @@ #define EXT4_SUPER_MAGIC 0xEF53 #endif -bool useOsBuffer = 1; // cache data in OS buffers -bool useFsReadAhead = 1; // allow filesystem to do readaheads -bool useMmapRead = 0; // do not use mmaps for reading files -bool useMmapWrite = 1; // use mmaps for appending to files - // This is only set from db_stress.cc and for testing only. // If non-zero, kill at various points in source code with probability 1/this int leveldb_kill_odds = 0; @@ -111,8 +106,8 @@ class PosixSequentialFile: public SequentialFile { PosixSequentialFile(const std::string& fname, FILE* f, const EnvOptions& options) : filename_(fname), file_(f), fd_(fileno(f)), - use_os_buffer_(options.UseOsBuffer()) { - assert(!options.UseMmapReads()); + use_os_buffer_(options.use_os_buffer) { + assert(!options.use_mmap_reads); } virtual ~PosixSequentialFile() { fclose(file_); } @@ -154,11 +149,8 @@ class PosixRandomAccessFile: public RandomAccessFile { public: PosixRandomAccessFile(const std::string& fname, int fd, const EnvOptions& options) - : filename_(fname), fd_(fd), use_os_buffer_(options.UseOsBuffer()) { - assert(!options.UseMmapReads()); - if (!options.UseReadahead()) { // disable read-aheads - posix_fadvise(fd, 0, 0, POSIX_FADV_RANDOM); - } + : filename_(fname), fd_(fd), use_os_buffer_(options.use_os_buffer) { + assert(!options.use_mmap_reads); } virtual ~PosixRandomAccessFile() { close(fd_); } @@ -245,9 +237,8 @@ class PosixMmapReadableFile: public RandomAccessFile { PosixMmapReadableFile(const std::string& fname, void* base, size_t length, const EnvOptions& options) : filename_(fname), mmapped_region_(base), length_(length) { - assert(options.UseMmapReads()); - assert(options.UseOsBuffer()); - assert(options.UseReadahead()); + assert(options.use_mmap_reads); + assert(options.use_os_buffer); } virtual ~PosixMmapReadableFile() { munmap(mmapped_region_, length_); } @@ -359,7 +350,7 @@ class PosixMmapFile : public WritableFile { file_offset_(0), pending_sync_(false) { assert((page_size & (page_size - 1)) == 0); - assert(options.UseMmapWrites()); + assert(options.use_mmap_writes); } @@ -524,7 +515,7 @@ class PosixWritableFile : public WritableFile { filesize_(0), pending_sync_(false), pending_fsync_(false) { - assert(!options.UseMmapWrites()); + assert(!options.use_mmap_writes); } ~PosixWritableFile() { @@ -703,7 +694,7 @@ class PosixEnv : public Env { } void SetFD_CLOEXEC(int fd, const EnvOptions* options) { - if ((options == nullptr || options->IsFDCloseOnExec()) && fd > 0) { + if ((options == nullptr || options->set_fd_cloexec) && fd > 0) { fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC); } } @@ -733,7 +724,7 @@ class PosixEnv : public Env { SetFD_CLOEXEC(fd, &options); if (fd < 0) { s = IOError(fname, errno); - } else if (options.UseMmapReads() && sizeof(void*) >= 8) { + } else if (options.use_mmap_reads && sizeof(void*) >= 8) { // Use of mmap for random reads has been removed because it // kills performance when storage is fast. // Use mmap when virtual address-space is plentiful. @@ -764,7 +755,7 @@ class PosixEnv : public Env { s = IOError(fname, errno); } else { SetFD_CLOEXEC(fd, &options); - if (options.UseMmapWrites()) { + if (options.use_mmap_writes) { if (!checkedDiskForMmap_) { // this will be executed once in the program's lifetime. // do not use mmapWrite on non ext-3/xfs/tmpfs systems. @@ -774,7 +765,7 @@ class PosixEnv : public Env { checkedDiskForMmap_ = true; } } - if (options.UseMmapWrites() && !forceMmapOff) { + if (options.use_mmap_writes && !forceMmapOff) { result->reset(new PosixMmapFile(fname, fd, page_size_, options)); } else { result->reset(new PosixWritableFile(fname, fd, 65536, options)); diff --git a/util/env_test.cc b/util/env_test.cc index b0dff593f2d5c1bfec9f85947283480490aa951f..4f899f149fc229187b022744af6a2852ec91d0b4 100644 --- a/util/env_test.cc +++ b/util/env_test.cc @@ -8,7 +8,6 @@ #include "port/port.h" #include "util/coding.h" #include "util/testharness.h" -#include "util/storage_options.h" namespace leveldb { @@ -120,7 +119,7 @@ char temp_id[MAX_ID_SIZE]; TEST(EnvPosixTest, RandomAccessUniqueID) { // Create file. - const StorageOptions soptions; + const EnvOptions soptions; std::string fname = test::TmpDir() + "/" + "testfile"; unique_ptr wfile; ASSERT_OK(env_->NewWritableFile(fname, &wfile, soptions)); @@ -174,7 +173,7 @@ bool HasPrefix(const std::unordered_set& ss) { TEST(EnvPosixTest, RandomAccessUniqueIDConcurrent) { // Check whether a bunch of concurrently existing files have unique IDs. - const StorageOptions soptions; + const EnvOptions soptions; // Create the files std::vector fnames; @@ -210,7 +209,7 @@ TEST(EnvPosixTest, RandomAccessUniqueIDConcurrent) { } TEST(EnvPosixTest, RandomAccessUniqueIDDeletes) { - const StorageOptions soptions; + const EnvOptions soptions; std::string fname = test::TmpDir() + "/" + "testfile"; // Check that after file is deleted we don't get same ID again in a new file. diff --git a/util/ldb_cmd.cc b/util/ldb_cmd.cc index 9b96d0e0936567238d9c38f3fcd0f69d8f1e88cf..9985bad86ac148e68a52f1fa2d6bb0699d669670 100644 --- a/util/ldb_cmd.cc +++ b/util/ldb_cmd.cc @@ -503,7 +503,7 @@ void ManifestDumpCommand::DoCommand() { } Options options; - StorageOptions sopt; + EnvOptions sopt; std::string file(manifestfile); std::string dbname("dummy"); TableCache* tc = new TableCache(dbname, &options, sopt, 10); @@ -691,7 +691,7 @@ Options ReduceDBLevelsCommand::PrepareOptionsForOpenDB() { Status ReduceDBLevelsCommand::GetOldNumOfLevels(Options& opt, int* levels) { - StorageOptions soptions; + EnvOptions soptions; TableCache tc(db_path_, &opt, soptions, 10); const InternalKeyComparator cmp(opt.comparator); VersionSet versions(db_path_, &opt, soptions, &tc, &cmp); @@ -748,7 +748,7 @@ void ReduceDBLevelsCommand::DoCommand() { db_->CompactRange(nullptr, nullptr); CloseDB(); - StorageOptions soptions; + EnvOptions soptions; TableCache tc(db_path_, &opt, soptions, 10); const InternalKeyComparator cmp(opt.comparator); VersionSet versions(db_path_, &opt, soptions, &tc, &cmp); @@ -840,7 +840,7 @@ void WALDumperCommand::DoCommand() { unique_ptr file; Env* env_ = Env::Default(); - StorageOptions soptions; + EnvOptions soptions; Status status = env_->NewSequentialFile(wal_file_, &file, soptions); if (!status.ok()) { exec_state_ = LDBCommandExecuteResult::FAILED("Failed to open WAL file " + diff --git a/util/storage_options.h b/util/storage_options.h deleted file mode 100644 index bd01094a50f5a0661ff1d8b45c6eac22bf0f66a2..0000000000000000000000000000000000000000 --- a/util/storage_options.h +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright (c) 2011 The LevelDB Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. See the AUTHORS file for names of contributors. -// -#ifndef STORAGE_LEVELDB_UTIL_STORAGE_OPTIONS_H_ -#define STORAGE_LEVELDB_UTIL_STORAGE_OPTIONS_H_ - -#include -#include -#include "leveldb/env.h" -#include "leveldb/options.h" - -namespace leveldb { - -// Environment Options that are used to read files from storage -class StorageOptions : public EnvOptions { - public: - /* implicit */ StorageOptions(const Options& opt) : - data_in_os_(opt.allow_os_buffer), - fs_readahead_(opt.allow_readahead), - readahead_compactions_(opt.allow_readahead_compactions), - use_mmap_reads_(opt.allow_mmap_reads), - use_mmap_writes_(opt.allow_mmap_writes), - set_fd_cloexec_(opt.is_fd_close_on_exec) { - } - - // copy constructor with readaheads set to readahead_compactions_ - StorageOptions(const StorageOptions& opt) { - data_in_os_ = opt.UseOsBuffer(); - fs_readahead_ = opt.UseReadaheadCompactions(); - readahead_compactions_ = opt.UseReadaheadCompactions(); - use_mmap_reads_ = opt.UseMmapReads(); - use_mmap_writes_ = opt.UseMmapWrites(); - set_fd_cloexec_ = opt.IsFDCloseOnExec(); - } - - // constructor with default options - StorageOptions() { - Options opt; - data_in_os_ = opt.allow_os_buffer; - fs_readahead_ = opt.allow_readahead; - readahead_compactions_ = fs_readahead_; - use_mmap_reads_ = opt.allow_mmap_reads; - use_mmap_writes_ = opt.allow_mmap_writes; - set_fd_cloexec_ = opt.is_fd_close_on_exec; - } - - virtual ~StorageOptions() {} - - bool UseOsBuffer() const { return data_in_os_; }; - bool UseReadahead() const { return fs_readahead_; }; - bool UseMmapReads() const { return use_mmap_reads_; } - bool UseMmapWrites() const { return use_mmap_writes_; } - bool UseReadaheadCompactions() const { return readahead_compactions_;} - bool IsFDCloseOnExec() const { return set_fd_cloexec_;} - - void DisableMmapWrites() { - use_mmap_writes_ = false; - } - - private: - bool data_in_os_; - bool fs_readahead_; - bool readahead_compactions_; - bool use_mmap_reads_; - bool use_mmap_writes_; - bool set_fd_cloexec_; -}; - -} // namespace leveldb - -#endif // STORAGE_LEVELDB_UTIL_STORAGE_OPTIONS_H_