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;
|
typedef int32 KeyIndex;
|
||||||
|
|
||||||
// Size of a value.
|
// Size of a value.
|
||||||
typedef size_t ByteSize;
|
typedef uint32 ByteSize;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum
|
enum
|
||||||
@@ -171,10 +171,10 @@ public:
|
|||||||
MemoryInputStream stream (data, false);
|
MemoryInputStream stream (data, false);
|
||||||
|
|
||||||
// This defines the file format!
|
// This defines the file format!
|
||||||
keyRecord->valFileOffset = stream.readInt64BigEndian ();
|
stream.readTypeBigEndianInto (&keyRecord->valFileOffset);
|
||||||
keyRecord->valSize = stream.readIntBigEndian ();
|
stream.readTypeBigEndianInto (&keyRecord->valSize);
|
||||||
keyRecord->leftIndex = stream.readIntBigEndian ();
|
stream.readTypeBigEndianInto (&keyRecord->leftIndex);
|
||||||
keyRecord->rightIndex = stream.readIntBigEndian ();
|
stream.readTypeBigEndianInto (&keyRecord->rightIndex);
|
||||||
|
|
||||||
// Grab the key
|
// Grab the key
|
||||||
stream.read (keyRecord->key, m_keyBytes);
|
stream.read (keyRecord->key, m_keyBytes);
|
||||||
@@ -211,10 +211,10 @@ public:
|
|||||||
MemoryOutputStream stream (data, false);
|
MemoryOutputStream stream (data, false);
|
||||||
|
|
||||||
// This defines the file format!
|
// This defines the file format!
|
||||||
stream.writeInt64BigEndian (keyRecord.valFileOffset);
|
stream.writeTypeBigEndian (keyRecord.valFileOffset);
|
||||||
stream.writeIntBigEndian (keyRecord.valSize);
|
stream.writeTypeBigEndian (keyRecord.valSize);
|
||||||
stream.writeIntBigEndian (keyRecord.leftIndex);
|
stream.writeTypeBigEndian (keyRecord.leftIndex);
|
||||||
stream.writeIntBigEndian (keyRecord.rightIndex);
|
stream.writeTypeBigEndian (keyRecord.rightIndex);
|
||||||
|
|
||||||
// Write the key
|
// Write the key
|
||||||
if (includingKey)
|
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)
|
void put (void const* key, void const* value, int valueBytes)
|
||||||
{
|
{
|
||||||
bassert (valueBytes > 0);
|
bassert (valueBytes > 0);
|
||||||
@@ -425,6 +446,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
writeKeyRecord (findResult.keyRecord, findResult.keyIndex, state, false);
|
writeKeyRecord (findResult.keyRecord, findResult.keyIndex, state, false);
|
||||||
|
|
||||||
|
//checkKeyRecord (findResult.keyRecord, findResult.keyIndex, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write the new key
|
// Write the new key
|
||||||
@@ -437,6 +460,8 @@ public:
|
|||||||
memcpy (findResult.keyRecord.key, key, m_keyBytes);
|
memcpy (findResult.keyRecord.key, key, m_keyBytes);
|
||||||
|
|
||||||
writeKeyRecord (findResult.keyRecord, state->newKeyIndex, state, true);
|
writeKeyRecord (findResult.keyRecord, state->newKeyIndex, state, true);
|
||||||
|
|
||||||
|
//checkKeyRecord (findResult.keyRecord, findResult.keyIndex, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Key file has grown by one.
|
// Key file has grown by one.
|
||||||
@@ -645,12 +670,15 @@ public:
|
|||||||
|
|
||||||
expect (found, "Should be found");
|
expect (found, "Should be found");
|
||||||
|
|
||||||
|
if (found)
|
||||||
|
{
|
||||||
payload.repeatableRandomFill (1, maxPayloadBytes, keyIndex + seedValue);
|
payload.repeatableRandomFill (1, maxPayloadBytes, keyIndex + seedValue);
|
||||||
|
|
||||||
expect (payload == cb.payload, "Should be equal");
|
expect (payload == cb.payload, "Should be equal");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
// Re-open the database and confirm the data
|
// Re-open the database and confirm the data
|
||||||
@@ -668,11 +696,14 @@ public:
|
|||||||
|
|
||||||
expect (found, "Should be found");
|
expect (found, "Should be found");
|
||||||
|
|
||||||
|
if (found)
|
||||||
|
{
|
||||||
payload.repeatableRandomFill (1, maxPayloadBytes, keyIndex + seedValue);
|
payload.repeatableRandomFill (1, maxPayloadBytes, keyIndex + seedValue);
|
||||||
|
|
||||||
expect (payload == cb.payload, "Should be equal");
|
expect (payload == cb.payload, "Should be equal");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
deleteDBFiles (path);
|
deleteDBFiles (path);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -887,7 +887,7 @@ class NodeStoreTimingTests : public NodeStoreUnitTest
|
|||||||
public:
|
public:
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
numObjectsToTest = 10000
|
numObjectsToTest = 50000
|
||||||
};
|
};
|
||||||
|
|
||||||
NodeStoreTimingTests ()
|
NodeStoreTimingTests ()
|
||||||
@@ -970,7 +970,7 @@ public:
|
|||||||
|
|
||||||
testBackend ("keyvadb", seedValue);
|
testBackend ("keyvadb", seedValue);
|
||||||
|
|
||||||
#if 0
|
#if 1
|
||||||
testBackend ("leveldb", seedValue);
|
testBackend ("leveldb", seedValue);
|
||||||
|
|
||||||
testBackend ("sqlite", seedValue);
|
testBackend ("sqlite", seedValue);
|
||||||
|
|||||||
Reference in New Issue
Block a user