aboutsummaryrefslogtreecommitdiff
path: root/src/leveldb.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/leveldb.cpp')
-rw-r--r--src/leveldb.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/leveldb.cpp b/src/leveldb.cpp
index 9e2f32a171..b41764f51f 100644
--- a/src/leveldb.cpp
+++ b/src/leveldb.cpp
@@ -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;
}
-