mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-18 22:35:39 +01:00
Add LevelDB MemEnv support
Support LevelDB memory-backed environments, and use them in unit tests.
This commit is contained in:
@@ -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()));
|
||||
|
||||
Reference in New Issue
Block a user