From c15d29643268057d85d3a1f9900ca9983cb324d6 Mon Sep 17 00:00:00 2001 From: Andrew Noyes Date: Wed, 17 Apr 2024 17:13:22 -0700 Subject: [PATCH] Exercise copyChildrenAndKeyFrom for Node{48,256} to itself --- CMakeLists.txt | 4 ++++ ConflictSet.cpp | 6 ++++++ test_conflict_set.py | 15 +++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index ce04877..b73142d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -263,6 +263,10 @@ if(BUILD_TESTING) # find. if(NOT CMAKE_CROSSCOMPILING) find_package(Python3 REQUIRED COMPONENTS Interpreter) + set_property( + DIRECTORY + APPEND + PROPERTY CMAKE_CONFIGURE_DEPENDS ${CMAKE_SOURCE_DIR}/test_conflict_set.py) execute_process( COMMAND ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/test_conflict_set.py list OUTPUT_VARIABLE SCRIPT_TESTS) diff --git a/ConflictSet.cpp b/ConflictSet.cpp index 09bf1b6..068847b 100644 --- a/ConflictSet.cpp +++ b/ConflictSet.cpp @@ -1146,8 +1146,14 @@ void freeAndMakeCapacityAtLeast(Node *&self, int capacity, // capacity. void maybeDecreaseCapacity(Node *&self, NodeAllocators *allocators, ConflictSet::Impl *impl) { + const int maxCapacity = (self->numChildren + int(self->entryPresent)) * (self->partialKeyLen + 1); +#if DEBUG_VERBOSE && !defined(NDEBUG) + fprintf(stderr, "maybeDecreaseCapacity: current: %d, max: %d, key: %s\n", + self->getCapacity(), maxCapacity, + getSearchPathPrintable(self).c_str()); +#endif if (self->getCapacity() <= maxCapacity) { return; } diff --git a/test_conflict_set.py b/test_conflict_set.py index 262911e..417dc40 100644 --- a/test_conflict_set.py +++ b/test_conflict_set.py @@ -66,6 +66,21 @@ def test_inner_full_words(): cs.check(read(1, b"\x21", b"\xc2")) +def test_decrease_capacity(): + # make a Node48, then a Node256 + for count in (17, 49): + with DebugConflictSet() as cs: + for i in range(count): + cs.addWrites(1, write(bytes(([0] * 99) + [i]))) + # lower its partial key length + cs.addWrites(2, write(bytes([0] * 98))) + # create work for setOldestVersion + for i in range(3, 1000): + cs.addWrites(i) + # setOldestVersion should decrease the capacity + cs.setOldestVersion(1) + + if __name__ == "__main__": # budget "pytest" for ctest integration without pulling in a dependency. You can of course still use pytest in local development. import argparse