|
|
|
@ -8,6 +8,7 @@
@@ -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() {
@@ -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) {
@@ -28,8 +29,13 @@ CLevelDB::CLevelDB(const boost::filesystem::path &path) {
|
|
|
|
|
syncoptions.sync = true; |
|
|
|
|
options = GetOptions(); |
|
|
|
|
options.create_if_missing = true; |
|
|
|
|
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())); |
|
|
|
|