Compare commits
6
Commits
e23018c952
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aeafce1bc8 | ||
|
|
cce3e1651f | ||
|
|
d7b4b66dd5 | ||
|
|
3d997d5c57 | ||
|
|
0ca1d3c546 | ||
|
|
b671f93e5a |
No files matched your search
+1
-1
@@ -394,7 +394,7 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR AND BUILD_TESTING)
|
||||
add_test(NAME conflict_set_cxx_api_test COMMAND conflict_set_cxx_api_test)
|
||||
|
||||
# SHOW_MEMORY instrumentation, which the rest of the test suite doesn't
|
||||
# compile with
|
||||
# compile with. It assumes a single live ConflictSet (see Internal.h).
|
||||
add_executable(conflict_set_show_memory_test ConflictSet.cpp
|
||||
ShowMemoryTest.cpp)
|
||||
target_compile_options(conflict_set_show_memory_test PRIVATE ${TEST_FLAGS})
|
||||
|
||||
+12
-3
@@ -5546,7 +5546,9 @@ void internal_addWrites(ConflictSet::Impl *impl,
|
||||
impl->totalBytes += mallocBytesDelta;
|
||||
impl->memory_bytes.set(impl->totalBytes);
|
||||
#if SHOW_MEMORY
|
||||
// Testing-only cross-check of the accounting.
|
||||
// Testing-only cross-check of the accounting. `mallocBytes` is process-wide,
|
||||
// while `impl->totalBytes` only covers this instance, so this holds only
|
||||
// while this is the only live ConflictSet (see Internal.h).
|
||||
if (impl->totalBytes != mallocBytes) {
|
||||
abort(); // GCOVR_EXCL_LINE
|
||||
}
|
||||
@@ -5559,7 +5561,9 @@ void internal_setOldestVersion(ConflictSet::Impl *impl, int64_t oldestVersion) {
|
||||
impl->totalBytes += mallocBytesDelta;
|
||||
impl->memory_bytes.set(impl->totalBytes);
|
||||
#if SHOW_MEMORY
|
||||
// Testing-only cross-check of the accounting.
|
||||
// Testing-only cross-check of the accounting. `mallocBytes` is process-wide,
|
||||
// while `impl->totalBytes` only covers this instance, so this holds only
|
||||
// while this is the only live ConflictSet (see Internal.h).
|
||||
if (impl->totalBytes != mallocBytes) {
|
||||
abort(); // GCOVR_EXCL_LINE
|
||||
}
|
||||
@@ -5631,6 +5635,9 @@ Node *firstGeqLogical(Node *n, const TrivialSpan key) {
|
||||
goto downLeftSpine;
|
||||
} else {
|
||||
n = nextSibling(n);
|
||||
if (n == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
goto downLeftSpine;
|
||||
}
|
||||
}
|
||||
@@ -5928,7 +5935,9 @@ checkMaxVersion(Node *root, Node *node, InternalVersionT oldestVersion,
|
||||
expected = std::max(expected, child->entry.rangeVersion);
|
||||
}
|
||||
}
|
||||
auto key = getSearchPath(root);
|
||||
// Account for the range version of the first key after `node`'s subtree: a
|
||||
// range write spanning the subtree is recorded there.
|
||||
auto key = getSearchPath(node);
|
||||
bool ok;
|
||||
auto inc = strinc(key, ok);
|
||||
if (ok) {
|
||||
|
||||
@@ -96,6 +96,14 @@ static_assert(std::is_trivial_v<TrivialSpan>);
|
||||
// GCOVR_EXCL_START
|
||||
|
||||
#if SHOW_MEMORY
|
||||
// Process-wide by design: `safe_malloc`/`safe_free` update these for every
|
||||
// allocation in the process, no matter which ConflictSet made it. An instance's
|
||||
// `totalBytes`, in contrast, only accounts for the allocations made during its
|
||||
// own API calls, so the SHOW_MEMORY cross-check of the two in
|
||||
// `internal_addWrites`/`internal_setOldestVersion` only holds while a single
|
||||
// ConflictSet is alive. Running several at once is supported by the library;
|
||||
// SHOW_MEMORY just doesn't instrument it. `peakMallocBytes` is process-wide
|
||||
// too, but as a peak it remains meaningful with several instances.
|
||||
inline int64_t mallocBytes = 0;
|
||||
inline int64_t peakMallocBytes = 0;
|
||||
// Defined in ConflictSet.cpp
|
||||
|
||||
+3
-2
@@ -1,8 +1,9 @@
|
||||
// Exercises the SHOW_MEMORY instrumentation, which the other tests don't
|
||||
// compile with (this target passes -DSHOW_MEMORY=1). The instrumentation has
|
||||
// its own consistency checks, which abort on failure, and asserts are enabled
|
||||
// by TEST_FLAGS. Only one ConflictSet may exist at a time, since the
|
||||
// accounting is process-wide.
|
||||
// by TEST_FLAGS. Only one ConflictSet may exist at a time: the accounting is
|
||||
// process-wide, while the cross-check compares it against a single instance's
|
||||
// totals (see the comment on `mallocBytes` in Internal.h).
|
||||
#include "ConflictSet.h"
|
||||
#include "Internal.h"
|
||||
|
||||
|
||||
+22
-4
@@ -31,7 +31,9 @@
|
||||
std::span<const uint8_t> keyAfter(Arena &arena, std::span<const uint8_t> key) {
|
||||
auto result =
|
||||
std::span<uint8_t>(new (arena) uint8_t[key.size() + 1], key.size() + 1);
|
||||
memcpy(result.data(), key.data(), key.size());
|
||||
if (key.size() > 0) {
|
||||
memcpy(result.data(), key.data(), key.size());
|
||||
}
|
||||
result[result.size() - 1] = 0;
|
||||
return result;
|
||||
}
|
||||
@@ -50,6 +52,14 @@ using Version = int64_t;
|
||||
#define force_inline inline __attribute__((always_inline))
|
||||
using StringRef = std::span<const uint8_t>;
|
||||
|
||||
// memcmp, but safe for zero-length ranges: memcmp is undefined behavior unless
|
||||
// both pointers are valid, even when the count is 0, and spans for the empty
|
||||
// key are allowed to have a null data().
|
||||
static force_inline bool equalBytes(const uint8_t *a, const uint8_t *b,
|
||||
int size) {
|
||||
return size == 0 || memcmp(a, b, size) == 0;
|
||||
}
|
||||
|
||||
struct KeyRangeRef {
|
||||
StringRef begin;
|
||||
StringRef end;
|
||||
@@ -180,7 +190,8 @@ void sortPoints(std::vector<KeyInfo> &points) {
|
||||
}
|
||||
|
||||
static int compare(const StringRef &a, const StringRef &b) {
|
||||
int c = memcmp(a.data(), b.data(), std::min(a.size(), b.size()));
|
||||
int n = std::min(a.size(), b.size());
|
||||
int c = n > 0 ? memcmp(a.data(), b.data(), n) : 0;
|
||||
if (c < 0)
|
||||
return -1;
|
||||
if (c > 0)
|
||||
@@ -371,7 +382,7 @@ public:
|
||||
Node *n = finger[0]->getNext(
|
||||
0); // or alreadyChecked, but that is more easily invalidated
|
||||
if (n && n->length() == value.size() &&
|
||||
!memcmp(n->value(), value.data(), value.size()))
|
||||
equalBytes(n->value(), value.data(), value.size()))
|
||||
return n;
|
||||
else
|
||||
return nullptr;
|
||||
@@ -695,7 +706,8 @@ private:
|
||||
s = nextS;
|
||||
if (start.finished()) {
|
||||
if (nextS->length() == start.value.size() &&
|
||||
!memcmp(nextS->value(), start.value.data(), start.value.size()))
|
||||
equalBytes(nextS->value(), start.value.data(),
|
||||
start.value.size()))
|
||||
return noConflict();
|
||||
else
|
||||
return conflict();
|
||||
@@ -915,6 +927,9 @@ void internal_addWrites(ConflictSet::Impl *impl,
|
||||
impl->totalBytes += mallocBytesDelta;
|
||||
impl->memory_bytes.set(impl->totalBytes);
|
||||
#if SHOW_MEMORY
|
||||
// Testing-only cross-check of the accounting. `mallocBytes` is process-wide,
|
||||
// while `impl->totalBytes` only covers this instance, so this holds only
|
||||
// while this is the only live ConflictSet (see Internal.h).
|
||||
if (impl->totalBytes != mallocBytes) {
|
||||
abort();
|
||||
}
|
||||
@@ -927,6 +942,9 @@ void internal_setOldestVersion(ConflictSet::Impl *impl, int64_t oldestVersion) {
|
||||
impl->totalBytes += mallocBytesDelta;
|
||||
impl->memory_bytes.set(impl->totalBytes);
|
||||
#if SHOW_MEMORY
|
||||
// Testing-only cross-check of the accounting. `mallocBytes` is process-wide,
|
||||
// while `impl->totalBytes` only covers this instance, so this holds only
|
||||
// while this is the only live ConflictSet (see Internal.h).
|
||||
if (impl->totalBytes != mallocBytes) {
|
||||
abort();
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import struct
|
||||
|
||||
import conflict_set
|
||||
from conflict_set import *
|
||||
|
||||
|
||||
@@ -251,6 +253,25 @@ def test_merge_child_node48():
|
||||
cs.addWrites(1, write(b"\x00" * 8, b"\x00" * 10))
|
||||
|
||||
|
||||
def test_empty_key_null_pointer():
|
||||
# Regression test for issue #96: the header only constrains the length of a
|
||||
# key, so a zero-length key may be spelled with a null pointer. Both
|
||||
# implementations must agree on such a key, and must not pass the null
|
||||
# pointer to memcpy/memcmp, which is undefined behavior even when the length
|
||||
# is 0 (keyAfter() in SkipList.cpp did, on every empty-key point operation).
|
||||
null_key = conflict_set._Key(None, 0)
|
||||
with DebugConflictSet() as cs:
|
||||
cs.addWrites(1, WriteRange(null_key, null_key))
|
||||
assert cs.check(ReadRange(null_key, null_key, 0)) == [Result.CONFLICT]
|
||||
assert cs.check(ReadRange(null_key, null_key, 1)) == [Result.COMMIT]
|
||||
|
||||
# The same operations spelled with a non-null empty key must agree.
|
||||
with DebugConflictSet() as cs:
|
||||
cs.addWrites(1, write(b""))
|
||||
assert cs.check(read(0, b"")) == [Result.CONFLICT]
|
||||
assert cs.check(read(1, b"")) == [Result.COMMIT]
|
||||
|
||||
|
||||
def test_fixup_256_heterogeneous_versions():
|
||||
# Regression test for issue #89: recomputing the maxVersion of a Node256
|
||||
# must consider all of its children, not just those with an index < 16.
|
||||
|
||||
Reference in new issue
Block a user