10 #include <boost/filesystem.hpp>
11 #include <leveldb/cache.h>
12 #include <leveldb/env.h>
13 #include <leveldb/filter_policy.h>
20 if (status.IsCorruption())
22 if (status.IsIOError())
24 if (status.IsNotFound())
29 static leveldb::Options GetOptions(
size_t nCacheSize) {
30 leveldb::Options options;
31 options.block_cache = leveldb::NewLRUCache(nCacheSize / 2);
32 options.write_buffer_size = nCacheSize / 4;
33 options.filter_policy = leveldb::NewBloomFilterPolicy(10);
34 options.compression = leveldb::kNoCompression;
35 options.max_open_files = 64;
45 options = GetOptions(nCacheSize);
46 options.create_if_missing =
true;
48 penv = leveldb::NewMemEnv(leveldb::Env::Default());
52 LogPrintf(
"Wiping LevelDB in %s\n", path.string());
53 leveldb::DestroyDB(path.string(),
options);
56 LogPrintf(
"Opening LevelDB in %s\n", path.string());
58 leveldb::Status status = leveldb::DB::Open(
options, path.string(), &
pdb);
60 LogPrintf(
"Opened LevelDB successfully\n");
75 leveldb::Status status = pdb->Write(fSync ? syncoptions : writeoptions, &batch.batch);
leveldb::WriteOptions syncoptions
CLevelDBWrapper(const boost::filesystem::path &path, size_t nCacheSize, bool fMemory=false, bool fWipe=false)
void HandleError(const leveldb::Status &status)
bool TryCreateDirectory(const boost::filesystem::path &p)
leveldb::ReadOptions iteroptions
bool WriteBatch(CLevelDBBatch &batch, bool fSync=false)
leveldb::ReadOptions readoptions