diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2012-09-04 18:12:00 +0200 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2012-10-20 23:08:57 +0200 |
commit | e1bfbab8029c33102889d7d970da5b6cc32ff75b (patch) | |
tree | c96ed4dca6cbca2791096fe95e2e866c06016a6a /src/leveldb.cpp | |
parent | 2d8a48292b0da96cda8d7b45a24a22adfb4667b2 (diff) |
Add LevelDB MemEnv support
Support LevelDB memory-backed environments, and use them in unit tests.
Diffstat (limited to 'src/leveldb.cpp')
-rw-r--r-- | src/leveldb.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/leveldb.cpp b/src/leveldb.cpp index 29e5e6a7fd..e8a0fbe874 100644 --- a/src/leveldb.cpp +++ b/src/leveldb.cpp @@ -8,6 +8,7 @@ #include <leveldb/env.h> #include <leveldb/cache.h> #include <leveldb/filter_policy.h> +#include <memenv/memenv.h> #include <boost/filesystem.hpp> @@ -20,7 +21,7 @@ static leveldb::Options GetOptions() { return options; } -CLevelDB::CLevelDB(const boost::filesystem::path &path) { +CLevelDB::CLevelDB(const boost::filesystem::path &path, bool fMemory) { penv = NULL; readoptions.verify_checksums = true; iteroptions.verify_checksums = true; @@ -28,8 +29,13 @@ CLevelDB::CLevelDB(const boost::filesystem::path &path) { syncoptions.sync = true; options = GetOptions(); options.create_if_missing = true; - boost::filesystem::create_directory(path); - printf("Opening LevelDB in %s\n", path.string().c_str()); + if (fMemory) { + penv = leveldb::NewMemEnv(leveldb::Env::Default()); + options.env = penv; + } else { + boost::filesystem::create_directory(path); + printf("Opening LevelDB in %s\n", path.string().c_str()); + } leveldb::Status status = leveldb::DB::Open(options, path.string(), &pdb); if (!status.ok()) throw std::runtime_error(strprintf("CLevelDB(): error opening database environment %s", status.ToString().c_str())); |