mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 11:05:54 +00:00
Fix KeyvaDB for sizeof(size_t)
This commit is contained in:
@@ -29,7 +29,7 @@ private:
|
||||
typedef int32 KeyIndex;
|
||||
|
||||
// Size of a value.
|
||||
typedef size_t ByteSize;
|
||||
typedef uint32 ByteSize;
|
||||
|
||||
private:
|
||||
enum
|
||||
@@ -171,10 +171,10 @@ public:
|
||||
MemoryInputStream stream (data, false);
|
||||
|
||||
// This defines the file format!
|
||||
keyRecord->valFileOffset = stream.readInt64BigEndian ();
|
||||
keyRecord->valSize = stream.readIntBigEndian ();
|
||||
keyRecord->leftIndex = stream.readIntBigEndian ();
|
||||
keyRecord->rightIndex = stream.readIntBigEndian ();
|
||||
stream.readTypeBigEndianInto (&keyRecord->valFileOffset);
|
||||
stream.readTypeBigEndianInto (&keyRecord->valSize);
|
||||
stream.readTypeBigEndianInto (&keyRecord->leftIndex);
|
||||
stream.readTypeBigEndianInto (&keyRecord->rightIndex);
|
||||
|
||||
// Grab the key
|
||||
stream.read (keyRecord->key, m_keyBytes);
|
||||
@@ -211,10 +211,10 @@ public:
|
||||
MemoryOutputStream stream (data, false);
|
||||
|
||||
// This defines the file format!
|
||||
stream.writeInt64BigEndian (keyRecord.valFileOffset);
|
||||
stream.writeIntBigEndian (keyRecord.valSize);
|
||||
stream.writeIntBigEndian (keyRecord.leftIndex);
|
||||
stream.writeIntBigEndian (keyRecord.rightIndex);
|
||||
stream.writeTypeBigEndian (keyRecord.valFileOffset);
|
||||
stream.writeTypeBigEndian (keyRecord.valSize);
|
||||
stream.writeTypeBigEndian (keyRecord.leftIndex);
|
||||
stream.writeTypeBigEndian (keyRecord.rightIndex);
|
||||
|
||||
// Write the key
|
||||
if (includingKey)
|
||||
@@ -394,6 +394,27 @@ public:
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
// Compares two key records for equality
|
||||
bool areKeyRecordsEqual (KeyRecord const& lhs, KeyRecord const& rhs)
|
||||
{
|
||||
return lhs.leftIndex == rhs.leftIndex &&
|
||||
lhs.rightIndex == rhs.rightIndex &&
|
||||
lhs.valFileOffset == rhs.valFileOffset &&
|
||||
lhs.valSize == rhs.valSize &&
|
||||
(memcmp (lhs.key, rhs.key, m_keyBytes) == 0);
|
||||
}
|
||||
|
||||
// Makes sure a key record matches disk
|
||||
void checkKeyRecord (KeyRecord const& keyRecord, KeyIndex keyIndex, SharedState::WriteAccess& state)
|
||||
{
|
||||
MemoryBlock keyStorage (m_keyBytes);
|
||||
KeyRecord checkRecord (keyStorage.getData ());
|
||||
readKeyRecord (&checkRecord, keyIndex, state);
|
||||
|
||||
bassert (areKeyRecordsEqual (checkRecord, keyRecord));
|
||||
}
|
||||
|
||||
// Write a key value pair. Does nothing if the key exists.
|
||||
void put (void const* key, void const* value, int valueBytes)
|
||||
{
|
||||
bassert (valueBytes > 0);
|
||||
@@ -425,6 +446,8 @@ public:
|
||||
}
|
||||
|
||||
writeKeyRecord (findResult.keyRecord, findResult.keyIndex, state, false);
|
||||
|
||||
//checkKeyRecord (findResult.keyRecord, findResult.keyIndex, state);
|
||||
}
|
||||
|
||||
// Write the new key
|
||||
@@ -437,6 +460,8 @@ public:
|
||||
memcpy (findResult.keyRecord.key, key, m_keyBytes);
|
||||
|
||||
writeKeyRecord (findResult.keyRecord, state->newKeyIndex, state, true);
|
||||
|
||||
//checkKeyRecord (findResult.keyRecord, findResult.keyIndex, state);
|
||||
}
|
||||
|
||||
// Key file has grown by one.
|
||||
@@ -645,12 +670,15 @@ public:
|
||||
|
||||
expect (found, "Should be found");
|
||||
|
||||
if (found)
|
||||
{
|
||||
payload.repeatableRandomFill (1, maxPayloadBytes, keyIndex + seedValue);
|
||||
|
||||
expect (payload == cb.payload, "Should be equal");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// Re-open the database and confirm the data
|
||||
@@ -668,11 +696,14 @@ public:
|
||||
|
||||
expect (found, "Should be found");
|
||||
|
||||
if (found)
|
||||
{
|
||||
payload.repeatableRandomFill (1, maxPayloadBytes, keyIndex + seedValue);
|
||||
|
||||
expect (payload == cb.payload, "Should be equal");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
deleteDBFiles (path);
|
||||
}
|
||||
|
||||
@@ -887,7 +887,7 @@ class NodeStoreTimingTests : public NodeStoreUnitTest
|
||||
public:
|
||||
enum
|
||||
{
|
||||
numObjectsToTest = 10000
|
||||
numObjectsToTest = 50000
|
||||
};
|
||||
|
||||
NodeStoreTimingTests ()
|
||||
@@ -970,7 +970,7 @@ public:
|
||||
|
||||
testBackend ("keyvadb", seedValue);
|
||||
|
||||
#if 0
|
||||
#if 1
|
||||
testBackend ("leveldb", seedValue);
|
||||
|
||||
testBackend ("sqlite", seedValue);
|
||||
|
||||
Reference in New Issue
Block a user