aboutsummaryrefslogtreecommitdiff
path: root/src/leveldb.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2013-01-29 01:44:19 +0100
committerPieter Wuille <pieterw@google.com>2013-01-30 04:30:02 +0100
commit421218d3040279c84616891e8d14b05576b07c57 (patch)
treea1d1546c823d593008866a3790c0c71cbe4c10de /src/leveldb.cpp
parent7851033dd687e826df82c1ec841480710468ce8c (diff)
Deal with LevelDB errors
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;
}
-