7 #include <leveldb/cache.h>
8 #include <leveldb/env.h>
9 #include <leveldb/filter_policy.h>
14 static void SetMaxOpenFiles(leveldb::Options *options) {
29 int default_open_files = options->max_open_files;
31 if (
sizeof(
void*) < 8) {
32 options->max_open_files = 64;
36 options->max_open_files, default_open_files);
39 static leveldb::Options GetOptions(
size_t nCacheSize)
41 leveldb::Options options;
42 options.block_cache = leveldb::NewLRUCache(nCacheSize / 2);
43 options.write_buffer_size = nCacheSize / 4;
44 options.filter_policy = leveldb::NewBloomFilterPolicy(10);
45 options.compression = leveldb::kNoCompression;
46 if (leveldb::kMajorVersion > 1 || (leveldb::kMajorVersion == 1 && leveldb::kMinorVersion >= 16)) {
49 options.paranoid_checks =
true;
51 SetMaxOpenFiles(&options);
62 options = GetOptions(nCacheSize);
63 options.create_if_missing =
true;
66 penv = leveldb::NewMemEnv(leveldb::Env::Default());
70 LogPrintf(
"Wiping LevelDB in %s\n", path.string());
71 leveldb::Status result = leveldb::DestroyDB(path.string(),
options);
75 LogPrintf(
"Opening LevelDB in %s\n", path.string());
77 leveldb::Status status = leveldb::DB::Open(
options, path.string(), &
pdb);
79 LogPrintf(
"Opened LevelDB successfully\n");
87 options.filter_policy =
nullptr;
105 return !(it->Valid());
120 LogPrintf(
"%s\n", status.ToString());
121 if (status.IsCorruption())
123 if (status.IsIOError())
125 if (status.IsNotFound())
Batch of changes queued to be written to a CDBWrapper.
leveldb::WriteBatch batch
leveldb::Iterator * piter
CDBIterator * NewIterator()
leveldb::Env * penv
custom environment this database is using (may be nullptr in case of default environment)
bool WriteBatch(CDBBatch &batch, bool fSync=false)
CDBWrapper(const fs::path &path, size_t nCacheSize, bool fMemory=false, bool fWipe=false, int nVersion=CLIENT_VERSION)
leveldb::Options options
database options used
leveldb::WriteOptions writeoptions
options used when writing to the database
leveldb::WriteOptions syncoptions
options used when sync writing to the database
int nVersion
the version used to serialize data
leveldb::DB * pdb
the database itself
leveldb::ReadOptions iteroptions
options used when iterating over values of the database
bool IsEmpty()
Return true if the database managed by this class contains no entries.
leveldb::ReadOptions readoptions
options used when reading from the database
#define LogPrint(category,...)
These should be considered an implementation detail of the specific database.
void HandleError(const leveldb::Status &status)
Handle database error by throwing dbwrapper_error exception.
bool TryCreateDirectories(const fs::path &p)
Ignores exceptions thrown by Boost's create_directories if the requested directory exists.