dbwrapper: Move HandleError
to dbwrapper_private
HandleError is implementation-specific.
This commit is contained in:
parent
b69836d6ff
commit
869cf1234a
2 changed files with 23 additions and 21 deletions
|
@ -15,20 +15,6 @@
|
||||||
#include <memenv.h>
|
#include <memenv.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
void HandleError(const leveldb::Status& status)
|
|
||||||
{
|
|
||||||
if (status.ok())
|
|
||||||
return;
|
|
||||||
LogPrintf("%s\n", status.ToString());
|
|
||||||
if (status.IsCorruption())
|
|
||||||
throw dbwrapper_error("Database corrupted");
|
|
||||||
if (status.IsIOError())
|
|
||||||
throw dbwrapper_error("Database I/O error");
|
|
||||||
if (status.IsNotFound())
|
|
||||||
throw dbwrapper_error("Database entry missing");
|
|
||||||
throw dbwrapper_error("Unknown database error");
|
|
||||||
}
|
|
||||||
|
|
||||||
static leveldb::Options GetOptions(size_t nCacheSize)
|
static leveldb::Options GetOptions(size_t nCacheSize)
|
||||||
{
|
{
|
||||||
leveldb::Options options;
|
leveldb::Options options;
|
||||||
|
@ -61,13 +47,13 @@ CDBWrapper::CDBWrapper(const boost::filesystem::path& path, size_t nCacheSize, b
|
||||||
if (fWipe) {
|
if (fWipe) {
|
||||||
LogPrintf("Wiping LevelDB in %s\n", path.string());
|
LogPrintf("Wiping LevelDB in %s\n", path.string());
|
||||||
leveldb::Status result = leveldb::DestroyDB(path.string(), options);
|
leveldb::Status result = leveldb::DestroyDB(path.string(), options);
|
||||||
HandleError(result);
|
dbwrapper_private::HandleError(result);
|
||||||
}
|
}
|
||||||
TryCreateDirectory(path);
|
TryCreateDirectory(path);
|
||||||
LogPrintf("Opening LevelDB in %s\n", path.string());
|
LogPrintf("Opening LevelDB in %s\n", path.string());
|
||||||
}
|
}
|
||||||
leveldb::Status status = leveldb::DB::Open(options, path.string(), &pdb);
|
leveldb::Status status = leveldb::DB::Open(options, path.string(), &pdb);
|
||||||
HandleError(status);
|
dbwrapper_private::HandleError(status);
|
||||||
LogPrintf("Opened LevelDB successfully\n");
|
LogPrintf("Opened LevelDB successfully\n");
|
||||||
|
|
||||||
// The base-case obfuscation key, which is a noop.
|
// The base-case obfuscation key, which is a noop.
|
||||||
|
@ -105,7 +91,7 @@ CDBWrapper::~CDBWrapper()
|
||||||
bool CDBWrapper::WriteBatch(CDBBatch& batch, bool fSync)
|
bool CDBWrapper::WriteBatch(CDBBatch& batch, bool fSync)
|
||||||
{
|
{
|
||||||
leveldb::Status status = pdb->Write(fSync ? syncoptions : writeoptions, &batch.batch);
|
leveldb::Status status = pdb->Write(fSync ? syncoptions : writeoptions, &batch.batch);
|
||||||
HandleError(status);
|
dbwrapper_private::HandleError(status);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,6 +129,20 @@ void CDBIterator::Next() { piter->Next(); }
|
||||||
|
|
||||||
namespace dbwrapper_private {
|
namespace dbwrapper_private {
|
||||||
|
|
||||||
|
void HandleError(const leveldb::Status& status)
|
||||||
|
{
|
||||||
|
if (status.ok())
|
||||||
|
return;
|
||||||
|
LogPrintf("%s\n", status.ToString());
|
||||||
|
if (status.IsCorruption())
|
||||||
|
throw dbwrapper_error("Database corrupted");
|
||||||
|
if (status.IsIOError())
|
||||||
|
throw dbwrapper_error("Database I/O error");
|
||||||
|
if (status.IsNotFound())
|
||||||
|
throw dbwrapper_error("Database entry missing");
|
||||||
|
throw dbwrapper_error("Unknown database error");
|
||||||
|
}
|
||||||
|
|
||||||
const std::vector<unsigned char>& GetObfuscateKey(const CDBWrapper &w)
|
const std::vector<unsigned char>& GetObfuscateKey(const CDBWrapper &w)
|
||||||
{
|
{
|
||||||
return w.obfuscate_key;
|
return w.obfuscate_key;
|
||||||
|
|
|
@ -23,14 +23,16 @@ public:
|
||||||
dbwrapper_error(const std::string& msg) : std::runtime_error(msg) {}
|
dbwrapper_error(const std::string& msg) : std::runtime_error(msg) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
void HandleError(const leveldb::Status& status);
|
|
||||||
|
|
||||||
class CDBWrapper;
|
class CDBWrapper;
|
||||||
|
|
||||||
/** These should be considered an implementation detail of the specific database.
|
/** These should be considered an implementation detail of the specific database.
|
||||||
*/
|
*/
|
||||||
namespace dbwrapper_private {
|
namespace dbwrapper_private {
|
||||||
|
|
||||||
|
/** Handle database error by throwing dbwrapper_error exception.
|
||||||
|
*/
|
||||||
|
void HandleError(const leveldb::Status& status);
|
||||||
|
|
||||||
/** Work around circular dependency, as well as for testing in dbwrapper_tests.
|
/** Work around circular dependency, as well as for testing in dbwrapper_tests.
|
||||||
* Database obfuscation should be considered an implementation detail of the
|
* Database obfuscation should be considered an implementation detail of the
|
||||||
* specific database.
|
* specific database.
|
||||||
|
@ -208,7 +210,7 @@ public:
|
||||||
if (status.IsNotFound())
|
if (status.IsNotFound())
|
||||||
return false;
|
return false;
|
||||||
LogPrintf("LevelDB read failure: %s\n", status.ToString());
|
LogPrintf("LevelDB read failure: %s\n", status.ToString());
|
||||||
HandleError(status);
|
dbwrapper_private::HandleError(status);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
CDataStream ssValue(strValue.data(), strValue.data() + strValue.size(), SER_DISK, CLIENT_VERSION);
|
CDataStream ssValue(strValue.data(), strValue.data() + strValue.size(), SER_DISK, CLIENT_VERSION);
|
||||||
|
@ -242,7 +244,7 @@ public:
|
||||||
if (status.IsNotFound())
|
if (status.IsNotFound())
|
||||||
return false;
|
return false;
|
||||||
LogPrintf("LevelDB read failure: %s\n", status.ToString());
|
LogPrintf("LevelDB read failure: %s\n", status.ToString());
|
||||||
HandleError(status);
|
dbwrapper_private::HandleError(status);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue