mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-06-02 23:42:33 +02:00
refactor: Split dbwrapper CDBWrapper::Exists implementation
Keep the generic serialization in the header, while moving leveldb-specifics to the implementation file. The context of this commit is an effort to decouple the dbwrapper header file from leveldb includes. To this end, the includes are moved to the dbwrapper implementation file. This is done as part of the kernel project to reduce the number of required includes for users of the kernel.
This commit is contained in:
parent
a5c2eb5748
commit
dede0eef7a
@ -313,6 +313,21 @@ std::optional<std::string> CDBWrapper::ReadImpl(Span<const std::byte> ssKey) con
|
|||||||
return strValue;
|
return strValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CDBWrapper::ExistsImpl(Span<const std::byte> ssKey) const
|
||||||
|
{
|
||||||
|
leveldb::Slice slKey(CharCast(ssKey.data()), ssKey.size());
|
||||||
|
|
||||||
|
std::string strValue;
|
||||||
|
leveldb::Status status = pdb->Get(readoptions, slKey, &strValue);
|
||||||
|
if (!status.ok()) {
|
||||||
|
if (status.IsNotFound())
|
||||||
|
return false;
|
||||||
|
LogPrintf("LevelDB read failure: %s\n", status.ToString());
|
||||||
|
dbwrapper_private::HandleError(status);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool CDBWrapper::IsEmpty()
|
bool CDBWrapper::IsEmpty()
|
||||||
{
|
{
|
||||||
std::unique_ptr<CDBIterator> it(NewIterator());
|
std::unique_ptr<CDBIterator> it(NewIterator());
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
#define BITCOIN_DBWRAPPER_H
|
#define BITCOIN_DBWRAPPER_H
|
||||||
|
|
||||||
#include <clientversion.h>
|
#include <clientversion.h>
|
||||||
#include <logging.h>
|
|
||||||
#include <serialize.h>
|
#include <serialize.h>
|
||||||
#include <span.h>
|
#include <span.h>
|
||||||
#include <streams.h>
|
#include <streams.h>
|
||||||
@ -18,7 +17,6 @@
|
|||||||
#include <leveldb/db.h>
|
#include <leveldb/db.h>
|
||||||
#include <leveldb/options.h>
|
#include <leveldb/options.h>
|
||||||
#include <leveldb/slice.h>
|
#include <leveldb/slice.h>
|
||||||
#include <leveldb/status.h>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
@ -26,6 +24,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
namespace leveldb {
|
namespace leveldb {
|
||||||
class Env;
|
class Env;
|
||||||
|
class Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const size_t DBWRAPPER_PREALLOC_KEY_SIZE = 64;
|
static const size_t DBWRAPPER_PREALLOC_KEY_SIZE = 64;
|
||||||
@ -236,6 +235,7 @@ private:
|
|||||||
bool m_is_memory;
|
bool m_is_memory;
|
||||||
|
|
||||||
std::optional<std::string> ReadImpl(Span<const std::byte> ssKey) const;
|
std::optional<std::string> ReadImpl(Span<const std::byte> ssKey) const;
|
||||||
|
bool ExistsImpl(Span<const std::byte> ssKey) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CDBWrapper(const DBParams& params);
|
CDBWrapper(const DBParams& params);
|
||||||
@ -286,17 +286,7 @@ public:
|
|||||||
DataStream ssKey{};
|
DataStream ssKey{};
|
||||||
ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
|
ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
|
||||||
ssKey << key;
|
ssKey << key;
|
||||||
leveldb::Slice slKey(CharCast(ssKey.data()), ssKey.size());
|
return ExistsImpl(ssKey);
|
||||||
|
|
||||||
std::string strValue;
|
|
||||||
leveldb::Status status = pdb->Get(readoptions, slKey, &strValue);
|
|
||||||
if (!status.ok()) {
|
|
||||||
if (status.IsNotFound())
|
|
||||||
return false;
|
|
||||||
LogPrintf("LevelDB read failure: %s\n", status.ToString());
|
|
||||||
dbwrapper_private::HandleError(status);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename K>
|
template <typename K>
|
||||||
|
Loading…
Reference in New Issue
Block a user