Deal with LevelDB errors
This commit is contained in:
committed by
Pieter Wuille
parent
7851033dd6
commit
421218d304
@@ -12,6 +12,18 @@
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
void HandleError(const leveldb::Status &status) throw(leveldb_error) {
|
||||
if (status.ok())
|
||||
return;
|
||||
if (status.IsCorruption())
|
||||
throw leveldb_error("Database corrupted");
|
||||
if (status.IsIOError())
|
||||
throw leveldb_error("Database I/O error");
|
||||
if (status.IsNotFound())
|
||||
throw leveldb_error("Database entry missing");
|
||||
throw leveldb_error("Unknown database error");
|
||||
}
|
||||
|
||||
static leveldb::Options GetOptions(size_t nCacheSize) {
|
||||
leveldb::Options options;
|
||||
options.block_cache = leveldb::NewLRUCache(nCacheSize / 2);
|
||||
@@ -57,12 +69,12 @@ CLevelDB::~CLevelDB() {
|
||||
options.env = NULL;
|
||||
}
|
||||
|
||||
bool CLevelDB::WriteBatch(CLevelDBBatch &batch, bool fSync) {
|
||||
bool CLevelDB::WriteBatch(CLevelDBBatch &batch, bool fSync) throw(leveldb_error) {
|
||||
leveldb::Status status = pdb->Write(fSync ? syncoptions : writeoptions, &batch.batch);
|
||||
if (!status.ok()) {
|
||||
printf("LevelDB write failure: %s\n", status.ToString().c_str());
|
||||
HandleError(status);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user