fix osx unit test failure
This commit is contained in:
parent
197f8427c4
commit
32549a4e5a
1 changed files with 23 additions and 17 deletions
|
@ -61,10 +61,9 @@ public:
|
||||||
void SeekToFirst();
|
void SeekToFirst();
|
||||||
|
|
||||||
template<typename K> void Seek(const K& key) {
|
template<typename K> void Seek(const K& key) {
|
||||||
CDataStream ssKey1(SER_DISK, CLIENT_VERSION);
|
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
|
||||||
// ssKey1.reserve(parent.ssKey.capacity());
|
ssKey << key;
|
||||||
ssKey1 << key;
|
leveldb::Slice slKey(ssKey.data(), ssKey.size());
|
||||||
leveldb::Slice slKey(ssKey1.data(), ssKey1.size());
|
|
||||||
piter->Seek(slKey);
|
piter->Seek(slKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,6 +232,8 @@ public:
|
||||||
size_t EstimateSize(const K& key_begin, const K& key_end) const
|
size_t EstimateSize(const K& key_begin, const K& key_end) const
|
||||||
{
|
{
|
||||||
CDataStream ssKey1(SER_DISK, CLIENT_VERSION), ssKey2(SER_DISK, CLIENT_VERSION);
|
CDataStream ssKey1(SER_DISK, CLIENT_VERSION), ssKey2(SER_DISK, CLIENT_VERSION);
|
||||||
|
ssKey1.reserve(ssKey.capacity());
|
||||||
|
ssKey2.reserve(ssKey.capacity());
|
||||||
ssKey1 << key_begin;
|
ssKey1 << key_begin;
|
||||||
ssKey2 << key_end;
|
ssKey2 << key_end;
|
||||||
leveldb::Slice slKey1(ssKey1.data(), ssKey1.size());
|
leveldb::Slice slKey1(ssKey1.data(), ssKey1.size());
|
||||||
|
@ -269,12 +270,17 @@ class CDBBatch
|
||||||
leveldb::WriteBatch batch;
|
leveldb::WriteBatch batch;
|
||||||
|
|
||||||
size_t size_estimate;
|
size_t size_estimate;
|
||||||
|
CDataStream ssKey, ssValue;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @param[in] _parent CDBWrapper that this batch is to be submitted to
|
* @param[in] _parent CDBWrapper that this batch is to be submitted to
|
||||||
*/
|
*/
|
||||||
explicit CDBBatch(const CDBWrapper &_parent) : parent(_parent), size_estimate(0) { };
|
explicit CDBBatch(const CDBWrapper &_parent) : parent(_parent), size_estimate(0),
|
||||||
|
ssKey(SER_DISK, CLIENT_VERSION), ssValue(SER_DISK, CLIENT_VERSION) {
|
||||||
|
ssKey.reserve(parent.ssKey.capacity());
|
||||||
|
ssValue.reserve(parent.ssValue.capacity());
|
||||||
|
};
|
||||||
|
|
||||||
void Clear()
|
void Clear()
|
||||||
{
|
{
|
||||||
|
@ -285,14 +291,14 @@ public:
|
||||||
template <typename K, typename V>
|
template <typename K, typename V>
|
||||||
void Write(const K& key, const V& value)
|
void Write(const K& key, const V& value)
|
||||||
{
|
{
|
||||||
assert(parent.ssKey.empty());
|
assert(ssKey.empty());
|
||||||
parent.ssKey << key;
|
ssKey << key;
|
||||||
leveldb::Slice slKey(parent.ssKey.data(), parent.ssKey.size());
|
leveldb::Slice slKey(ssKey.data(), ssKey.size());
|
||||||
|
|
||||||
assert(parent.ssValue.empty());
|
assert(ssValue.empty());
|
||||||
parent.ssValue << value;
|
ssValue << value;
|
||||||
parent.ssValue.Xor(dbwrapper_private::GetObfuscateKey(parent));
|
ssValue.Xor(dbwrapper_private::GetObfuscateKey(parent));
|
||||||
leveldb::Slice slValue(parent.ssValue.data(), parent.ssValue.size());
|
leveldb::Slice slValue(ssValue.data(), ssValue.size());
|
||||||
|
|
||||||
batch.Put(slKey, slValue);
|
batch.Put(slKey, slValue);
|
||||||
// LevelDB serializes writes as:
|
// LevelDB serializes writes as:
|
||||||
|
@ -303,15 +309,15 @@ public:
|
||||||
// - byte[]: value
|
// - byte[]: value
|
||||||
// The formula below assumes the key and value are both less than 16k.
|
// The formula below assumes the key and value are both less than 16k.
|
||||||
size_estimate += 3 + (slKey.size() > 127) + slKey.size() + (slValue.size() > 127) + slValue.size();
|
size_estimate += 3 + (slKey.size() > 127) + slKey.size() + (slValue.size() > 127) + slValue.size();
|
||||||
parent.ssKey.clear();
|
ssKey.clear();
|
||||||
parent.ssValue.clear();
|
ssValue.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename K>
|
template <typename K>
|
||||||
void Erase(const K& key)
|
void Erase(const K& key)
|
||||||
{
|
{
|
||||||
parent.ssKey << key;
|
ssKey << key;
|
||||||
leveldb::Slice slKey(parent.ssKey.data(), parent.ssKey.size());
|
leveldb::Slice slKey(ssKey.data(), ssKey.size());
|
||||||
|
|
||||||
batch.Delete(slKey);
|
batch.Delete(slKey);
|
||||||
// LevelDB serializes erases as:
|
// LevelDB serializes erases as:
|
||||||
|
@ -320,7 +326,7 @@ public:
|
||||||
// - byte[]: key
|
// - byte[]: key
|
||||||
// The formula below assumes the key is less than 16kB.
|
// The formula below assumes the key is less than 16kB.
|
||||||
size_estimate += 2 + (slKey.size() > 127) + slKey.size();
|
size_estimate += 2 + (slKey.size() > 127) + slKey.size();
|
||||||
parent.ssKey.clear();
|
ssKey.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t SizeEstimate() const { return size_estimate; }
|
size_t SizeEstimate() const { return size_estimate; }
|
||||||
|
|
Loading…
Add table
Reference in a new issue