leveldbwrapper symbol rename: Remove "Level" from class, etc. names
This commit is contained in:
parent
7249ee6d7c
commit
f345c41ec4
|
@ -20,12 +20,12 @@ void HandleError(const leveldb::Status& status)
|
||||||
return;
|
return;
|
||||||
LogPrintf("%s\n", status.ToString());
|
LogPrintf("%s\n", status.ToString());
|
||||||
if (status.IsCorruption())
|
if (status.IsCorruption())
|
||||||
throw leveldb_error("Database corrupted");
|
throw dbwrapper_error("Database corrupted");
|
||||||
if (status.IsIOError())
|
if (status.IsIOError())
|
||||||
throw leveldb_error("Database I/O error");
|
throw dbwrapper_error("Database I/O error");
|
||||||
if (status.IsNotFound())
|
if (status.IsNotFound())
|
||||||
throw leveldb_error("Database entry missing");
|
throw dbwrapper_error("Database entry missing");
|
||||||
throw leveldb_error("Unknown database error");
|
throw dbwrapper_error("Unknown database error");
|
||||||
}
|
}
|
||||||
|
|
||||||
static leveldb::Options GetOptions(size_t nCacheSize)
|
static leveldb::Options GetOptions(size_t nCacheSize)
|
||||||
|
@ -44,7 +44,7 @@ static leveldb::Options GetOptions(size_t nCacheSize)
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
CLevelDBWrapper::CLevelDBWrapper(const boost::filesystem::path& path, size_t nCacheSize, bool fMemory, bool fWipe)
|
CDBWrapper::CDBWrapper(const boost::filesystem::path& path, size_t nCacheSize, bool fMemory, bool fWipe)
|
||||||
{
|
{
|
||||||
penv = NULL;
|
penv = NULL;
|
||||||
readoptions.verify_checksums = true;
|
readoptions.verify_checksums = true;
|
||||||
|
@ -70,7 +70,7 @@ CLevelDBWrapper::CLevelDBWrapper(const boost::filesystem::path& path, size_t nCa
|
||||||
LogPrintf("Opened LevelDB successfully\n");
|
LogPrintf("Opened LevelDB successfully\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
CLevelDBWrapper::~CLevelDBWrapper()
|
CDBWrapper::~CDBWrapper()
|
||||||
{
|
{
|
||||||
delete pdb;
|
delete pdb;
|
||||||
pdb = NULL;
|
pdb = NULL;
|
||||||
|
@ -82,21 +82,21 @@ CLevelDBWrapper::~CLevelDBWrapper()
|
||||||
options.env = NULL;
|
options.env = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CLevelDBWrapper::WriteBatch(CLevelDBBatch& 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);
|
HandleError(status);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CLevelDBWrapper::IsEmpty()
|
bool CDBWrapper::IsEmpty()
|
||||||
{
|
{
|
||||||
boost::scoped_ptr<CLevelDBIterator> it(NewIterator());
|
boost::scoped_ptr<CDBIterator> it(NewIterator());
|
||||||
it->SeekToFirst();
|
it->SeekToFirst();
|
||||||
return !(it->Valid());
|
return !(it->Valid());
|
||||||
}
|
}
|
||||||
|
|
||||||
CLevelDBIterator::~CLevelDBIterator() { delete piter; }
|
CDBIterator::~CDBIterator() { delete piter; }
|
||||||
bool CLevelDBIterator::Valid() { return piter->Valid(); }
|
bool CDBIterator::Valid() { return piter->Valid(); }
|
||||||
void CLevelDBIterator::SeekToFirst() { piter->SeekToFirst(); }
|
void CDBIterator::SeekToFirst() { piter->SeekToFirst(); }
|
||||||
void CLevelDBIterator::Next() { piter->Next(); }
|
void CDBIterator::Next() { piter->Next(); }
|
||||||
|
|
|
@ -16,18 +16,18 @@
|
||||||
#include <leveldb/db.h>
|
#include <leveldb/db.h>
|
||||||
#include <leveldb/write_batch.h>
|
#include <leveldb/write_batch.h>
|
||||||
|
|
||||||
class leveldb_error : public std::runtime_error
|
class dbwrapper_error : public std::runtime_error
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
leveldb_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);
|
void HandleError(const leveldb::Status& status);
|
||||||
|
|
||||||
/** Batch of changes queued to be written to a CLevelDBWrapper */
|
/** Batch of changes queued to be written to a CDBWrapper */
|
||||||
class CLevelDBBatch
|
class CDBBatch
|
||||||
{
|
{
|
||||||
friend class CLevelDBWrapper;
|
friend class CDBWrapper;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
leveldb::WriteBatch batch;
|
leveldb::WriteBatch batch;
|
||||||
|
@ -61,7 +61,7 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class CLevelDBIterator
|
class CDBIterator
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
leveldb::Iterator *piter;
|
leveldb::Iterator *piter;
|
||||||
|
@ -71,9 +71,9 @@ public:
|
||||||
/**
|
/**
|
||||||
* @param[in] piterIn The original leveldb iterator.
|
* @param[in] piterIn The original leveldb iterator.
|
||||||
*/
|
*/
|
||||||
CLevelDBIterator(leveldb::Iterator *piterIn) :
|
CDBIterator(leveldb::Iterator *piterIn) :
|
||||||
piter(piterIn) { };
|
piter(piterIn) { };
|
||||||
~CLevelDBIterator();
|
~CDBIterator();
|
||||||
|
|
||||||
bool Valid();
|
bool Valid();
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@ public:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class CLevelDBWrapper
|
class CDBWrapper
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
//! custom environment this database is using (may be NULL in case of default environment)
|
//! custom environment this database is using (may be NULL in case of default environment)
|
||||||
|
@ -152,8 +152,8 @@ public:
|
||||||
* @param[in] fMemory If true, use leveldb's memory environment.
|
* @param[in] fMemory If true, use leveldb's memory environment.
|
||||||
* @param[in] fWipe If true, remove all existing data.
|
* @param[in] fWipe If true, remove all existing data.
|
||||||
*/
|
*/
|
||||||
CLevelDBWrapper(const boost::filesystem::path& path, size_t nCacheSize, bool fMemory = false, bool fWipe = false);
|
CDBWrapper(const boost::filesystem::path& path, size_t nCacheSize, bool fMemory = false, bool fWipe = false);
|
||||||
~CLevelDBWrapper();
|
~CDBWrapper();
|
||||||
|
|
||||||
template <typename K, typename V>
|
template <typename K, typename V>
|
||||||
bool Read(const K& key, V& value) const
|
bool Read(const K& key, V& value) const
|
||||||
|
@ -183,7 +183,7 @@ public:
|
||||||
template <typename K, typename V>
|
template <typename K, typename V>
|
||||||
bool Write(const K& key, const V& value, bool fSync = false)
|
bool Write(const K& key, const V& value, bool fSync = false)
|
||||||
{
|
{
|
||||||
CLevelDBBatch batch;
|
CDBBatch batch;
|
||||||
batch.Write(key, value);
|
batch.Write(key, value);
|
||||||
return WriteBatch(batch, fSync);
|
return WriteBatch(batch, fSync);
|
||||||
}
|
}
|
||||||
|
@ -210,12 +210,12 @@ public:
|
||||||
template <typename K>
|
template <typename K>
|
||||||
bool Erase(const K& key, bool fSync = false)
|
bool Erase(const K& key, bool fSync = false)
|
||||||
{
|
{
|
||||||
CLevelDBBatch batch;
|
CDBBatch batch;
|
||||||
batch.Erase(key);
|
batch.Erase(key);
|
||||||
return WriteBatch(batch, fSync);
|
return WriteBatch(batch, fSync);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WriteBatch(CLevelDBBatch& batch, bool fSync = false);
|
bool WriteBatch(CDBBatch& batch, bool fSync = false);
|
||||||
|
|
||||||
// not available for LevelDB; provide for compatibility with BDB
|
// not available for LevelDB; provide for compatibility with BDB
|
||||||
bool Flush()
|
bool Flush()
|
||||||
|
@ -225,13 +225,13 @@ public:
|
||||||
|
|
||||||
bool Sync()
|
bool Sync()
|
||||||
{
|
{
|
||||||
CLevelDBBatch batch;
|
CDBBatch batch;
|
||||||
return WriteBatch(batch, true);
|
return WriteBatch(batch, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
CLevelDBIterator *NewIterator()
|
CDBIterator *NewIterator()
|
||||||
{
|
{
|
||||||
return new CLevelDBIterator(pdb->NewIterator(iteroptions));
|
return new CDBIterator(pdb->NewIterator(iteroptions));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -25,13 +25,13 @@ bool is_null_key(const vector<unsigned char>& key) {
|
||||||
return isnull;
|
return isnull;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_SUITE(leveldbwrapper_tests, BasicTestingSetup)
|
BOOST_FIXTURE_TEST_SUITE(dbwrapper_tests, BasicTestingSetup)
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(leveldbwrapper)
|
BOOST_AUTO_TEST_CASE(dbwrapper)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
path ph = temp_directory_path() / unique_path();
|
path ph = temp_directory_path() / unique_path();
|
||||||
CLevelDBWrapper dbw(ph, (1 << 20), true, false);
|
CDBWrapper dbw(ph, (1 << 20), true, false);
|
||||||
char key = 'k';
|
char key = 'k';
|
||||||
uint256 in = GetRandHash();
|
uint256 in = GetRandHash();
|
||||||
uint256 res;
|
uint256 res;
|
||||||
|
@ -43,11 +43,11 @@ BOOST_AUTO_TEST_CASE(leveldbwrapper)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test batch operations
|
// Test batch operations
|
||||||
BOOST_AUTO_TEST_CASE(leveldbwrapper_batch)
|
BOOST_AUTO_TEST_CASE(dbwrapper_batch)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
path ph = temp_directory_path() / unique_path();
|
path ph = temp_directory_path() / unique_path();
|
||||||
CLevelDBWrapper dbw(ph, (1 << 20), true, false);
|
CDBWrapper dbw(ph, (1 << 20), true, false);
|
||||||
|
|
||||||
char key = 'i';
|
char key = 'i';
|
||||||
uint256 in = GetRandHash();
|
uint256 in = GetRandHash();
|
||||||
|
@ -57,7 +57,7 @@ BOOST_AUTO_TEST_CASE(leveldbwrapper_batch)
|
||||||
uint256 in3 = GetRandHash();
|
uint256 in3 = GetRandHash();
|
||||||
|
|
||||||
uint256 res;
|
uint256 res;
|
||||||
CLevelDBBatch batch;
|
CDBBatch batch;
|
||||||
|
|
||||||
batch.Write(key, in);
|
batch.Write(key, in);
|
||||||
batch.Write(key2, in2);
|
batch.Write(key2, in2);
|
||||||
|
@ -78,11 +78,11 @@ BOOST_AUTO_TEST_CASE(leveldbwrapper_batch)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(leveldbwrapper_iterator)
|
BOOST_AUTO_TEST_CASE(dbwrapper_iterator)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
path ph = temp_directory_path() / unique_path();
|
path ph = temp_directory_path() / unique_path();
|
||||||
CLevelDBWrapper dbw(ph, (1 << 20), true, false);
|
CDBWrapper dbw(ph, (1 << 20), true, false);
|
||||||
|
|
||||||
// The two keys are intentionally chosen for ordering
|
// The two keys are intentionally chosen for ordering
|
||||||
char key = 'j';
|
char key = 'j';
|
||||||
|
@ -92,7 +92,7 @@ BOOST_AUTO_TEST_CASE(leveldbwrapper_iterator)
|
||||||
uint256 in2 = GetRandHash();
|
uint256 in2 = GetRandHash();
|
||||||
BOOST_CHECK(dbw.Write(key2, in2));
|
BOOST_CHECK(dbw.Write(key2, in2));
|
||||||
|
|
||||||
boost::scoped_ptr<CLevelDBIterator> it(const_cast<CLevelDBWrapper*>(&dbw)->NewIterator());
|
boost::scoped_ptr<CDBIterator> it(const_cast<CDBWrapper*>(&dbw)->NewIterator());
|
||||||
|
|
||||||
// Be sure to seek past any earlier key (if it exists)
|
// Be sure to seek past any earlier key (if it exists)
|
||||||
it->Seek(key);
|
it->Seek(key);
|
||||||
|
|
12
src/txdb.cpp
12
src/txdb.cpp
|
@ -85,7 +85,7 @@ bool CCoinsViewDB::BatchWrite(CCoinsMap &mapCoins,
|
||||||
const uint256 &hashAnchor,
|
const uint256 &hashAnchor,
|
||||||
CAnchorsMap &mapAnchors,
|
CAnchorsMap &mapAnchors,
|
||||||
CNullifiersMap &mapNullifiers) {
|
CNullifiersMap &mapNullifiers) {
|
||||||
CLevelDBBatch batch;
|
CDBBatch batch;
|
||||||
size_t count = 0;
|
size_t count = 0;
|
||||||
size_t changed = 0;
|
size_t changed = 0;
|
||||||
for (CCoinsMap::iterator it = mapCoins.begin(); it != mapCoins.end();) {
|
for (CCoinsMap::iterator it = mapCoins.begin(); it != mapCoins.end();) {
|
||||||
|
@ -135,7 +135,7 @@ bool CCoinsViewDB::BatchWrite(CCoinsMap &mapCoins,
|
||||||
return db.WriteBatch(batch);
|
return db.WriteBatch(batch);
|
||||||
}
|
}
|
||||||
|
|
||||||
CBlockTreeDB::CBlockTreeDB(size_t nCacheSize, bool fMemory, bool fWipe) : CLevelDBWrapper(GetDataDir() / "blocks" / "index", nCacheSize, fMemory, fWipe) {
|
CBlockTreeDB::CBlockTreeDB(size_t nCacheSize, bool fMemory, bool fWipe) : CDBWrapper(GetDataDir() / "blocks" / "index", nCacheSize, fMemory, fWipe) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CBlockTreeDB::ReadBlockFileInfo(int nFile, CBlockFileInfo &info) {
|
bool CBlockTreeDB::ReadBlockFileInfo(int nFile, CBlockFileInfo &info) {
|
||||||
|
@ -162,7 +162,7 @@ bool CCoinsViewDB::GetStats(CCoinsStats &stats) const {
|
||||||
/* It seems that there are no "const iterators" for LevelDB. Since we
|
/* It seems that there are no "const iterators" for LevelDB. Since we
|
||||||
only need read operations on it, use a const-cast to get around
|
only need read operations on it, use a const-cast to get around
|
||||||
that restriction. */
|
that restriction. */
|
||||||
boost::scoped_ptr<CLevelDBIterator> pcursor(const_cast<CLevelDBWrapper*>(&db)->NewIterator());
|
boost::scoped_ptr<CDBIterator> pcursor(const_cast<CDBWrapper*>(&db)->NewIterator());
|
||||||
pcursor->Seek(DB_COINS);
|
pcursor->Seek(DB_COINS);
|
||||||
|
|
||||||
CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION);
|
CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION);
|
||||||
|
@ -205,7 +205,7 @@ bool CCoinsViewDB::GetStats(CCoinsStats &stats) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CBlockTreeDB::WriteBatchSync(const std::vector<std::pair<int, const CBlockFileInfo*> >& fileInfo, int nLastFile, const std::vector<const CBlockIndex*>& blockinfo) {
|
bool CBlockTreeDB::WriteBatchSync(const std::vector<std::pair<int, const CBlockFileInfo*> >& fileInfo, int nLastFile, const std::vector<const CBlockIndex*>& blockinfo) {
|
||||||
CLevelDBBatch batch;
|
CDBBatch batch;
|
||||||
for (std::vector<std::pair<int, const CBlockFileInfo*> >::const_iterator it=fileInfo.begin(); it != fileInfo.end(); it++) {
|
for (std::vector<std::pair<int, const CBlockFileInfo*> >::const_iterator it=fileInfo.begin(); it != fileInfo.end(); it++) {
|
||||||
batch.Write(make_pair(DB_BLOCK_FILES, it->first), *it->second);
|
batch.Write(make_pair(DB_BLOCK_FILES, it->first), *it->second);
|
||||||
}
|
}
|
||||||
|
@ -229,7 +229,7 @@ bool CBlockTreeDB::ReadTxIndex(const uint256 &txid, CDiskTxPos &pos) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CBlockTreeDB::WriteTxIndex(const std::vector<std::pair<uint256, CDiskTxPos> >&vect) {
|
bool CBlockTreeDB::WriteTxIndex(const std::vector<std::pair<uint256, CDiskTxPos> >&vect) {
|
||||||
CLevelDBBatch batch;
|
CDBBatch batch;
|
||||||
for (std::vector<std::pair<uint256,CDiskTxPos> >::const_iterator it=vect.begin(); it!=vect.end(); it++)
|
for (std::vector<std::pair<uint256,CDiskTxPos> >::const_iterator it=vect.begin(); it!=vect.end(); it++)
|
||||||
batch.Write(make_pair(DB_TXINDEX, it->first), it->second);
|
batch.Write(make_pair(DB_TXINDEX, it->first), it->second);
|
||||||
return WriteBatch(batch);
|
return WriteBatch(batch);
|
||||||
|
@ -249,7 +249,7 @@ bool CBlockTreeDB::ReadFlag(const std::string &name, bool &fValue) {
|
||||||
|
|
||||||
bool CBlockTreeDB::LoadBlockIndexGuts()
|
bool CBlockTreeDB::LoadBlockIndexGuts()
|
||||||
{
|
{
|
||||||
boost::scoped_ptr<CLevelDBIterator> pcursor(NewIterator());
|
boost::scoped_ptr<CDBIterator> pcursor(NewIterator());
|
||||||
|
|
||||||
pcursor->Seek(make_pair(DB_BLOCK_INDEX, uint256()));
|
pcursor->Seek(make_pair(DB_BLOCK_INDEX, uint256()));
|
||||||
|
|
||||||
|
|
|
@ -26,11 +26,11 @@ static const int64_t nMaxDbCache = sizeof(void*) > 4 ? 16384 : 1024;
|
||||||
//! min. -dbcache in (MiB)
|
//! min. -dbcache in (MiB)
|
||||||
static const int64_t nMinDbCache = 4;
|
static const int64_t nMinDbCache = 4;
|
||||||
|
|
||||||
/** CCoinsView backed by the LevelDB coin database (chainstate/) */
|
/** CCoinsView backed by the coin database (chainstate/) */
|
||||||
class CCoinsViewDB : public CCoinsView
|
class CCoinsViewDB : public CCoinsView
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
CLevelDBWrapper db;
|
CDBWrapper db;
|
||||||
CCoinsViewDB(std::string dbName, size_t nCacheSize, bool fMemory = false, bool fWipe = false);
|
CCoinsViewDB(std::string dbName, size_t nCacheSize, bool fMemory = false, bool fWipe = false);
|
||||||
public:
|
public:
|
||||||
CCoinsViewDB(size_t nCacheSize, bool fMemory = false, bool fWipe = false);
|
CCoinsViewDB(size_t nCacheSize, bool fMemory = false, bool fWipe = false);
|
||||||
|
@ -50,7 +50,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Access to the block database (blocks/index/) */
|
/** Access to the block database (blocks/index/) */
|
||||||
class CBlockTreeDB : public CLevelDBWrapper
|
class CBlockTreeDB : public CDBWrapper
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CBlockTreeDB(size_t nCacheSize, bool fMemory = false, bool fWipe = false);
|
CBlockTreeDB(size_t nCacheSize, bool fMemory = false, bool fWipe = false);
|
||||||
|
|
Loading…
Reference in New Issue