diff --git a/python_tests/memo_test_types.py b/python_tests/memo_test_types.py index 770d03f4..7769e3fa 100644 --- a/python_tests/memo_test_types.py +++ b/python_tests/memo_test_types.py @@ -1,3 +1,4 @@ +from dataclasses import dataclass import dbzero as db0 from datetime import datetime @@ -220,3 +221,13 @@ def __init__(self, type, processor_type, data = None, key = None, parent = None, self.child_tasks = [] self.requirements = requirements self.max_retry = None + + +RANDOM_BYTES = b'DB0'*100000 + +@db0.memo(no_default_tags=True) +@dataclass +class MemoBlob: + def __init__(self, size_bytes: int): + assert size_bytes <= len(RANDOM_BYTES) + self.data = RANDOM_BYTES[:size_bytes] diff --git a/python_tests/test_issues_11.py b/python_tests/test_issues_11.py new file mode 100644 index 00000000..ea67633c --- /dev/null +++ b/python_tests/test_issues_11.py @@ -0,0 +1,25 @@ +import dbzero as db0 +import pytest +from .conftest import DB0_DIR +from datetime import datetime +from .memo_test_types import MemoBlob +import random + + +@pytest.mark.stress_test +@pytest.mark.parametrize("db0_slab_size", [{"slab_size": 64 << 20, "autocommit": False}], indirect=True) +def test_wide_lock_badaddr_issue(db0_slab_size): + db0.set_cache_size(8 << 30) + all_blobs = db0.list() + append_count = 300289 + # append large blobs to force wide locks + for count in range(append_count): + all_blobs.append(MemoBlob(24 << 10)) + if count % 50000 == 0: + print("Commit...") + db0.commit() + print(f"Appended {count} blobs") + + # faulty operation + all_blobs.append(MemoBlob(24 << 10)) + \ No newline at end of file diff --git a/src/dbzero/core/collections/SGB_Tree/SGB_CompressedLookupTree.hpp b/src/dbzero/core/collections/SGB_Tree/SGB_CompressedLookupTree.hpp index 5feea5cc..8f487c55 100644 --- a/src/dbzero/core/collections/SGB_Tree/SGB_CompressedLookupTree.hpp +++ b/src/dbzero/core/collections/SGB_Tree/SGB_CompressedLookupTree.hpp @@ -144,7 +144,7 @@ DB0_PACKED_END typename ItemEqualType, typename CompressedItemEqualType, typename CapacityType = std::uint16_t, - typename AddressType = std::uint32_t, + typename AddressType = std::uint64_t, typename HeaderType = db0::o_null, typename TreeHeaderType = db0::o_null> class sgb_compressed_lookup_types diff --git a/src/dbzero/core/collections/SGB_Tree/SGB_LookupTree.hpp b/src/dbzero/core/collections/SGB_Tree/SGB_LookupTree.hpp index 4c3e4aaf..11734316 100644 --- a/src/dbzero/core/collections/SGB_Tree/SGB_LookupTree.hpp +++ b/src/dbzero/core/collections/SGB_Tree/SGB_LookupTree.hpp @@ -333,7 +333,7 @@ DB0_PACKED_END typename ItemCompType, typename ItemEqualType, typename CapacityType = std::uint16_t, - typename AddressType = std::uint32_t, + typename AddressType = std::uint64_t, typename HeaderType = db0::o_null, typename TreeHeaderType = db0::o_null> class sgb_lookup_types diff --git a/src/dbzero/core/collections/SGB_Tree/SGB_Tree.hpp b/src/dbzero/core/collections/SGB_Tree/SGB_Tree.hpp index 70049dc3..012796f1 100644 --- a/src/dbzero/core/collections/SGB_Tree/SGB_Tree.hpp +++ b/src/dbzero/core/collections/SGB_Tree/SGB_Tree.hpp @@ -581,7 +581,7 @@ namespace db0 * @tparam HeaderT optional fixed-size header to be associated with each node / block (default is none / null), helpful when implementing extensions */ template , typename ItemEqualT = std::equal_to, - typename CapacityT = std::uint16_t, typename AddressT = std::uint32_t, typename HeaderT = o_null, typename TreeHeaderT = o_null> + typename CapacityT = std::uint16_t, typename AddressT = std::uint64_t, typename HeaderT = o_null, typename TreeHeaderT = o_null> class SGB_Tree: public SGB_TreeBase > { using super_t = SGB_TreeBase >; diff --git a/src/dbzero/core/memory/AlgoAllocator.cpp b/src/dbzero/core/memory/AlgoAllocator.cpp index b7f6d2b3..b651c585 100644 --- a/src/dbzero/core/memory/AlgoAllocator.cpp +++ b/src/dbzero/core/memory/AlgoAllocator.cpp @@ -13,11 +13,11 @@ namespace db0 { } - std::optional
AlgoAllocator::tryAlloc(std::size_t size, std::uint32_t slot_num, + std::optional
AlgoAllocator::tryAlloc(std::size_t size, std::uint32_t slot_num, bool aligned, unsigned char) { assert(slot_num == 0); - assert(!aligned && "AlgoAllocator: aligned allocation not supported"); + assert(!aligned && "AlgoAllocator: aligned allocation not supported"); assert(size == m_alloc_size && "AlgoAllocator: invalid alloc size requested"); return m_address_pool_f(m_next_i++); } @@ -63,7 +63,7 @@ namespace db0 void AlgoAllocator::reset() { m_next_i = 0; } - + Address AlgoAllocator::getRootAddress() const { return m_address_pool_f(0); } diff --git a/src/dbzero/core/memory/MetaAllocator.cpp b/src/dbzero/core/memory/MetaAllocator.cpp index 9b7482cc..9996c23e 100644 --- a/src/dbzero/core/memory/MetaAllocator.cpp +++ b/src/dbzero/core/memory/MetaAllocator.cpp @@ -753,7 +753,7 @@ namespace db0 void MetaAllocator::formatPrefix(std::shared_ptr prefix, std::size_t page_size, std::size_t slab_size) { - // create the meta-header and the address 0x0 + // create the meta-header at the address 0x0 OneShotAllocator one_shot(Address::fromOffset(0), o_meta_header::sizeOf()); Memspace memspace(Memspace::tag_from_reference(), prefix, one_shot); v_object meta_header(memspace, page_size, slab_size);