dbwrapper: Move `HandleError` to `dbwrapper_private`
HandleError is implementation-specific.
This commit is contained in:
parent
809a429ecf
commit
3923bcca7c
|
@ -14,20 +14,6 @@
|
|||
#include <memenv.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)
|
||||
{
|
||||
leveldb::Options options;
|
||||
|
@ -60,13 +46,13 @@ CDBWrapper::CDBWrapper(const boost::filesystem::path& path, size_t nCacheSize, b
|
|||
if (fWipe) {
|
||||
LogPrintf("Wiping LevelDB in %s\n", path.string());
|
||||
leveldb::Status result = leveldb::DestroyDB(path.string(), options);
|
||||
HandleError(result);
|
||||
dbwrapper_private::HandleError(result);
|
||||
}
|
||||
TryCreateDirectory(path);
|
||||
LogPrintf("Opening LevelDB in %s\n", path.string());
|
||||
}
|
||||
leveldb::Status status = leveldb::DB::Open(options, path.string(), &pdb);
|
||||
HandleError(status);
|
||||
dbwrapper_private::HandleError(status);
|
||||
LogPrintf("Opened LevelDB successfully\n");
|
||||
}
|
||||
|
||||
|
@ -85,7 +71,7 @@ CDBWrapper::~CDBWrapper()
|
|||
bool CDBWrapper::WriteBatch(CDBBatch& batch, bool fSync)
|
||||
{
|
||||
leveldb::Status status = pdb->Write(fSync ? syncoptions : writeoptions, &batch.batch);
|
||||
HandleError(status);
|
||||
dbwrapper_private::HandleError(status);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -100,3 +86,21 @@ CDBIterator::~CDBIterator() { delete piter; }
|
|||
bool CDBIterator::Valid() { return piter->Valid(); }
|
||||
void CDBIterator::SeekToFirst() { piter->SeekToFirst(); }
|
||||
void CDBIterator::Next() { piter->Next(); }
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -22,9 +22,17 @@ public:
|
|||
dbwrapper_error(const std::string& msg) : std::runtime_error(msg) {}
|
||||
};
|
||||
|
||||
class CDBWrapper;
|
||||
|
||||
/** These should be considered an implementation detail of the specific database.
|
||||
*/
|
||||
namespace dbwrapper_private {
|
||||
|
||||
/** Handle database error by throwing dbwrapper_error exception.
|
||||
*/
|
||||
void HandleError(const leveldb::Status& status);
|
||||
|
||||
class CDBWrapper;
|
||||
};
|
||||
|
||||
/** Batch of changes queued to be written to a CDBWrapper */
|
||||
class CDBBatch
|
||||
|
@ -179,7 +187,7 @@ public:
|
|||
if (status.IsNotFound())
|
||||
return false;
|
||||
LogPrintf("LevelDB read failure: %s\n", status.ToString());
|
||||
HandleError(status);
|
||||
dbwrapper_private::HandleError(status);
|
||||
}
|
||||
try {
|
||||
CDataStream ssValue(strValue.data(), strValue.data() + strValue.size(), SER_DISK, CLIENT_VERSION);
|
||||
|
@ -212,7 +220,7 @@ public:
|
|||
if (status.IsNotFound())
|
||||
return false;
|
||||
LogPrintf("LevelDB read failure: %s\n", status.ToString());
|
||||
HandleError(status);
|
||||
dbwrapper_private::HandleError(status);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ PaymentDisclosureDB::PaymentDisclosureDB(const boost::filesystem::path& dbPath)
|
|||
TryCreateDirectory(path);
|
||||
options.create_if_missing = true;
|
||||
leveldb::Status status = leveldb::DB::Open(options, path.string(), &db);
|
||||
HandleError(status); // throws exception
|
||||
dbwrapper_private::HandleError(status); // throws exception
|
||||
LogPrintf("PaymentDisclosure: Opened LevelDB successfully\n");
|
||||
}
|
||||
|
||||
|
@ -62,7 +62,7 @@ bool PaymentDisclosureDB::Put(const PaymentDisclosureKey& key, const PaymentDisc
|
|||
leveldb::Slice slice(&ssValue[0], ssValue.size());
|
||||
|
||||
leveldb::Status status = db->Put(writeOptions, key.ToString(), slice);
|
||||
HandleError(status);
|
||||
dbwrapper_private::HandleError(status);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -80,7 +80,7 @@ bool PaymentDisclosureDB::Get(const PaymentDisclosureKey& key, PaymentDisclosure
|
|||
if (status.IsNotFound())
|
||||
return false;
|
||||
LogPrintf("PaymentDisclosure: LevelDB read failure: %s\n", status.ToString());
|
||||
HandleError(status);
|
||||
dbwrapper_private::HandleError(status);
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
Loading…
Reference in New Issue