diff --git a/builds/gnu/Makefile.am b/builds/gnu/Makefile.am index 779dd0c99..ad966609e 100644 --- a/builds/gnu/Makefile.am +++ b/builds/gnu/Makefile.am @@ -102,12 +102,12 @@ include_bitcoin_database_impl_primitivesdir = \ include_bitcoin_database_impl_primitives_HEADERS = \ ${srcdir}/../../include/bitcoin/database/impl/primitives/arrayhead.ipp \ ${srcdir}/../../include/bitcoin/database/impl/primitives/arraymap.ipp \ + ${srcdir}/../../include/bitcoin/database/impl/primitives/body.ipp \ ${srcdir}/../../include/bitcoin/database/impl/primitives/hashhead.ipp \ ${srcdir}/../../include/bitcoin/database/impl/primitives/hashmap.ipp \ ${srcdir}/../../include/bitcoin/database/impl/primitives/iterator.ipp \ ${srcdir}/../../include/bitcoin/database/impl/primitives/keys.ipp \ ${srcdir}/../../include/bitcoin/database/impl/primitives/linkage.ipp \ - ${srcdir}/../../include/bitcoin/database/impl/primitives/manager.ipp \ ${srcdir}/../../include/bitcoin/database/impl/primitives/nohead.ipp \ ${srcdir}/../../include/bitcoin/database/impl/primitives/nomap.ipp \ ${srcdir}/../../include/bitcoin/database/impl/primitives/nomaps.ipp @@ -238,13 +238,13 @@ include_bitcoin_database_primitivesdir = \ include_bitcoin_database_primitives_HEADERS = \ ${srcdir}/../../include/bitcoin/database/primitives/arrayhead.hpp \ ${srcdir}/../../include/bitcoin/database/primitives/arraymap.hpp \ + ${srcdir}/../../include/bitcoin/database/primitives/body.hpp \ ${srcdir}/../../include/bitcoin/database/primitives/column.hpp \ ${srcdir}/../../include/bitcoin/database/primitives/hashhead.hpp \ ${srcdir}/../../include/bitcoin/database/primitives/hashmap.hpp \ ${srcdir}/../../include/bitcoin/database/primitives/iterator.hpp \ ${srcdir}/../../include/bitcoin/database/primitives/keys.hpp \ ${srcdir}/../../include/bitcoin/database/primitives/linkage.hpp \ - ${srcdir}/../../include/bitcoin/database/primitives/manager.hpp \ ${srcdir}/../../include/bitcoin/database/primitives/nohead.hpp \ ${srcdir}/../../include/bitcoin/database/primitives/nomap.hpp \ ${srcdir}/../../include/bitcoin/database/primitives/nomaps.hpp \ @@ -361,12 +361,12 @@ test_libbitcoin_database_test_SOURCES = \ ${srcdir}/../../test/mocks/blocks.cpp \ ${srcdir}/../../test/primitives/arrayhead.cpp \ ${srcdir}/../../test/primitives/arraymap.cpp \ + ${srcdir}/../../test/primitives/body.cpp \ ${srcdir}/../../test/primitives/hashhead.cpp \ ${srcdir}/../../test/primitives/hashmap.cpp \ ${srcdir}/../../test/primitives/iterator.cpp \ ${srcdir}/../../test/primitives/keys.cpp \ ${srcdir}/../../test/primitives/linkage.cpp \ - ${srcdir}/../../test/primitives/manager.cpp \ ${srcdir}/../../test/primitives/nohead.cpp \ ${srcdir}/../../test/primitives/nomap.cpp \ ${srcdir}/../../test/query/amounts.cpp \ diff --git a/builds/msvc/vs2022/libbitcoin-database-test/libbitcoin-database-test.vcxproj b/builds/msvc/vs2022/libbitcoin-database-test/libbitcoin-database-test.vcxproj index 1fa17717a..a15e09cba 100644 --- a/builds/msvc/vs2022/libbitcoin-database-test/libbitcoin-database-test.vcxproj +++ b/builds/msvc/vs2022/libbitcoin-database-test/libbitcoin-database-test.vcxproj @@ -135,12 +135,12 @@ + - diff --git a/builds/msvc/vs2022/libbitcoin-database-test/libbitcoin-database-test.vcxproj.filters b/builds/msvc/vs2022/libbitcoin-database-test/libbitcoin-database-test.vcxproj.filters index 7fa9e4d5d..df6a33f30 100644 --- a/builds/msvc/vs2022/libbitcoin-database-test/libbitcoin-database-test.vcxproj.filters +++ b/builds/msvc/vs2022/libbitcoin-database-test/libbitcoin-database-test.vcxproj.filters @@ -105,6 +105,9 @@ src\primitives + + src\primitives + src\primitives @@ -120,9 +123,6 @@ src\primitives - - src\primitives - src\primitives diff --git a/builds/msvc/vs2022/libbitcoin-database/libbitcoin-database.vcxproj b/builds/msvc/vs2022/libbitcoin-database/libbitcoin-database.vcxproj index efedb59c9..31ff28add 100644 --- a/builds/msvc/vs2022/libbitcoin-database/libbitcoin-database.vcxproj +++ b/builds/msvc/vs2022/libbitcoin-database/libbitcoin-database.vcxproj @@ -163,13 +163,13 @@ + - @@ -227,12 +227,12 @@ + - diff --git a/builds/msvc/vs2022/libbitcoin-database/libbitcoin-database.vcxproj.filters b/builds/msvc/vs2022/libbitcoin-database/libbitcoin-database.vcxproj.filters index 0d8fcc5f1..c5d038085 100644 --- a/builds/msvc/vs2022/libbitcoin-database/libbitcoin-database.vcxproj.filters +++ b/builds/msvc/vs2022/libbitcoin-database/libbitcoin-database.vcxproj.filters @@ -206,6 +206,9 @@ include\bitcoin\database\primitives + + include\bitcoin\database\primitives + include\bitcoin\database\primitives @@ -224,9 +227,6 @@ include\bitcoin\database\primitives - - include\bitcoin\database\primitives - include\bitcoin\database\primitives @@ -394,6 +394,9 @@ include\bitcoin\database\impl\primitives + + include\bitcoin\database\impl\primitives + include\bitcoin\database\impl\primitives @@ -409,9 +412,6 @@ include\bitcoin\database\impl\primitives - - include\bitcoin\database\impl\primitives - include\bitcoin\database\impl\primitives diff --git a/builds/msvc/vs2026/libbitcoin-database-test/libbitcoin-database-test.vcxproj b/builds/msvc/vs2026/libbitcoin-database-test/libbitcoin-database-test.vcxproj index cdcacca69..a01439e5f 100644 --- a/builds/msvc/vs2026/libbitcoin-database-test/libbitcoin-database-test.vcxproj +++ b/builds/msvc/vs2026/libbitcoin-database-test/libbitcoin-database-test.vcxproj @@ -135,12 +135,12 @@ + - diff --git a/builds/msvc/vs2026/libbitcoin-database-test/libbitcoin-database-test.vcxproj.filters b/builds/msvc/vs2026/libbitcoin-database-test/libbitcoin-database-test.vcxproj.filters index 7fa9e4d5d..df6a33f30 100644 --- a/builds/msvc/vs2026/libbitcoin-database-test/libbitcoin-database-test.vcxproj.filters +++ b/builds/msvc/vs2026/libbitcoin-database-test/libbitcoin-database-test.vcxproj.filters @@ -105,6 +105,9 @@ src\primitives + + src\primitives + src\primitives @@ -120,9 +123,6 @@ src\primitives - - src\primitives - src\primitives diff --git a/builds/msvc/vs2026/libbitcoin-database/libbitcoin-database.vcxproj b/builds/msvc/vs2026/libbitcoin-database/libbitcoin-database.vcxproj index 3cba41c76..f3b32a16b 100644 --- a/builds/msvc/vs2026/libbitcoin-database/libbitcoin-database.vcxproj +++ b/builds/msvc/vs2026/libbitcoin-database/libbitcoin-database.vcxproj @@ -163,13 +163,13 @@ + - @@ -227,12 +227,12 @@ + - diff --git a/builds/msvc/vs2026/libbitcoin-database/libbitcoin-database.vcxproj.filters b/builds/msvc/vs2026/libbitcoin-database/libbitcoin-database.vcxproj.filters index 0d8fcc5f1..c5d038085 100644 --- a/builds/msvc/vs2026/libbitcoin-database/libbitcoin-database.vcxproj.filters +++ b/builds/msvc/vs2026/libbitcoin-database/libbitcoin-database.vcxproj.filters @@ -206,6 +206,9 @@ include\bitcoin\database\primitives + + include\bitcoin\database\primitives + include\bitcoin\database\primitives @@ -224,9 +227,6 @@ include\bitcoin\database\primitives - - include\bitcoin\database\primitives - include\bitcoin\database\primitives @@ -394,6 +394,9 @@ include\bitcoin\database\impl\primitives + + include\bitcoin\database\impl\primitives + include\bitcoin\database\impl\primitives @@ -409,9 +412,6 @@ include\bitcoin\database\impl\primitives - - include\bitcoin\database\impl\primitives - include\bitcoin\database\impl\primitives diff --git a/include/bitcoin/database.hpp b/include/bitcoin/database.hpp index 2989b4496..36f8ae717 100644 --- a/include/bitcoin/database.hpp +++ b/include/bitcoin/database.hpp @@ -41,13 +41,13 @@ #include #include #include +#include #include #include #include #include #include #include -#include #include #include #include diff --git a/include/bitcoin/database/impl/memory/mmap_dispatch.ipp b/include/bitcoin/database/impl/memory/mmap_dispatch.ipp index f2ca4b458..e93f603bb 100644 --- a/include/bitcoin/database/impl/memory/mmap_dispatch.ipp +++ b/include/bitcoin/database/impl/memory/mmap_dispatch.ipp @@ -34,9 +34,10 @@ namespace database { // ---------------------------------------------------------------------------- TEMPLATE -memory_ptr CLASS::set(size_t offset, size_t size, uint8_t backfill) NOEXCEPT +memory CLASS::get_filled(size_t offset, size_t size, + uint8_t backfill) NOEXCEPT { - // This is basically allocate(...) for application to a table head. + // This is basically allocate(...), backfilled for use with a table head. { std::unique_lock field_lock(field_mutex_); @@ -70,28 +71,29 @@ memory_ptr CLASS::set(size_t offset, size_t size, uint8_t backfill) NOEXCEPT } TEMPLATE -memory_ptr CLASS::get_capacity(size_t offset) const NOEXCEPT +memory CLASS::get_capacity(size_t offset) const NOEXCEPT { const auto allocated = to_width(capacity()); - const auto ptr = std::make_shared(remap_mutex_); - if (!loaded_ || is_null(ptr)) + memory out{ remap_mutex_ }; + + if (!loaded_) return {}; auto data = memory_map_.front(); - ptr->assign(std::next(data, offset), std::next(data, allocated)); - return ptr; + out.assign(std::next(data, offset), std::next(data, allocated)); + return out; } TEMPLATE memory::iterator CLASS::get_raw(size_t offset) const NOEXCEPT { // Pointer otherwise unguarded, not remap safe (use for fixed table heads). - return get_at_raw(zero, offset); + return get_raw_at(zero, offset); } TEMPLATE -memory::iterator CLASS::get_at_raw(size_t column, size_t offset) const NOEXCEPT +memory::iterator CLASS::get_raw_at(size_t column, size_t offset) const NOEXCEPT { // get_raw not used for variably-sized heads, so should always be bounded. BC_ASSERT(offset < (size() * widths.at(column))); @@ -101,41 +103,13 @@ memory::iterator CLASS::get_at_raw(size_t column, size_t offset) const NOEXCEPT } TEMPLATE -memory_ptr CLASS::get(size_t offset) const NOEXCEPT +memory CLASS::get(size_t offset) const NOEXCEPT { return get_at(zero, offset); } TEMPLATE -memory_ptr CLASS::get_at(size_t column, size_t offset) const NOEXCEPT -{ - if (column >= columns) - return {}; - - // Obtaining size before access prevents mutual mutex wait (deadlock). - const auto allocated = size() * widths.at(column); - - // Takes a shared lock on remap_mutex_ until destruct, blocking remap. - const auto ptr = std::make_shared(remap_mutex_); - - // loaded_ update is precluded by above lock, making this read atomic. - if (!loaded_ || is_null(ptr)) - return {}; - - // With offset > size the assignment is negative (stream is exhausted). - auto data = memory_map_.at(column); - ptr->assign(std::next(data, offset), std::next(data, allocated)); - return ptr; -} - -TEMPLATE -memory CLASS::get1(size_t offset) const NOEXCEPT -{ - return get_at1(zero, offset); -} - -TEMPLATE -memory CLASS::get_at1(size_t column, size_t offset) const NOEXCEPT +memory CLASS::get_at(size_t column, size_t offset) const NOEXCEPT { if (column >= columns) return {}; diff --git a/include/bitcoin/database/impl/memory/mmap_storage.ipp b/include/bitcoin/database/impl/memory/mmap_storage.ipp index fd348bfad..8ab5ee395 100644 --- a/include/bitcoin/database/impl/memory/mmap_storage.ipp +++ b/include/bitcoin/database/impl/memory/mmap_storage.ipp @@ -259,7 +259,7 @@ code CLASS::dump(const std::filesystem::path& path) const NOEXCEPT if (!ptr) return error::unloaded_file; - return file::create_file_ex(path, ptr->begin(), ptr->size()); + return file::create_file_ex(path, ptr.begin(), ptr.size()); } // ---------------------------------------------------------------------------- diff --git a/include/bitcoin/database/impl/primitives/arrayhead.ipp b/include/bitcoin/database/impl/primitives/arrayhead.ipp index b80df826d..57bad0353 100644 --- a/include/bitcoin/database/impl/primitives/arrayhead.ipp +++ b/include/bitcoin/database/impl/primitives/arrayhead.ipp @@ -71,7 +71,7 @@ bool CLASS::clear() NOEXCEPT // count to zero, which is picked up in arraymap::reset(). Body file size // remains unchanged and subject to initialization size at each startup. So // there is no reduction until restart, which can include config change. - std::fill_n(ptr->data(), size(), system::bit_all); + std::fill_n(ptr.data(), size(), system::bit_all); return set_body_count(zero); } @@ -81,7 +81,7 @@ bool CLASS::create() NOEXCEPT if (is_nonzero(size())) return false; - // Guards addition overflow in manager_.get (start must be valid). + // Guards addition overflow in body_.get (start must be valid). if (file_.allocate(link_to_position(initial_buckets_)) == storage::eof) return false; @@ -105,7 +105,7 @@ bool CLASS::get_body_count(Link& count) const NOEXCEPT // Body count is written as the first value in link size, but since // offsetting is a multiple of cell size, a full cell is consumed for it. // In case of nomap or disabled there are no cells, so file is link size. - count = to_array(ptr->data()); + count = to_array(ptr.data()); return true; } @@ -119,7 +119,7 @@ bool CLASS::set_body_count(const Link& count) NOEXCEPT // Body count is written as the first value in link size, but since // offsetting is a multiple of cell size, a full cell is consumed for it. // In case of nomap or disabled there are no cells, so file is link size. - to_array(ptr->data()) = count; + to_array(ptr.data()) = count; return true; } @@ -138,13 +138,13 @@ Link CLASS::at(size_t key) const NOEXCEPT return {}; const auto ptr = file_.get(position); - if (is_null(ptr)) + if (!ptr) return {}; if constexpr (aligned) { // Reads full padded word. - const auto raw = ptr->data(); + const auto raw = ptr.data(); const auto& head = *pointer_cast>(raw); // Aligned values must be masked to match terminal. @@ -152,7 +152,7 @@ Link CLASS::at(size_t key) const NOEXCEPT } else { - const auto& head = to_array(ptr->data()); + const auto& head = to_array(ptr.data()); mutex_.lock_shared(); const auto top = head; mutex_.unlock_shared(); @@ -167,20 +167,21 @@ bool CLASS::push(const Link& link, const Link& index) NOEXCEPT constexpr auto fill = bit_all; // Allocate as necessary and fill allocations. - const auto ptr = file_.set(link_to_position(index), bucket_size, fill); - if (is_null(ptr)) + const auto position = link_to_position(index); + const auto ptr = file_.get_filled(position, bucket_size, fill); + if (!ptr) return false; if constexpr (aligned) { // Writes full padded word (0x00 fill). - const auto raw = ptr->data(); + const auto raw = ptr.data(); auto& head = *pointer_cast>(raw); head.store(link, std::memory_order_relaxed); } else { - auto& head = to_array(ptr->data()); + auto& head = to_array(ptr.data()); mutex_.lock(); head = link; diff --git a/include/bitcoin/database/impl/primitives/arraymap.ipp b/include/bitcoin/database/impl/primitives/arraymap.ipp index b37a898b1..47146e64e 100644 --- a/include/bitcoin/database/impl/primitives/arraymap.ipp +++ b/include/bitcoin/database/impl/primitives/arraymap.ipp @@ -179,7 +179,7 @@ inline bool CLASS::get(const Link& link, Element& element) const NOEXCEPT return false; using namespace system; - iostream stream{ *ptr }; + iostream stream{ ptr }; reader source{ stream }; if constexpr (!is_slab) { BC_DEBUG_ONLY(source.set_limit(RowSize * element.count());) } @@ -201,7 +201,7 @@ bool CLASS::put(size_t key, const Element& element) NOEXCEPT // iostream.flush is a nop (direct copy). using namespace system; - iostream stream{ *ptr }; + iostream stream{ ptr }; finalizer sink{ stream }; if constexpr (!is_slab) { BC_DEBUG_ONLY(sink.set_limit(RowSize * element.count());) } diff --git a/include/bitcoin/database/impl/primitives/manager.ipp b/include/bitcoin/database/impl/primitives/body.ipp similarity index 88% rename from include/bitcoin/database/impl/primitives/manager.ipp rename to include/bitcoin/database/impl/primitives/body.ipp index a1a0b0cba..49ccf64f8 100644 --- a/include/bitcoin/database/impl/primitives/manager.ipp +++ b/include/bitcoin/database/impl/primitives/body.ipp @@ -16,8 +16,8 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -#ifndef LIBBITCOIN_DATABASE_PRIMITIVES_MANAGER_IPP -#define LIBBITCOIN_DATABASE_PRIMITIVES_MANAGER_IPP +#ifndef LIBBITCOIN_DATABASE_PRIMITIVES_BODY_IPP +#define LIBBITCOIN_DATABASE_PRIMITIVES_BODY_IPP #include @@ -26,7 +26,7 @@ namespace database { TEMPLATE template -inline memory_ptr CLASS::get() const NOEXCEPT +inline memory CLASS::get() const NOEXCEPT { if constexpr (is_one(columns)) return files_.get(); @@ -36,17 +36,7 @@ inline memory_ptr CLASS::get() const NOEXCEPT TEMPLATE template -inline memory CLASS::get1() const NOEXCEPT -{ - if constexpr (is_one(columns)) - return files_.get1(); - else - return files_.get_at1(Column); -} - -TEMPLATE -template -inline memory_ptr CLASS::get(const Link& link) const NOEXCEPT +inline memory CLASS::get(const Link& link) const NOEXCEPT { if (link.is_terminal()) return {}; @@ -60,22 +50,6 @@ inline memory_ptr CLASS::get(const Link& link) const NOEXCEPT return files_.get_at(Column, position); } -TEMPLATE -template -inline memory CLASS::get1(const Link& link) const NOEXCEPT -{ - if (link.is_terminal()) - return {}; - - const auto position = link_to_position(link); - - // memory.size() may be negative (stream treats as exhausted). - if constexpr (is_one(columns)) - return files_.get1(position); - else - return files_.get_at1(Column, position); -} - TEMPLATE template inline memory::iterator CLASS::get_raw1(const Link& link) const NOEXCEPT @@ -89,12 +63,12 @@ inline memory::iterator CLASS::get_raw1(const Link& link) const NOEXCEPT if constexpr (is_one(columns)) return files_.get_raw(position); else - return files_.get_at_raw(Column, position); + return files_.get_raw_at(Column, position); } TEMPLATE template > -inline memory_ptr CLASS::get_capacity(const Link& link) const NOEXCEPT +inline memory CLASS::get_capacity(const Link& link) const NOEXCEPT { if (link.is_terminal()) return {}; @@ -103,7 +77,7 @@ inline memory_ptr CLASS::get_capacity(const Link& link) const NOEXCEPT } TEMPLATE -CLASS::managers(storage& body) NOEXCEPT +CLASS::bodys(storage& body) NOEXCEPT : files_(body) { } diff --git a/include/bitcoin/database/impl/primitives/hashhead.ipp b/include/bitcoin/database/impl/primitives/hashhead.ipp index 6858e2324..b2fd79a9c 100644 --- a/include/bitcoin/database/impl/primitives/hashhead.ipp +++ b/include/bitcoin/database/impl/primitives/hashhead.ipp @@ -71,8 +71,8 @@ bool CLASS::create() NOEXCEPT BC_ASSERT_MSG(verify(), "unexpected head size"); // std::memset/fill_n have identical performance (on win32). - ////std::memset(ptr->data(), system::bit_all, allocation); - std::fill_n(ptr->data(), allocation, system::bit_all); + ////std::memset(ptr.data(), system::bit_all, allocation); + std::fill_n(ptr.data(), allocation, system::bit_all); return set_body_count(zero); } @@ -92,7 +92,7 @@ bool CLASS::get_body_count(Link& count) const NOEXCEPT // Body count is written as the first value in link size, but since // offsetting is a multiple of sell size, a full cell is consumed for it. // In case of disabled there are no cells, so file is link size. - link_array(count.value) = link_array(ptr->data()); + link_array(count.value) = link_array(ptr.data()); return true; } @@ -107,7 +107,7 @@ bool CLASS::set_body_count(const Link& count) NOEXCEPT // offsetting is a multiple of sell size, a full cell is consumed for it. // In case of disabled there are no cells, so file is link size. auto value = count.value; - link_array(ptr->data()) = link_array(value); + link_array(ptr.data()) = link_array(value); return true; } diff --git a/include/bitcoin/database/impl/primitives/hashmap.ipp b/include/bitcoin/database/impl/primitives/hashmap.ipp index f15e87b6e..ab8436469 100644 --- a/include/bitcoin/database/impl/primitives/hashmap.ipp +++ b/include/bitcoin/database/impl/primitives/hashmap.ipp @@ -165,7 +165,7 @@ inline Link CLASS::top(const Link& link) const NOEXCEPT } TEMPLATE -inline bool CLASS::exists(const memory_ptr& ptr, const Key& key) const NOEXCEPT +inline bool CLASS::exists(const memory& ptr, const Key& key) const NOEXCEPT { return !first(ptr, key).is_terminal(); } @@ -177,7 +177,7 @@ inline bool CLASS::exists(const Key& key) const NOEXCEPT } TEMPLATE -inline Link CLASS::first(const memory_ptr& ptr, const Key& key) const NOEXCEPT +inline Link CLASS::first(const memory& ptr, const Key& key) const NOEXCEPT { return first(ptr, head_.top(key), key); } @@ -208,7 +208,7 @@ inline Link CLASS::allocate(const Link& size) NOEXCEPT } TEMPLATE -inline memory_ptr CLASS::get_memory() const NOEXCEPT +inline memory CLASS::get_memory() const NOEXCEPT { return body_.get(); } @@ -218,10 +218,10 @@ Key CLASS::get_key(const Link& link) NOEXCEPT { using namespace system; const auto ptr = body_.get(link); - if (!ptr || is_lesser(ptr->size(), index_size)) + if (!ptr || is_lesser(ptr.size(), index_size)) return {}; - return unsafe_array_cast(std::next(ptr->begin(), + return unsafe_array_cast(std::next(ptr.begin(), Link::size)); } @@ -236,7 +236,7 @@ TEMPLATE ELEMENT_CONSTRAINT inline Link CLASS::find_link(const Key& key, Element& element) const NOEXCEPT { - // This override avoids duplicated memory_ptr construct in get(first()). + // This override avoids duplicated memory construct in get(first()). const auto ptr = get_memory(); const auto link = first(ptr, head_.top(key), key); if (link.is_terminal()) @@ -256,7 +256,7 @@ inline bool CLASS::get(const Link& link, Element& element) const NOEXCEPT // static TEMPLATE ELEMENT_CONSTRAINT -inline bool CLASS::get(const memory_ptr& ptr, const Link& link, +inline bool CLASS::get(const memory& ptr, const Link& link, Element& element) NOEXCEPT { return read(ptr, link, element); @@ -284,7 +284,7 @@ inline bool CLASS::get(const iterator& it, const Link& link, // static TEMPLATE ELEMENT_CONSTRAINT -bool CLASS::set(const memory_ptr& ptr, const Link& link, const Key& key, +bool CLASS::set(const memory& ptr, const Link& link, const Key& key, const Element& element) NOEXCEPT { using namespace system; @@ -295,13 +295,13 @@ bool CLASS::set(const memory_ptr& ptr, const Link& link, const Key& key, if (is_limited(start)) return false; - const auto size = ptr->size(); + const auto size = ptr.size(); const auto position = possible_narrow_and_sign_cast(start); if (position >= size) return false; // Stream starts at record and the index is skipped for reader convenience. - const auto offset = ptr->offset(start); + const auto offset = ptr.offset(start); if (is_null(offset)) return false; @@ -383,7 +383,7 @@ inline bool CLASS::put(const Link& link, const Key& key, TEMPLATE ELEMENT_CONSTRAINT -inline bool CLASS::put(const memory_ptr& ptr, const Link& link, const Key& key, +inline bool CLASS::put(const memory& ptr, const Link& link, const Key& key, const Element& element) NOEXCEPT { return write(ptr, link, key, element); @@ -391,7 +391,7 @@ inline bool CLASS::put(const memory_ptr& ptr, const Link& link, const Key& key, TEMPLATE ELEMENT_CONSTRAINT -inline bool CLASS::put(bool& duplicate, const memory_ptr& ptr, +inline bool CLASS::put(bool& duplicate, const memory& ptr, const Link& link, const Key& key, const Element& element) NOEXCEPT { Link previous{}; @@ -429,7 +429,7 @@ inline bool CLASS::commit(const Link& link, const Key& key) NOEXCEPT } TEMPLATE -bool CLASS::commit(const memory_ptr& ptr, const Link& link, +bool CLASS::commit(const memory& ptr, const Link& link, const Key& key) NOEXCEPT { using namespace system; @@ -437,7 +437,7 @@ bool CLASS::commit(const memory_ptr& ptr, const Link& link, return false; // get element offset (fault) - const auto offset = ptr->offset(body::link_to_position(link)); + const auto offset = ptr.offset(body::link_to_position(link)); if (is_null(offset)) return false; @@ -451,8 +451,7 @@ bool CLASS::commit(const memory_ptr& ptr, const Link& link, // static TEMPLATE -Link CLASS::first(const memory_ptr& ptr, const Link& link, - const Key& key) NOEXCEPT +Link CLASS::first(const memory& ptr, const Link& link, const Key& key) NOEXCEPT { using namespace system; if (!ptr) @@ -462,7 +461,7 @@ Link CLASS::first(const memory_ptr& ptr, const Link& link, while (!next.is_terminal()) { // get element offset (fault) - const auto offset = ptr->offset(body::link_to_position(next)); + const auto offset = ptr.offset(body::link_to_position(next)); if (is_null(offset)) return {}; @@ -481,8 +480,7 @@ Link CLASS::first(const memory_ptr& ptr, const Link& link, // static TEMPLATE ELEMENT_CONSTRAINT -bool CLASS::read(const memory_ptr& ptr, const Link& link, - Element& element) NOEXCEPT +bool CLASS::read(const memory& ptr, const Link& link, Element& element) NOEXCEPT { using namespace system; if (!ptr || link.is_terminal()) @@ -492,12 +490,12 @@ bool CLASS::read(const memory_ptr& ptr, const Link& link, if (is_limited(start)) return false; - const auto size = ptr->size(); + const auto size = ptr.size(); const auto position = possible_narrow_and_sign_cast(start); if (position >= size) return false; - const auto offset = ptr->offset(start); + const auto offset = ptr.offset(start); if (is_null(offset)) return false; @@ -512,7 +510,7 @@ bool CLASS::read(const memory_ptr& ptr, const Link& link, TEMPLATE ELEMENT_CONSTRAINT -bool CLASS::write(const memory_ptr& ptr, const Link& link, const Key& key, +bool CLASS::write(const memory& ptr, const Link& link, const Key& key, const Element& element) NOEXCEPT { Link unused{}; @@ -521,7 +519,7 @@ bool CLASS::write(const memory_ptr& ptr, const Link& link, const Key& key, TEMPLATE ELEMENT_CONSTRAINT -bool CLASS::write(Link& previous, const memory_ptr& ptr, const Link& link, +bool CLASS::write(Link& previous, const memory& ptr, const Link& link, const Key& key, const Element& element) NOEXCEPT { using namespace system; @@ -532,12 +530,12 @@ bool CLASS::write(Link& previous, const memory_ptr& ptr, const Link& link, if (is_limited(start)) return false; - const auto size = ptr->size(); + const auto size = ptr.size(); const auto position = possible_narrow_and_sign_cast(start); if (position >= size) return false; - const auto offset = ptr->offset(start); + const auto offset = ptr.offset(start); if (is_null(offset)) return false; diff --git a/include/bitcoin/database/impl/primitives/iterator.ipp b/include/bitcoin/database/impl/primitives/iterator.ipp index 7db4b1125..144c0f572 100644 --- a/include/bitcoin/database/impl/primitives/iterator.ipp +++ b/include/bitcoin/database/impl/primitives/iterator.ipp @@ -28,14 +28,14 @@ namespace libbitcoin { namespace database { TEMPLATE -CLASS::iterator(memory_ptr&& data, const Link& start, Key&& key) NOEXCEPT +CLASS::iterator(memory&& data, const Link& start, Key&& key) NOEXCEPT : memory_(std::move(data)), key_(std::forward(key)), link_(to_first(start)) { } TEMPLATE -CLASS::iterator(memory_ptr&& data, const Link& start, const Key& key) NOEXCEPT +CLASS::iterator(memory&& data, const Link& start, const Key& key) NOEXCEPT : memory_(std::move(data)), key_(key), link_(to_first(start)) { } @@ -59,7 +59,7 @@ inline const Link& CLASS::get() const NOEXCEPT } TEMPLATE -inline const memory_ptr& CLASS::ptr() const NOEXCEPT +inline const memory& CLASS::ptr() const NOEXCEPT { return memory_; } @@ -99,13 +99,13 @@ inline CLASS& CLASS::operator++() NOEXCEPT return *this; } -TEMPLATE -inline CLASS CLASS::operator++(int) NOEXCEPT -{ - auto previous = *this; - ++(*this); - return previous; -} +////TEMPLATE +////inline CLASS CLASS::operator++(int) NOEXCEPT +////{ +//// auto previous = *this; +//// ++(*this); +//// return previous; +////} // protected // ---------------------------------------------------------------------------- @@ -120,7 +120,7 @@ Link CLASS::to_first(Link link) const NOEXCEPT while (!link.is_terminal()) { // get element offset (fault) - const auto offset = memory_->offset(manager::link_to_position(link)); + const auto offset = memory_.offset(body::link_to_position(link)); if (is_null(offset)) return Link::terminal; @@ -142,7 +142,7 @@ Link CLASS::to_next(Link link) const NOEXCEPT while (!link.is_terminal()) { // get element offset (fault) - auto offset = memory_->offset(manager::link_to_position(link)); + auto offset = memory_.offset(body::link_to_position(link)); if (is_null(offset)) return Link::terminal; @@ -152,7 +152,7 @@ Link CLASS::to_next(Link link) const NOEXCEPT return link; // get next element offset (fault) - offset = memory_->offset(manager::link_to_position(link)); + offset = memory_.offset(body::link_to_position(link)); if (is_null(offset)) return Link::terminal; diff --git a/include/bitcoin/database/impl/primitives/nohead.ipp b/include/bitcoin/database/impl/primitives/nohead.ipp index 67693beca..e907f7fc5 100644 --- a/include/bitcoin/database/impl/primitives/nohead.ipp +++ b/include/bitcoin/database/impl/primitives/nohead.ipp @@ -63,7 +63,7 @@ bool CLASS::clear() NOEXCEPT // count to zero, which is picked up in arraymap::reset(). Body file size // remains unchanged and subject to initialization size at each startup. So // there is no reduction until restart, which can include config change. - std::fill_n(ptr->data(), size(), system::bit_all); + std::fill_n(ptr.data(), size(), system::bit_all); return set_body_count(zero); } @@ -73,7 +73,7 @@ bool CLASS::create() NOEXCEPT if (is_nonzero(size())) return false; - // Guards addition overflow in manager_.get (start must be valid). + // Guards addition overflow in body_.get (start must be valid). if (file_.allocate(link_to_position(initial_buckets_)) == storage::eof) return false; @@ -97,7 +97,7 @@ bool CLASS::get_body_count(Link& count) const NOEXCEPT // Body count is written as the first value in link size, but since // offsetting is a multiple of cell size, a full cell is consumed for it. // In case of nomap or disabled there are no cells, so file is link size. - count = to_array(ptr->data()); + count = to_array(ptr.data()); return true; } @@ -111,7 +111,7 @@ bool CLASS::set_body_count(const Link& count) NOEXCEPT // Body count is written as the first value in link size, but since // offsetting is a multiple of cell size, a full cell is consumed for it. // In case of nomap or disabled there are no cells, so file is link size. - to_array(ptr->data()) = count; + to_array(ptr.data()) = count; return true; } diff --git a/include/bitcoin/database/impl/primitives/nomap.ipp b/include/bitcoin/database/impl/primitives/nomap.ipp index f3b68090c..0f466bf08 100644 --- a/include/bitcoin/database/impl/primitives/nomap.ipp +++ b/include/bitcoin/database/impl/primitives/nomap.ipp @@ -26,7 +26,7 @@ namespace database { TEMPLATE CLASS::nomap(storage& header, storage& body) NOEXCEPT - : head_(header, 0), manager_(body) + : head_(header, 0), body_(body) { } @@ -38,19 +38,19 @@ bool CLASS::create() NOEXCEPT { Link count{}; return head_.create() && - head_.get_body_count(count) && manager_.truncate(count); + head_.get_body_count(count) && body_.truncate(count); } TEMPLATE bool CLASS::close() NOEXCEPT { - return head_.set_body_count(manager_.count()); + return head_.set_body_count(body_.count()); } TEMPLATE bool CLASS::backup(bool) NOEXCEPT { - return head_.set_body_count(manager_.count()); + return head_.set_body_count(body_.count()); } TEMPLATE @@ -58,7 +58,7 @@ bool CLASS::restore() NOEXCEPT { Link count{}; return head_.verify() && - head_.get_body_count(count) && manager_.truncate(count); + head_.get_body_count(count) && body_.truncate(count); } TEMPLATE @@ -66,7 +66,7 @@ bool CLASS::verify() const NOEXCEPT { Link count{}; return head_.verify() && - head_.get_body_count(count) && count == manager_.count(); + head_.get_body_count(count) && count == body_.count(); } // sizing @@ -87,50 +87,50 @@ size_t CLASS::head_size() const NOEXCEPT TEMPLATE size_t CLASS::body_size() const NOEXCEPT { - return manager_.size(); + return body_.size(); } TEMPLATE size_t CLASS::capacity() const NOEXCEPT { - return manager_.capacity(); + return body_.capacity(); } TEMPLATE Link CLASS::count() const NOEXCEPT { - return manager_.count(); + return body_.count(); } TEMPLATE bool CLASS::truncate(const Link& count) NOEXCEPT { - return manager_.truncate(count); + return body_.truncate(count); } TEMPLATE bool CLASS::expand(const Link& count) NOEXCEPT { - return manager_.expand(count); + return body_.expand(count); } TEMPLATE bool CLASS::drop() NOEXCEPT { - return manager_.truncate(0) && backup(); + return body_.truncate(0) && backup(); } TEMPLATE bool CLASS::reserve(const Link& size) NOEXCEPT { // Not writer-writer thread safe (two writers may share reserve). - return manager_.reserve(size); + return body_.reserve(size); } TEMPLATE -memory_ptr CLASS::get_memory() const NOEXCEPT +memory CLASS::get_memory() const NOEXCEPT { - return manager_.get(); + return body_.get(); } // error condition @@ -139,19 +139,19 @@ memory_ptr CLASS::get_memory() const NOEXCEPT TEMPLATE code CLASS::get_fault() const NOEXCEPT { - return manager_.get_fault(); + return body_.get_fault(); } TEMPLATE size_t CLASS::get_space() const NOEXCEPT { - return manager_.get_space(); + return body_.get_space(); } TEMPLATE code CLASS::reload() NOEXCEPT { - return manager_.reload(); + return body_.reload(); } // query interface @@ -160,23 +160,22 @@ code CLASS::reload() NOEXCEPT // static TEMPLATE template > -bool CLASS::get(const memory_ptr& ptr, const Link& link, - Element& element) NOEXCEPT +bool CLASS::get(const memory& ptr, const Link& link, Element& element) NOEXCEPT { using namespace system; if (!ptr || link.is_terminal()) return false; - const auto start = manager::link_to_position(link); + const auto start = body::link_to_position(link); if (is_limited(start)) return false; - const auto size = ptr->size(); + const auto size = ptr.size(); const auto position = possible_narrow_and_sign_cast(start); if (position >= size) return false; - const auto offset = ptr->offset(start); + const auto offset = ptr.offset(start); if (is_null(offset)) return false; @@ -211,19 +210,19 @@ template > bool CLASS::put(const Link& link, const Element& element) NOEXCEPT { using namespace system; - const auto ptr = manager_.get(link); + const auto ptr = body_.get(link); return put(ptr, element); } TEMPLATE template > -bool CLASS::put(const memory_ptr& ptr, const Element& element) NOEXCEPT +bool CLASS::put(const memory& ptr, const Element& element) NOEXCEPT { using namespace system; if (!ptr) return false; - iostream stream{ *ptr }; + iostream stream{ ptr }; flipper sink{ stream }; if constexpr (!is_slab) @@ -239,7 +238,7 @@ template > inline bool CLASS::put_link(Link& link, const Element& element) NOEXCEPT { const auto count = element.count(); - link = manager_.allocate(count); + link = body_.allocate(count); return put(link, element); } @@ -251,20 +250,20 @@ inline Link CLASS::put_link(const Element& element) NOEXCEPT return put_link(link, element) ? link : Link{}; } -/// NOT THREAD SAFE (used only for height index with writer ordering). +// NOT THREAD SAFE (used only for height index with writer ordering). TEMPLATE template > inline bool CLASS::commit(const Element& element) NOEXCEPT { // Zero allocation provides link of next (presumably reserved) element. - const auto link = manager_.allocate(0); + const auto link = body_.allocate(0); // Write element into reserved but unallocated space. - if (!put(manager_.get_capacity(link), element)) + if (!put(body_.get_capacity(link), element)) return false; // Allocate reserved and written element (exposes logically). - return !manager_.allocate(element.count()).is_terminal(); + return !body_.allocate(element.count()).is_terminal(); } } // namespace database diff --git a/include/bitcoin/database/impl/primitives/nomaps.ipp b/include/bitcoin/database/impl/primitives/nomaps.ipp index 39f59c2c9..4b9c8863b 100644 --- a/include/bitcoin/database/impl/primitives/nomaps.ipp +++ b/include/bitcoin/database/impl/primitives/nomaps.ipp @@ -28,7 +28,7 @@ namespace database { TEMPLATE CLASS::nomaps(storage& header, storage& body) NOEXCEPT : head_(header, 0), - manager_(body) + body_(body) { } @@ -40,19 +40,19 @@ bool CLASS::create() NOEXCEPT { Link count{}; return head_.create() && - head_.get_body_count(count) && manager_.truncate(count); + head_.get_body_count(count) && body_.truncate(count); } TEMPLATE bool CLASS::close() NOEXCEPT { - return head_.set_body_count(manager_.count()); + return head_.set_body_count(body_.count()); } TEMPLATE bool CLASS::backup(bool) NOEXCEPT { - return head_.set_body_count(manager_.count()); + return head_.set_body_count(body_.count()); } TEMPLATE @@ -60,7 +60,7 @@ bool CLASS::restore() NOEXCEPT { Link count{}; return head_.verify() && - head_.get_body_count(count) && manager_.truncate(count); + head_.get_body_count(count) && body_.truncate(count); } TEMPLATE @@ -68,7 +68,7 @@ bool CLASS::verify() const NOEXCEPT { Link count{}; return head_.verify() && - head_.get_body_count(count) && count == manager_.count(); + head_.get_body_count(count) && count == body_.count(); } // sizing @@ -77,31 +77,31 @@ bool CLASS::verify() const NOEXCEPT TEMPLATE size_t CLASS::body_size() const NOEXCEPT { - return manager_.size(); + return body_.size(); } TEMPLATE Link CLASS::count() const NOEXCEPT { - return manager_.count(); + return body_.count(); } TEMPLATE Link CLASS::allocate(const Link& count) NOEXCEPT { - return manager_.allocate(count); + return body_.allocate(count); } TEMPLATE bool CLASS::truncate(const Link& count) NOEXCEPT { - return manager_.truncate(count); + return body_.truncate(count); } TEMPLATE bool CLASS::drop() NOEXCEPT { - return manager_.truncate(0) && backup(); + return body_.truncate(0) && backup(); } // Faults. @@ -110,19 +110,19 @@ bool CLASS::drop() NOEXCEPT TEMPLATE code CLASS::get_fault() const NOEXCEPT { - return manager_.get_fault(); + return body_.get_fault(); } TEMPLATE size_t CLASS::get_space() const NOEXCEPT { - return manager_.get_space(); + return body_.get_space(); } TEMPLATE code CLASS::reload() NOEXCEPT { - return manager_.reload(); + return body_.reload(); } // query interface @@ -138,7 +138,7 @@ TEMPLATE template memory CLASS::get_memory() const NOEXCEPT { - return manager_.template get1(); + return body_.template get(); } // static @@ -184,7 +184,7 @@ TEMPLATE template bool CLASS::put(const Link& link, const Element& element) NOEXCEPT { - const auto ptr = manager_.template get_raw1(link); + const auto ptr = body_.template get_raw1(link); return put(ptr, element); } @@ -198,7 +198,8 @@ bool CLASS::put(memory::iterator it, const Element& element) NOEXCEPT return false; using namespace system; - iostream stream{ it, system::maximum }; + const auto bytes = width * element.count(); + iostream stream{ it, possible_narrow_and_sign_cast(bytes) }; flipper sink{ stream }; BC_DEBUG_ONLY(sink.set_limit(width * element.count());) diff --git a/include/bitcoin/database/memory/accessor.hpp b/include/bitcoin/database/memory/accessor.hpp index c4a1cb541..63c782982 100644 --- a/include/bitcoin/database/memory/accessor.hpp +++ b/include/bitcoin/database/memory/accessor.hpp @@ -25,15 +25,14 @@ namespace libbitcoin { namespace database { +/// Not thread safe. /// Shared r/w access to a memory buffer, mutex blocks memory remap. -/// Zero/negative size is allowed (automatically handled by bc streams). class accessor final { public: typedef uint8_t value_type; typedef value_type* iterator; typedef const value_type* const_iterator; - typedef std::shared_ptr ptr; DELETE_COPY(accessor); DEFAULT_MOVE(accessor); @@ -50,7 +49,14 @@ class accessor final { } + /// True if holds lock on memory buffer. + inline operator bool() const NOEXCEPT + { + return !is_null(begin_); + } + /// Set the buffer, where end is within allocated space. + /// Zero/negative size is allowed (automatically handled by bc streams). /// End should be initialized to logical space though that may contract or /// expand during accessor lifetime. The only guarantee offered by end is /// that it remains within allocated space and is initially logical space. @@ -58,36 +64,32 @@ class accessor final { begin_ = begin; end_ = end; - ////BC_ASSERT(!system::is_negative(size())); } - /// memory interface - /// ----------------------------------------------------------------------- - - inline operator bool() const NOEXCEPT + /// Release lock and invalidate pointers (idempotent). + inline void reset() NOEXCEPT { - return !is_null(begin_); + if (!is_null(begin_)) + { + shared_lock_.unlock(); + begin_ = nullptr; + end_ = nullptr; + } } - /// Return an offset from begin, nullptr if end or past end. + /// Return an offset from begin, nullptr if past buffer. inline uint8_t* offset(size_t bytes) const NOEXCEPT { if (system::is_greater(bytes, size())) return nullptr; - BC_PUSH_WARNING(NO_POINTER_ARITHMETIC) - return begin_ + bytes; - BC_POP_WARNING() - ////return std::next(begin_, bytes); + return std::next(begin_, bytes); } /// The logical buffer size (from begin to end). inline ptrdiff_t size() const NOEXCEPT { - BC_PUSH_WARNING(NO_POINTER_ARITHMETIC) - return system::possible_narrow_and_sign_cast(end_ - begin_); - BC_POP_WARNING() - ////return std::distance(begin_, end_); + return std::distance(begin_, end_); } /// Alias for begin. @@ -96,12 +98,6 @@ class accessor final return begin(); } - /// Get logical buffer (guarded against remap only). - inline operator system::data_slab() const NOEXCEPT - { - return { begin(), end() }; - }; - /// Buffer start. inline uint8_t* begin() const NOEXCEPT { @@ -114,14 +110,22 @@ class accessor final return end_; } + /// Get logical buffer (guarded against remap only). + inline operator system::data_slab() const NOEXCEPT + { + return { begin(), end() }; + }; + private: + // These are not thread safe. uint8_t* begin_{}; uint8_t* end_{}; + + // This is thread safe. std::shared_lock shared_lock_; }; using memory = accessor; -using memory_ptr = accessor::ptr; } // namespace database } // namespace libbitcoin diff --git a/include/bitcoin/database/memory/finalizer.hpp b/include/bitcoin/database/memory/finalizer.hpp index a39169064..1146be5f5 100644 --- a/include/bitcoin/database/memory/finalizer.hpp +++ b/include/bitcoin/database/memory/finalizer.hpp @@ -65,7 +65,7 @@ class finalizer_ finalization finalize_; }; -/// A finalizing byte reader/writer that copies data from/to a memory_ptr. +/// A finalizing byte reader/writer that copies data from/to a memory object. using finalizer = finalizer_<>; BC_POP_WARNING() diff --git a/include/bitcoin/database/memory/interfaces/storage.hpp b/include/bitcoin/database/memory/interfaces/storage.hpp index 7c7343dad..8ee755640 100644 --- a/include/bitcoin/database/memory/interfaces/storage.hpp +++ b/include/bitcoin/database/memory/interfaces/storage.hpp @@ -89,12 +89,12 @@ class storage virtual size_t allocate(size_t count) NOEXCEPT = 0; /// Get remap-protected r/w access to offset (or null) allocated to size. - virtual memory_ptr set(size_t offset, size_t size, + virtual memory get_filled(size_t offset, size_t size, uint8_t backfill) NOEXCEPT = 0; /// Get remap-protected r/w access to start/offset of memory map (or null). /// Pointer is constrained to starting write within full capacity. - virtual memory_ptr get_capacity(size_t offset=zero) const NOEXCEPT = 0; + virtual memory get_capacity(size_t offset=zero) const NOEXCEPT = 0; /// Get unprotected r/w access to start/offset of memory map (or null). /// Pointer is constrained to starting write within full capacity. @@ -102,25 +102,16 @@ class storage /// Get unprotected r/w access to start/offset of memory map (or null). /// Pointer is constrained to starting write within full capacity. - virtual memory::iterator get_at_raw(size_t column, + virtual memory::iterator get_raw_at(size_t column, size_t offset=zero) const NOEXCEPT = 0; /// Get remap-protected r/w access to start/offset of memory map (or null). /// Pointer is constrained to starting write within logical allocation. - virtual memory_ptr get(size_t offset=zero) const NOEXCEPT = 0; + virtual memory get(size_t offset=zero) const NOEXCEPT = 0; /// Same as get() but within specified column (or null for invalid column). /// Pointer is constrained to starting write within logical allocation. - virtual memory_ptr get_at(size_t column, - size_t offset=zero) const NOEXCEPT = 0; - - /// Get remap-protected r/w access to start/offset of memory map (or null). - /// Pointer is constrained to starting write within logical allocation. - virtual memory get1(size_t offset=zero) const NOEXCEPT = 0; - - /// Same as get() but within specified column (or null for invalid column). - /// Pointer is constrained to starting write within logical allocation. - virtual memory get_at1(size_t column, + virtual memory get_at(size_t column, size_t offset=zero) const NOEXCEPT = 0; }; diff --git a/include/bitcoin/database/memory/mmap.hpp b/include/bitcoin/database/memory/mmap.hpp index b78d6ec33..b4514c087 100644 --- a/include/bitcoin/database/memory/mmap.hpp +++ b/include/bitcoin/database/memory/mmap.hpp @@ -132,31 +132,24 @@ class mmap size_t allocate(size_t count) NOEXCEPT override; /// Remap-protected r/w access to offset (or null) allocated to size. - memory_ptr set(size_t offset, size_t size, + memory get_filled(size_t offset, size_t size, uint8_t backfill) NOEXCEPT override; /// Remap-protected r/w access to start/offset (or null), within capacity. - memory_ptr get_capacity(size_t offset=zero) const NOEXCEPT override; + memory get_capacity(size_t offset=zero) const NOEXCEPT override; /// Unprotected r/w access to start/offset (or null), within logical. memory::iterator get_raw(size_t offset=zero) const NOEXCEPT override; /// Unprotected r/w access to start/offset (or null), within logical. - memory::iterator get_at_raw(size_t column, + memory::iterator get_raw_at(size_t column, size_t offset=zero) const NOEXCEPT override; /// Remap-protected r/w access to start/offset (or null), within logical. - memory_ptr get(size_t offset=zero) const NOEXCEPT override; + memory get(size_t offset=zero) const NOEXCEPT override; /// Same as get() but within specified column (or null for invalid column). - memory_ptr get_at(size_t column, - size_t offset=zero) const NOEXCEPT override; - - /// Remap-protected r/w access to start/offset (or null), within logical. - memory get1(size_t offset=zero) const NOEXCEPT override; - - /// Same as get() but within specified column (or null for invalid column). - memory get_at1(size_t column, size_t offset=zero) const NOEXCEPT override; + memory get_at(size_t column, size_t offset=zero) const NOEXCEPT override; protected: template diff --git a/include/bitcoin/database/primitives/arrayhead.hpp b/include/bitcoin/database/primitives/arrayhead.hpp index 1e84a1af6..4af44a78a 100644 --- a/include/bitcoin/database/primitives/arrayhead.hpp +++ b/include/bitcoin/database/primitives/arrayhead.hpp @@ -22,7 +22,7 @@ #include #include #include -#include +#include namespace libbitcoin { namespace database { @@ -70,7 +70,7 @@ class arrayhead private: using link = Link::integer; - using body = manager, Link::size>; + using body = database::body, Link::size>; static_assert(std::atomic::is_always_lock_free); static_assert(is_nonzero(Link::size)); static constexpr auto bucket_size = Align ? sizeof(link) : Link::size; diff --git a/include/bitcoin/database/primitives/arraymap.hpp b/include/bitcoin/database/primitives/arraymap.hpp index e150ae880..78d19e643 100644 --- a/include/bitcoin/database/primitives/arraymap.hpp +++ b/include/bitcoin/database/primitives/arraymap.hpp @@ -24,7 +24,7 @@ #include #include #include -#include +#include namespace libbitcoin { namespace database { @@ -115,7 +115,7 @@ class arraymap private: static constexpr auto is_slab = (RowSize == max_size_t); using head = database::arrayhead; - using body = database::manager, RowSize>; + using body = database::body, RowSize>; // Thread safe (index/top/push). // Not thread safe (create/open/close/backup/restore). diff --git a/include/bitcoin/database/primitives/manager.hpp b/include/bitcoin/database/primitives/body.hpp similarity index 86% rename from include/bitcoin/database/primitives/manager.hpp rename to include/bitcoin/database/primitives/body.hpp index 6f9cbbeb0..945c36408 100644 --- a/include/bitcoin/database/primitives/manager.hpp +++ b/include/bitcoin/database/primitives/body.hpp @@ -16,8 +16,8 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -#ifndef LIBBITCOIN_DATABASE_PRIMITIVES_MANAGER_HPP -#define LIBBITCOIN_DATABASE_PRIMITIVES_MANAGER_HPP +#ifndef LIBBITCOIN_DATABASE_PRIMITIVES_BODY_HPP +#define LIBBITCOIN_DATABASE_PRIMITIVES_BODY_HPP #include #include @@ -28,7 +28,7 @@ namespace libbitcoin { namespace database { template -class managers +class bodys { public: using integer = typename Link::integer; @@ -40,29 +40,25 @@ class managers static constexpr integer cast_link(size_t link) NOEXCEPT; public: - DEFAULT_COPY_MOVE_DESTRUCT(managers); + DEFAULT_COPY_MOVE_DESTRUCT(bodys); /// Return memory object for column full map (null only if oom or unloaded). template - inline memory_ptr get() const NOEXCEPT; - template - inline memory get1() const NOEXCEPT; + inline memory get() const NOEXCEPT; /// Return memory object for column record (null only if oom or unloaded). /// Pointer is constrained to starting write within logical allocation. template - inline memory_ptr get(const Link& link) const NOEXCEPT; - template - inline memory get1(const Link& link) const NOEXCEPT; + inline memory get(const Link& link) const NOEXCEPT; template inline memory::iterator get_raw1(const Link& link) const NOEXCEPT; /// Return memory object (limited to AoS) within capacity. template = true> - inline memory_ptr get_capacity(const Link& link) const NOEXCEPT; + inline memory get_capacity(const Link& link) const NOEXCEPT; /// Manage shared multi-backed byte storage device (caller owns storage). - managers(storage& body) NOEXCEPT; + bodys(storage& body) NOEXCEPT; /// The aggregate logical byte size (cold size) across all columns. inline size_t size() const NOEXCEPT; @@ -121,15 +117,15 @@ class managers }; template -using manager = managers; +using body = bodys; } // namespace database } // namespace libbitcoin #define TEMPLATE template -#define CLASS managers +#define CLASS bodys -#include +#include #undef CLASS #undef TEMPLATE diff --git a/include/bitcoin/database/primitives/hashmap.hpp b/include/bitcoin/database/primitives/hashmap.hpp index ab245a321..4413fac74 100644 --- a/include/bitcoin/database/primitives/hashmap.hpp +++ b/include/bitcoin/database/primitives/hashmap.hpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include namespace libbitcoin { namespace database { @@ -109,11 +109,11 @@ class hashmap inline Link top(const Link& list) const NOEXCEPT; /// True if an instance of object with key exists. - inline bool exists(const memory_ptr& ptr, const Key& key) const NOEXCEPT; + inline bool exists(const memory& ptr, const Key& key) const NOEXCEPT; inline bool exists(const Key& key) const NOEXCEPT; /// Return first element link or terminal if not found/error. - inline Link first(const memory_ptr& ptr, const Key& key) const NOEXCEPT; + inline Link first(const memory& ptr, const Key& key) const NOEXCEPT; inline Link first(const Key& key) const NOEXCEPT; /// Iterator holds shared lock on storage remap. @@ -124,7 +124,7 @@ class hashmap inline Link allocate(const Link& size) NOEXCEPT; /// Return ptr for batch processing, holds shared lock on storage remap. - inline memory_ptr get_memory() const NOEXCEPT; + inline memory get_memory() const NOEXCEPT; /// Return the associated search key (terminal link returns default). Key get_key(const Link& link) NOEXCEPT; @@ -143,7 +143,7 @@ class hashmap /// Get element at link using get_memory() ptr, false if deserialize error. template = true> - static inline bool get(const memory_ptr& ptr, const Link& link, + static inline bool get(const memory& ptr, const Link& link, Element& element) NOEXCEPT; /// Get element at link, false if deserialize error. @@ -158,7 +158,7 @@ class hashmap /// Set element into previously allocated link (follow with commit). template = true> - static bool set(const memory_ptr& ptr, const Link& link, const Key& key, + static bool set(const memory& ptr, const Link& link, const Key& key, const Element& element) NOEXCEPT; /// Set element into previously allocated link (follow with commit). @@ -190,39 +190,38 @@ class hashmap /// Set/commit allocated element at link to key, using get_memory() ptr. template = true> - inline bool put(const memory_ptr& ptr, const Link& link, + inline bool put(const memory& ptr, const Link& link, const Key& key, const Element& element) NOEXCEPT; /// Set/commit allocated element at link to key, using get_memory() ptr. template = true> - inline bool put(bool& duplicate, const memory_ptr& ptr, - const Link& link, const Key& key, const Element& element) NOEXCEPT; + inline bool put(bool& duplicate, const memory& ptr, const Link& link, + const Key& key, const Element& element) NOEXCEPT; /// Commit previously set element at link to key. inline Link commit_link(const Link& link, const Key& key) NOEXCEPT; inline bool commit(const Link& link, const Key& key) NOEXCEPT; - bool commit(const memory_ptr& ptr, const Link& link, - const Key& key) NOEXCEPT; + bool commit(const memory& ptr, const Link& link, const Key& key) NOEXCEPT; protected: - /// memory_ptr parameter must be from start (i.e. from get_memory()). + /// memory parameter must be from start (i.e. from get_memory()). /// Get first element matching key, from top link and whole table memory. - static Link first(const memory_ptr& ptr, const Link& link, + static Link first(const memory& ptr, const Link& link, const Key& key) NOEXCEPT; - /// memory_ptr parameter must be from start (i.e. from get_memory()). + /// memory parameter must be from start (i.e. from get_memory()). /// Get element at link using memory object, false if deserialize error. template = true> - static bool read(const memory_ptr& ptr, const Link& link, + static bool read(const memory& ptr, const Link& link, Element& element) NOEXCEPT; - /// memory_ptr parameter must be from start (i.e. from get_memory()). + /// memory parameter must be from start (i.e. from get_memory()). /// Set and commit previously allocated element at link to key. template = true> - bool write(const memory_ptr& ptr, const Link& link, - const Key& key, const Element& element) NOEXCEPT; + bool write(const memory& ptr, const Link& link, const Key& key, + const Element& element) NOEXCEPT; template = true> - bool write(Link& previous, const memory_ptr& ptr, const Link& link, + bool write(Link& previous, const memory& ptr, const Link& link, const Key& key, const Element& element) NOEXCEPT; private: @@ -230,7 +229,7 @@ class hashmap static constexpr auto key_size = keys::size(); static constexpr auto index_size = Link::size + key_size; using head = database::hashhead; - using body = database::manager; + using body = database::body; // Thread safe (index/top/push). // Not thread safe (create/open/close/backup/restore). diff --git a/include/bitcoin/database/primitives/iterator.hpp b/include/bitcoin/database/primitives/iterator.hpp index a735a7b37..744f993f2 100644 --- a/include/bitcoin/database/primitives/iterator.hpp +++ b/include/bitcoin/database/primitives/iterator.hpp @@ -22,24 +22,24 @@ #include #include #include -#include +#include namespace libbitcoin { namespace database { -/// THIS HOLDS A memory_ptr WHICH HOLDS A SHARED REMAP LOCK. IT SHOULD NOT BE -/// HELD WHILE THE HOLDING CODE EXECUTES READS AGAINST THE SAME TABLE. +/// THIS HOLDS A memory object WHICH HOLDS A SHARED REMAP LOCK. IT SHOULD NOT +/// BE HELD WHILE THE HOLDING CODE EXECUTES READS AGAINST THE SAME TABLE. /// OTHERWISE A DEADLOCK WILL OCCUR WHEN THE TABLE'S FILE IS EXPANDED, WHICH /// WAITS ON THE RELEASE OF THE SHARED LOCK (REMAP REQUIRES EXCLUSIVE ACCESS). /// THE hashmap.get(const iterator& it, ...) METHOD EXISTS TO PREVENT A CALL TO -/// manager.get(), WHICH DESPITE BEING A READ WOULD CAUSE A DEADLOCK. THIS IS +/// body.get(), WHICH DESPITE BEING A READ WOULD CAUSE A DEADLOCK. THIS IS /// BECAUSE IT CANNOT COMPLETE ITS READ WHILE REMAP IS WAITING ON ACCESS. /// A SIMILAR RISK ARISES FROM HOLDING iterator WHILE READING/WRITING ANY OTHER /// TABLE AS A CYCLE CAUSING THE ABOVE WILL OCCUR. USE THE ITERATOR TO COLLECT /// A SET FROM ITS TABLE AND THEN CALL iterator.release() TO FREE THE POINTER. /// This class is not thread safe. -/// Size non-max implies record manager (ordinal record links). +/// Size non-max implies record body (ordinal record links). template class iterator { @@ -52,8 +52,8 @@ class iterator static constexpr bool end() NOEXCEPT { return false; } /// This advances to first match (or terminal). - iterator(memory_ptr&& data, const Link& start, Key&& key) NOEXCEPT; - iterator(memory_ptr&& data, const Link& start, const Key& key) NOEXCEPT; + iterator(memory&& data, const Link& start, Key&& key) NOEXCEPT; + iterator(memory&& data, const Link& start, const Key& key) NOEXCEPT; /// Advance to next and return false if none found. inline bool advance() NOEXCEPT; @@ -64,10 +64,10 @@ class iterator /// Return current link, terminal if not found. inline const Link& get() const NOEXCEPT; - /// Access the underlying memory pointer. - inline const memory_ptr& ptr() const NOEXCEPT; + /// Access the underlying memory reference. + inline const memory& ptr() const NOEXCEPT; - /// Release the memory pointer, invalidates iterator. + /// Release the memory reference, invalidates iterator. inline void reset() NOEXCEPT; /// True if the iterator is not terminal. @@ -81,20 +81,20 @@ class iterator /// Increment operators. inline self& operator++() NOEXCEPT; - inline self operator++(int) NOEXCEPT; + ////inline self operator++(int) NOEXCEPT; protected: Link to_first(Link link) const NOEXCEPT; Link to_next(Link link) const NOEXCEPT; private: - using manager = database::manager; + using body = database::body; static constexpr auto key_size = keys::size(); // This is not thread safe, but it's object is not modified here and the // memory that it refers to is not addressable until written, and writes // are guarded by allocator, which is protected by mutex. - memory_ptr memory_; + memory memory_; // This is thread safe. const Key key_; diff --git a/include/bitcoin/database/primitives/nohead.hpp b/include/bitcoin/database/primitives/nohead.hpp index da5a46bf8..1fdb6237d 100644 --- a/include/bitcoin/database/primitives/nohead.hpp +++ b/include/bitcoin/database/primitives/nohead.hpp @@ -21,7 +21,7 @@ #include #include -#include +#include namespace libbitcoin { namespace database { @@ -60,7 +60,7 @@ class nohead private: using link = Link::integer; - using body = manager, Link::size>; + using body = database::body, Link::size>; static constexpr auto bucket_size = Link::size; static_assert(is_nonzero(bucket_size)); diff --git a/include/bitcoin/database/primitives/nomap.hpp b/include/bitcoin/database/primitives/nomap.hpp index 07892c9b9..0b20d34a3 100644 --- a/include/bitcoin/database/primitives/nomap.hpp +++ b/include/bitcoin/database/primitives/nomap.hpp @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include namespace libbitcoin { @@ -86,7 +86,7 @@ class nomap bool reserve(const Link& size) NOEXCEPT; /// Return ptr for batch processing, holds shared lock on storage remap. - memory_ptr get_memory() const NOEXCEPT; + memory get_memory() const NOEXCEPT; /// Errors. /// ----------------------------------------------------------------------- @@ -105,7 +105,7 @@ class nomap /// Get element at link using get_memory() ptr, false if deserialize error. template = true> - static bool get(const memory_ptr& ptr, const Link& link, + static bool get(const memory& ptr, const Link& link, Element& element) NOEXCEPT; /// Get element at link. @@ -120,7 +120,7 @@ class nomap template = true> bool put(const Link& link, const Element& element) NOEXCEPT; template = true> - bool put(const memory_ptr& ptr, const Element& element) NOEXCEPT; + bool put(const memory& ptr, const Element& element) NOEXCEPT; /// Put element and return link. template = true> @@ -135,7 +135,7 @@ class nomap private: static constexpr auto is_slab = (Size == max_size_t); - using manager = database::manager, Size>; + using body = database::body, Size>; using head = database::nohead; // Thread safe (index/top/push). @@ -143,7 +143,7 @@ class nomap head head_; // Thread safe. - manager manager_; + body body_; }; template diff --git a/include/bitcoin/database/primitives/nomaps.hpp b/include/bitcoin/database/primitives/nomaps.hpp index f68b2b25f..cf825d522 100644 --- a/include/bitcoin/database/primitives/nomaps.hpp +++ b/include/bitcoin/database/primitives/nomaps.hpp @@ -25,7 +25,7 @@ namespace libbitcoin { namespace database { -/// SoA aggregate array table: one shared head + one unified managers body. +/// SoA aggregate array table: one shared head + one unified bodys body. template class nomaps { @@ -94,7 +94,7 @@ class nomaps protected: using head = database::nohead; - using body = database::managers, + using body = database::bodys, Columns::width...>; template @@ -105,7 +105,7 @@ class nomaps head head_; // This is thread safe. - body manager_; + body body_; }; } // namespace database diff --git a/include/bitcoin/database/primitives/primitives.hpp b/include/bitcoin/database/primitives/primitives.hpp index fbcb943cc..b0a61d2aa 100644 --- a/include/bitcoin/database/primitives/primitives.hpp +++ b/include/bitcoin/database/primitives/primitives.hpp @@ -19,17 +19,20 @@ #ifndef LIBBITCOIN_DATABASE_PRIMITIVES_PRIMITIVES_HPP #define LIBBITCOIN_DATABASE_PRIMITIVES_PRIMITIVES_HPP +// helpers #include #include #include #include -#include // heads #include #include #include +// bodies +#include + // tables #include #include diff --git a/test/memory/mmap.cpp b/test/memory/mmap.cpp index 480cd38ef..f5838dac6 100644 --- a/test/memory/mmap.cpp +++ b/test/memory/mmap.cpp @@ -164,6 +164,7 @@ BOOST_AUTO_TEST_CASE(mmap__load__unloaded__true) BOOST_REQUIRE(!instance.close()); BOOST_REQUIRE(!instance.get_fault()); } + BOOST_AUTO_TEST_CASE(mmap__load__shared__load_locked) { const std::string file = TEST_PATH; @@ -440,18 +441,18 @@ BOOST_AUTO_TEST_CASE(mmap__truncate__decrease__success_logical_decreased_capacit BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(mmap__set__unloaded__false) +BOOST_AUTO_TEST_CASE(mmap__get_filled__unloaded__false) { const std::string file = TEST_PATH; BOOST_REQUIRE(test::create(file)); map instance(file); BOOST_REQUIRE(!instance.open()); - BOOST_REQUIRE(!instance.set(42, 24, 0xff)); + BOOST_REQUIRE(!instance.get_filled(42, 24, 0xff)); BOOST_REQUIRE(!instance.close()); BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(mmap__set__loaded__expected_capacity) +BOOST_AUTO_TEST_CASE(mmap__get_filled__loaded__expected_capacity) { constexpr auto half_rate = 50_size; constexpr auto minimum = 42_size; @@ -466,11 +467,11 @@ BOOST_AUTO_TEST_CASE(mmap__set__loaded__expected_capacity) BOOST_REQUIRE(!instance.load()); BOOST_REQUIRE_EQUAL(instance.capacity(), minimum); - auto memory = instance.set(offset, size, fill); + auto memory = instance.get_filled(offset, size, fill); BOOST_REQUIRE(memory); - const auto expected = std::next(instance.get()->data(), offset); - BOOST_REQUIRE(memory->data() == expected); + const auto expected = std::next(instance.get().data(), offset); + BOOST_REQUIRE(memory.data() == expected); constexpr auto capacity = offset + size + to_half(offset + size); BOOST_REQUIRE_EQUAL(instance.capacity(), capacity); @@ -482,7 +483,7 @@ BOOST_AUTO_TEST_CASE(mmap__set__loaded__expected_capacity) BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(mmap__set__add_overflow__eof) +BOOST_AUTO_TEST_CASE(mmap__get_filled__add_overflow__eof) { const std::string file = TEST_PATH; BOOST_REQUIRE(test::create(file)); @@ -490,14 +491,14 @@ BOOST_AUTO_TEST_CASE(mmap__set__add_overflow__eof) map instance(file); BOOST_REQUIRE(!instance.open()); BOOST_REQUIRE(!instance.load()); - BOOST_REQUIRE(instance.set(100, 24, 0xff)); - BOOST_REQUIRE(!instance.set(max_size_t, 24, 0xff)); + BOOST_REQUIRE(instance.get_filled(100, 24, 0xff)); + BOOST_REQUIRE(!instance.get_filled(max_size_t, 24, 0xff)); BOOST_REQUIRE(!instance.unload()); BOOST_REQUIRE(!instance.close()); BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(mmap__set__minimum_no_expansion__expected_capacity) +BOOST_AUTO_TEST_CASE(mmap__get_filled__minimum_no_expansion__expected_capacity) { constexpr auto rate = 0_size; constexpr auto minimum = 42_size; @@ -510,7 +511,7 @@ BOOST_AUTO_TEST_CASE(mmap__set__minimum_no_expansion__expected_capacity) map instance(file, minimum, rate); BOOST_REQUIRE(!instance.open()); BOOST_REQUIRE(!instance.load()); - BOOST_REQUIRE(instance.set(offset, size, fill)); + BOOST_REQUIRE(instance.get_filled(offset, size, fill)); constexpr auto capacity = std::max(minimum, offset + size); BOOST_REQUIRE_EQUAL(instance.capacity(), capacity); @@ -519,7 +520,7 @@ BOOST_AUTO_TEST_CASE(mmap__set__minimum_no_expansion__expected_capacity) BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(mmap__set__no_minimum_expansion__expected_capacity) +BOOST_AUTO_TEST_CASE(mmap__get_filled__no_minimum_expansion__expected_capacity) { // map will fail if minimum is zero. constexpr auto rate = 42_size; @@ -533,7 +534,7 @@ BOOST_AUTO_TEST_CASE(mmap__set__no_minimum_expansion__expected_capacity) map instance(file, minimum, rate); BOOST_REQUIRE(!instance.open()); BOOST_REQUIRE(!instance.load()); - BOOST_REQUIRE(instance.set(offset, size, fill)); + BOOST_REQUIRE(instance.get_filled(offset, size, fill)); // These add only because offset + size is 100. constexpr auto capacity = offset + size + rate; @@ -543,7 +544,7 @@ BOOST_AUTO_TEST_CASE(mmap__set__no_minimum_expansion__expected_capacity) BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(mmap__set__loaded__expected_fill) +BOOST_AUTO_TEST_CASE(mmap__get_filled__loaded__expected_fill) { BC_PUSH_WARNING(NO_POINTER_ARITHMETIC) @@ -559,14 +560,14 @@ BOOST_AUTO_TEST_CASE(mmap__set__loaded__expected_fill) BOOST_REQUIRE(!instance.open()); BOOST_REQUIRE(!instance.load()); - auto memory = instance.set(offset1, size1, fill1); + auto memory = instance.get_filled(offset1, size1, fill1); BOOST_REQUIRE(memory); constexpr auto capacity = offset1 + size1 + to_half(offset1 + size1); BOOST_REQUIRE_EQUAL(instance.capacity(), capacity); BOOST_REQUIRE_EQUAL(capacity, 12u); - auto data = instance.get()->data(); + auto data = instance.get().data(); ////BOOST_REQUIRE_EQUAL(data[ 0], 0x00_u8); // cannot assume mmap default fill ////BOOST_REQUIRE_EQUAL(data[ 1], 0x00_u8); // cannot assume mmap default fill ////BOOST_REQUIRE_EQUAL(data[ 2], 0x00_u8); // cannot assume mmap default fill @@ -589,7 +590,7 @@ BOOST_AUTO_TEST_CASE(mmap__set__loaded__expected_fill) constexpr auto offset2 = 15_size; constexpr auto fill2 = 0b1111'0000; memory.reset(); - memory = instance.set(offset2, size2, fill2); + memory = instance.get_filled(offset2, size2, fill2); BOOST_REQUIRE(memory); constexpr auto capacity2 = offset2 + size2 + to_half(offset2 + size2); @@ -602,8 +603,8 @@ BOOST_AUTO_TEST_CASE(mmap__set__loaded__expected_fill) data[18] = 'g'; data[19] = 'h'; - // Get data again in case it has been remapped by set(). - data = instance.get()->data(); + // Get data again in case it has been remapped by get_filled(). + data = instance.get().data(); ////BOOST_REQUIRE_EQUAL(data[ 0], 0x00_u8); // cannot assume mmap default fill ////BOOST_REQUIRE_EQUAL(data[ 1], 0x00_u8); // cannot assume mmap default fill ////BOOST_REQUIRE_EQUAL(data[ 2], 0x00_u8); // cannot assume mmap default fill @@ -681,8 +682,8 @@ BOOST_AUTO_TEST_CASE(mmap__get__size__expected) constexpr auto expected = 42u; auto ptr = instance.get(instance.allocate(expected)); - BOOST_CHECK_EQUAL(ptr->size(), expected); - BOOST_CHECK_EQUAL(*ptr->begin(), 0x00u); + BOOST_CHECK_EQUAL(ptr.size(), expected); + BOOST_CHECK_EQUAL(*ptr.begin(), 0x00u); BOOST_REQUIRE(instance.unload()); ptr.reset(); @@ -702,8 +703,8 @@ BOOST_AUTO_TEST_CASE(mmap__get_capacity__size__expected) constexpr auto expected = 42u; auto ptr = instance.get_capacity(instance.allocate(expected)); - BOOST_CHECK_EQUAL(ptr->size(), expected); - BOOST_CHECK_EQUAL(*ptr->begin(), 0x00u); + BOOST_REQUIRE_EQUAL(ptr.size(), expected); + BOOST_REQUIRE_EQUAL(*ptr.begin(), 0x00u); BOOST_REQUIRE(instance.unload()); ptr.reset(); @@ -722,8 +723,9 @@ BOOST_AUTO_TEST_CASE(mmap__get_raw__always__nonblocking) BOOST_REQUIRE(!instance.load()); constexpr auto expected = 42u; - auto raw = instance.get_raw(instance.allocate(expected)); - BOOST_CHECK_EQUAL(*raw, 0x00u); + const auto raw = instance.get_raw(instance.allocate(expected)); + BOOST_REQUIRE(!is_null(raw)); + BOOST_REQUIRE_EQUAL(*raw, 0x00u); // raw pointer does not block remap. BOOST_REQUIRE(!instance.unload()); @@ -771,13 +773,13 @@ BOOST_AUTO_TEST_CASE(mmap__write__read__expected) auto memory = instance.get(instance.allocate(sizeof(uint64_t))); BOOST_REQUIRE(memory); - system::unsafe_to_little_endian(memory->begin(), expected); + system::unsafe_to_little_endian(memory.begin(), expected); memory.reset(); BOOST_REQUIRE(!instance.flush()); memory = instance.get(); BOOST_REQUIRE(memory); - BOOST_REQUIRE_EQUAL(system::unsafe_from_little_endian(memory->begin()), expected); + BOOST_REQUIRE_EQUAL(system::unsafe_from_little_endian(memory.begin()), expected); memory.reset(); BOOST_REQUIRE(!instance.unload()); @@ -829,10 +831,10 @@ BOOST_AUTO_TEST_CASE(mmap__allocate__aggregate_remap__expected_geometry) BOOST_REQUIRE(write0_column0); BOOST_REQUIRE(write0_column1); - write0_column0->begin()[0] = 'a'; - write0_column1->begin()[0] = 'b'; - write0_column1->begin()[1] = 'c'; - write0_column1->begin()[2] = 'd'; + write0_column0.begin()[0] = 'a'; + write0_column1.begin()[0] = 'b'; + write0_column1.begin()[1] = 'c'; + write0_column1.begin()[2] = 'd'; write0_column0.reset(); write0_column1.reset(); @@ -852,10 +854,10 @@ BOOST_AUTO_TEST_CASE(mmap__allocate__aggregate_remap__expected_geometry) BOOST_REQUIRE(write1_column0); BOOST_REQUIRE(write1_column1); - write1_column0->begin()[0] = 'w'; - write1_column1->begin()[0] = 'x'; - write1_column1->begin()[1] = 'y'; - write1_column1->begin()[2] = 'z'; + write1_column0.begin()[0] = 'w'; + write1_column1.begin()[0] = 'x'; + write1_column1.begin()[1] = 'y'; + write1_column1.begin()[2] = 'z'; write1_column0.reset(); write1_column1.reset(); BOOST_REQUIRE(!instance.unload()); @@ -872,14 +874,14 @@ BOOST_AUTO_TEST_CASE(mmap__allocate__aggregate_remap__expected_geometry) auto read_column1 = instance.get_at(1, 0); BOOST_REQUIRE(read_column0); BOOST_REQUIRE(read_column1); - BOOST_REQUIRE_EQUAL(read_column0->begin()[0], 'a'); - BOOST_REQUIRE_EQUAL(read_column0->begin()[last], 'w'); - BOOST_REQUIRE_EQUAL(read_column1->begin()[0], 'b'); - BOOST_REQUIRE_EQUAL(read_column1->begin()[1], 'c'); - BOOST_REQUIRE_EQUAL(read_column1->begin()[2], 'd'); - BOOST_REQUIRE_EQUAL(read_column1->begin()[last * 3 + 0], 'x'); - BOOST_REQUIRE_EQUAL(read_column1->begin()[last * 3 + 1], 'y'); - BOOST_REQUIRE_EQUAL(read_column1->begin()[last * 3 + 2], 'z'); + BOOST_REQUIRE_EQUAL(read_column0.begin()[0], 'a'); + BOOST_REQUIRE_EQUAL(read_column0.begin()[last], 'w'); + BOOST_REQUIRE_EQUAL(read_column1.begin()[0], 'b'); + BOOST_REQUIRE_EQUAL(read_column1.begin()[1], 'c'); + BOOST_REQUIRE_EQUAL(read_column1.begin()[2], 'd'); + BOOST_REQUIRE_EQUAL(read_column1.begin()[last * 3 + 0], 'x'); + BOOST_REQUIRE_EQUAL(read_column1.begin()[last * 3 + 1], 'y'); + BOOST_REQUIRE_EQUAL(read_column1.begin()[last * 3 + 2], 'z'); read_column0.reset(); read_column1.reset(); diff --git a/test/mocks/chunk_storage.hpp b/test/mocks/chunk_storage.hpp index 55a97ce59..3fd6d2b64 100644 --- a/test/mocks/chunk_storage.hpp +++ b/test/mocks/chunk_storage.hpp @@ -240,7 +240,8 @@ class chunk_storages // access // ------------------------------------------------------------------------ - memory_ptr set(size_t offset, size_t size, uint8_t backfill) NOEXCEPT override + memory get_filled(size_t offset, size_t size, + uint8_t backfill) NOEXCEPT override { { std::unique_lock field_lock(field_mutex_); @@ -261,13 +262,12 @@ class chunk_storages return get(offset); } - memory_ptr get_capacity(size_t offset=zero) const NOEXCEPT override + memory get_capacity(size_t offset=zero) const NOEXCEPT override { - using namespace system; auto& buffer = at(zero); - const auto ptr = emplace_shared(map_mutex_); - ptr->assign(get_raw(offset), std::next(buffer.data(), buffer.size())); - return ptr; + accessor out{ map_mutex_ }; + out.assign(get_raw(offset), std::next(buffer.data(), buffer.size())); + return out; } memory::iterator get_raw(size_t offset=zero) const NOEXCEPT override @@ -275,33 +275,18 @@ class chunk_storages return std::next(at(zero).data(), offset); } - memory::iterator get_at_raw(size_t column, + memory::iterator get_raw_at(size_t column, size_t offset=zero) const NOEXCEPT override { return std::next(at(column).data(), offset); } - memory_ptr get(size_t offset=zero) const NOEXCEPT override + memory get(size_t offset=zero) const NOEXCEPT override { return get_at(zero, offset); } - memory_ptr get_at(size_t column, size_t offset=zero) const NOEXCEPT override - { - using namespace system; - auto data = at(column).data(); - const auto allocated = size() * widths.at(column); - const auto ptr = emplace_shared(map_mutex_); - ptr->assign(std::next(data, offset), std::next(data, allocated)); - return ptr; - } - - memory get1(size_t offset=zero) const NOEXCEPT override - { - return get_at1(zero, offset); - } - - memory get_at1(size_t column, size_t offset=zero) const NOEXCEPT override + memory get_at(size_t column, size_t offset=zero) const NOEXCEPT override { using namespace system; auto data = at(column).data(); diff --git a/test/primitives/arrayhead.cpp b/test/primitives/arrayhead.cpp index 4a29b33e5..1b730b365 100644 --- a/test/primitives/arrayhead.cpp +++ b/test/primitives/arrayhead.cpp @@ -37,17 +37,18 @@ static_assert(buckets == 20u); using link = linkage; using test_header = arrayhead; -class nullptr_storage - : public test::chunk_storages -{ -public: - using chunk_storages::chunk_storages; - - memory_ptr get(size_t size) const NOEXCEPT override - { - return is_zero(size) ? chunk_storages::get(size) : nullptr; - } -}; +// TODO: see hashhead. +////class nullptr_storage +//// : public test::chunk_storages +////{ +////public: +//// using chunk_storages::chunk_storages; +//// +//// memory get(size_t size) const NOEXCEPT override +//// { +//// return is_zero(size) ? chunk_storages::get(size) : memory{}; +//// } +////}; BOOST_AUTO_TEST_CASE(arrayhead__create__size__expected) { diff --git a/test/primitives/manager.cpp b/test/primitives/body.cpp similarity index 64% rename from test/primitives/manager.cpp rename to test/primitives/body.cpp index 8c7fc3cd4..2ba99b9eb 100644 --- a/test/primitives/manager.cpp +++ b/test/primitives/body.cpp @@ -19,7 +19,7 @@ #include "../test.hpp" #include "../mocks/chunk_storage.hpp" -BOOST_AUTO_TEST_SUITE(manager_tests) +BOOST_AUTO_TEST_SUITE(body_tests) using namespace system; @@ -29,39 +29,39 @@ using key2 = system::data_array<2>; // slabs -BOOST_AUTO_TEST_CASE(manager__count__empty_slab__zero) +BOOST_AUTO_TEST_CASE(body__count__empty_slab__zero) { test::chunk_storage file; - const manager, key1, max_size_t> instance(file); + const body, key1, max_size_t> instance(file); BOOST_REQUIRE(is_zero(instance.count())); BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(manager__count__non_empty_slab__expected) +BOOST_AUTO_TEST_CASE(body__count__non_empty_slab__expected) { constexpr auto expected = 42u; data_chunk buffer(expected, 0xff); test::chunk_storage file(buffer); // Slab sizing is byte-based (arbitrary, links are file offsets). - const manager, key1, max_size_t> instance(file); + const body, key1, max_size_t> instance(file); BOOST_REQUIRE_EQUAL(instance.count(), expected); BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(manager__capacity__non_reserved__expected) +BOOST_AUTO_TEST_CASE(body__capacity__non_reserved__expected) { constexpr auto expected = 42u; data_chunk buffer(expected, 0xff); test::chunk_storage file(buffer); // Capacity is byte-based. - const manager, key1, max_size_t> instance(file); + const body, key1, max_size_t> instance(file); BOOST_REQUIRE_EQUAL(instance.capacity(), expected); BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(manager__capacity__reserved__expected) +BOOST_AUTO_TEST_CASE(body__capacity__reserved__expected) { constexpr auto expand = 7u; constexpr auto initial = 42u; @@ -70,40 +70,40 @@ BOOST_AUTO_TEST_CASE(manager__capacity__reserved__expected) test::chunk_storage file(buffer); // Capacity is byte-based. - manager, key1, max_size_t> instance(file); + body, key1, max_size_t> instance(file); BOOST_REQUIRE(instance.reserve(expand)); BOOST_REQUIRE_EQUAL(instance.capacity(), expected); BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(manager__truncate__terminal_slab__false_unchanged) +BOOST_AUTO_TEST_CASE(body__truncate__terminal_slab__false_unchanged) { data_chunk buffer{}; test::chunk_storage file(buffer); - manager, key1, max_size_t> instance(file); + body, key1, max_size_t> instance(file); BOOST_REQUIRE(!instance.truncate(linkage<4>::terminal)); BOOST_REQUIRE_EQUAL(instance.count(), zero); BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(manager__truncate__overflow_slab__false_unchanged) +BOOST_AUTO_TEST_CASE(body__truncate__overflow_slab__false_unchanged) { constexpr auto size = 42u; data_chunk buffer(size, 0xff); test::chunk_storage file(buffer); - manager, key1, max_size_t> instance(file); + body, key1, max_size_t> instance(file); BOOST_REQUIRE(!instance.truncate(add1(size))); BOOST_REQUIRE_EQUAL(instance.count(), size); BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(manager__truncate__half_full_slab__true_changed) +BOOST_AUTO_TEST_CASE(body__truncate__half_full_slab__true_changed) { constexpr auto size = 42u; constexpr auto half = to_half(size); data_chunk buffer(size, 0xff); test::chunk_storage file(buffer); - manager, key1, max_size_t> instance(file); + body, key1, max_size_t> instance(file); BOOST_REQUIRE(instance.truncate(half)); BOOST_REQUIRE_EQUAL(instance.count(), half); @@ -116,60 +116,60 @@ BOOST_AUTO_TEST_CASE(manager__truncate__half_full_slab__true_changed) BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(manager__allocate__eof_slab__terminal_unchanged) +BOOST_AUTO_TEST_CASE(body__allocate__eof_slab__terminal_unchanged) { data_chunk buffer{}; test::chunk_storage file(buffer); - manager, key1, max_size_t> instance(file); + body, key1, max_size_t> instance(file); BOOST_REQUIRE_EQUAL(instance.allocate(storage::eof), linkage<7>::terminal); BOOST_REQUIRE_EQUAL(instance.count(), zero); BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(manager__allocate__terminal_slab__terminal_unchanged) +BOOST_AUTO_TEST_CASE(body__allocate__terminal_slab__terminal_unchanged) { data_chunk buffer{}; test::chunk_storage file(buffer); - manager, key1, max_size_t> instance(file); + body, key1, max_size_t> instance(file); BOOST_REQUIRE_EQUAL(instance.allocate(linkage<4>::terminal), linkage<4>::terminal); BOOST_REQUIRE_EQUAL(instance.count(), zero); BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(manager__allocate__empty_slab__expected) +BOOST_AUTO_TEST_CASE(body__allocate__empty_slab__expected) { constexpr auto expected = 42u; data_chunk buffer{}; test::chunk_storage file(buffer); - manager, key1, max_size_t> instance(file); + body, key1, max_size_t> instance(file); BOOST_REQUIRE_EQUAL(instance.allocate(expected), zero); BOOST_REQUIRE_EQUAL(instance.count(), expected); BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(manager__allocate__non_empty_slab__expected) +BOOST_AUTO_TEST_CASE(body__allocate__non_empty_slab__expected) { constexpr auto expected = 42u; data_chunk buffer(to_half(expected), 0xff); test::chunk_storage file(buffer); - manager, key1, max_size_t> instance(file); + body, key1, max_size_t> instance(file); BOOST_REQUIRE_EQUAL(instance.allocate(to_half(expected)), to_half(expected)); BOOST_REQUIRE_EQUAL(instance.count(), expected); BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(manager__get__terminal_slab__terminal) +BOOST_AUTO_TEST_CASE(body__get__terminal_slab__terminal) { constexpr auto size = 14u; data_chunk buffer(size, 0xff); test::chunk_storage file(buffer); - const manager, key1, max_size_t> instance(file); + const body, key1, max_size_t> instance(file); BOOST_REQUIRE_EQUAL(instance.count(), size); BOOST_REQUIRE(!instance.get(linkage<2>::terminal)); BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(manager__get__slab__expected) +BOOST_AUTO_TEST_CASE(body__get__slab__expected) { constexpr auto size = 16u; data_chunk buffer @@ -179,26 +179,26 @@ BOOST_AUTO_TEST_CASE(manager__get__slab__expected) }; test::chunk_storage file(buffer); - const manager, key1, max_size_t> instance(file); + const body, key1, max_size_t> instance(file); BOOST_REQUIRE_EQUAL(instance.count(), size); - BOOST_REQUIRE_EQUAL(*instance.get(0)->begin(), 0x00_u8); - BOOST_REQUIRE_EQUAL(*instance.get(1)->begin(), 0x01_u8); - BOOST_REQUIRE_EQUAL(*instance.get(2)->begin(), 0x02_u8); - BOOST_REQUIRE_EQUAL(*instance.get(9)->begin(), 0x09_u8); + BOOST_REQUIRE_EQUAL(*instance.get(0).begin(), 0x00_u8); + BOOST_REQUIRE_EQUAL(*instance.get(1).begin(), 0x01_u8); + BOOST_REQUIRE_EQUAL(*instance.get(2).begin(), 0x02_u8); + BOOST_REQUIRE_EQUAL(*instance.get(9).begin(), 0x09_u8); BOOST_REQUIRE(!instance.get_fault()); } // records -BOOST_AUTO_TEST_CASE(manager__count__empty_record__zero) +BOOST_AUTO_TEST_CASE(body__count__empty_record__zero) { test::chunk_storage file; - const manager, key1, 42> instance(file); + const body, key1, 42> instance(file); BOOST_REQUIRE(is_zero(instance.count())); BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(manager__count__1_record__expected) +BOOST_AUTO_TEST_CASE(body__count__1_record__expected) { constexpr auto count = 1u; constexpr auto bytes = 5u; @@ -207,81 +207,81 @@ BOOST_AUTO_TEST_CASE(manager__count__1_record__expected) test::chunk_storage file(buffer); // Record sizing is record count-based (links are record counters). - const manager, key1, bytes> instance(file); + const body, key1, bytes> instance(file); BOOST_REQUIRE_EQUAL(instance.count(), 1u); BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(manager__count__33_record__expected) +BOOST_AUTO_TEST_CASE(body__count__33_record__expected) { constexpr auto count = 33u; constexpr auto bytes = 5u; constexpr auto expected = count * (sizeof(uint32_t) + bytes + array_count); data_chunk buffer(expected, 0xff); test::chunk_storage file(buffer); - const manager, key2, bytes> instance(file); + const body, key2, bytes> instance(file); BOOST_REQUIRE_EQUAL(instance.count(), 33u); BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(manager__truncate__terminal_record__false_unchanged) +BOOST_AUTO_TEST_CASE(body__truncate__terminal_record__false_unchanged) { data_chunk buffer{}; test::chunk_storage file(buffer); - manager, key0, 5u> instance(file); + body, key0, 5u> instance(file); BOOST_REQUIRE(!instance.truncate(linkage<2>::terminal)); BOOST_REQUIRE_EQUAL(instance.count(), zero); BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(manager__truncate__overflow_record__false_unchanged) +BOOST_AUTO_TEST_CASE(body__truncate__overflow_record__false_unchanged) { data_chunk buffer(7, 0xff); test::chunk_storage file(buffer); - manager, key0, 5u> instance(file); + body, key0, 5u> instance(file); BOOST_REQUIRE_EQUAL(instance.count(), 1u); BOOST_REQUIRE(!instance.truncate(2)); BOOST_REQUIRE_EQUAL(instance.count(), 1u); BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(manager__truncate__half_full_record__true_logical_size_changed) +BOOST_AUTO_TEST_CASE(body__truncate__half_full_record__true_logical_size_changed) { - constexpr auto body = 14u; - data_chunk buffer(body, 0xff); + constexpr auto bodie = 14u; + data_chunk buffer(bodie, 0xff); test::chunk_storage file(buffer); - manager, key0, 5u> instance(file); + body, key0, 5u> instance(file); BOOST_REQUIRE_EQUAL(instance.count(), 2u); BOOST_REQUIRE(instance.truncate(1)); BOOST_REQUIRE_EQUAL(instance.count(), 1u); - BOOST_REQUIRE_EQUAL(instance.capacity(), body); + BOOST_REQUIRE_EQUAL(instance.capacity(), bodie); // Can only truncate to logical limit. BOOST_REQUIRE(!instance.truncate(2)); BOOST_REQUIRE_EQUAL(instance.count(), 1u); - BOOST_REQUIRE_EQUAL(instance.capacity(), body); + BOOST_REQUIRE_EQUAL(instance.capacity(), bodie); BOOST_REQUIRE(instance.truncate(0)); BOOST_REQUIRE_EQUAL(instance.count(), 0u); - BOOST_REQUIRE_EQUAL(instance.capacity(), body); + BOOST_REQUIRE_EQUAL(instance.capacity(), bodie); BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(manager__allocate__terminal_empty_record__terminal_unchanged) +BOOST_AUTO_TEST_CASE(body__allocate__terminal_empty_record__terminal_unchanged) { data_chunk buffer{}; test::chunk_storage file(buffer); - manager, key0, 5u> instance(file); + body, key0, 5u> instance(file); BOOST_REQUIRE_EQUAL(instance.allocate(linkage<2>::terminal), linkage<2>::terminal); BOOST_REQUIRE_EQUAL(instance.count(), zero); BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(manager__allocate__terminal_non_empty_record__expected) +BOOST_AUTO_TEST_CASE(body__allocate__terminal_non_empty_record__expected) { data_chunk buffer(7, 0xff); test::chunk_storage file(buffer); - manager, key0, 5u> instance(file); + body, key0, 5u> instance(file); BOOST_REQUIRE_EQUAL(instance.allocate(1), 1u); BOOST_REQUIRE_EQUAL(instance.count(), 2u); BOOST_REQUIRE_EQUAL(instance.allocate(linkage<2>::terminal), linkage<2>::terminal); @@ -289,11 +289,11 @@ BOOST_AUTO_TEST_CASE(manager__allocate__terminal_non_empty_record__expected) BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(manager__allocate__empty_record__expected) +BOOST_AUTO_TEST_CASE(body__allocate__empty_record__expected) { data_chunk buffer{}; test::chunk_storage file(buffer); - manager, key0, 5u> instance(file); + body, key0, 5u> instance(file); BOOST_REQUIRE_EQUAL(instance.allocate(1), 0u); BOOST_REQUIRE_EQUAL(instance.count(), 1u); BOOST_REQUIRE_EQUAL(instance.allocate(2), 1u); @@ -301,11 +301,11 @@ BOOST_AUTO_TEST_CASE(manager__allocate__empty_record__expected) BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(manager__allocate__non_empty_record__expected) +BOOST_AUTO_TEST_CASE(body__allocate__non_empty_record__expected) { data_chunk buffer(7, 0xff); test::chunk_storage file(buffer); - manager, key0, 5u> instance(file); + body, key0, 5u> instance(file); BOOST_REQUIRE_EQUAL(instance.allocate(1), 1u); BOOST_REQUIRE_EQUAL(instance.count(), 2u); BOOST_REQUIRE_EQUAL(instance.allocate(2), 2u); @@ -313,20 +313,20 @@ BOOST_AUTO_TEST_CASE(manager__allocate__non_empty_record__expected) BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(manager__get__terminal_record__terminal) +BOOST_AUTO_TEST_CASE(body__get__terminal_record__terminal) { - constexpr auto body = 14u; + constexpr auto bodie = 14u; constexpr auto element = 5u; - data_chunk buffer(body, 0xff); + data_chunk buffer(bodie, 0xff); test::chunk_storage file(buffer); - const manager, key0, element> instance(file); + const body, key0, element> instance(file); BOOST_REQUIRE_EQUAL(instance.count(), 2u); - BOOST_REQUIRE_EQUAL(instance.get(1)->size(), (body - 1 * element)); + BOOST_REQUIRE_EQUAL(instance.get(1).size(), (bodie - 1 * element)); BOOST_REQUIRE(!instance.get(linkage<2>::terminal)); BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(manager__get__record__expected) +BOOST_AUTO_TEST_CASE(body__get__record__expected) { data_chunk buffer { @@ -335,32 +335,32 @@ BOOST_AUTO_TEST_CASE(manager__get__record__expected) }; constexpr auto element = 6u; - const auto body = buffer.size(); - const auto expected = to_signed(body - 1u * element); + const auto bodie = buffer.size(); + const auto expected = to_signed(bodie - 1u * element); test::chunk_storage file(buffer); - const manager, key0, element> instance(file); + const body, key0, element> instance(file); BOOST_REQUIRE_EQUAL(instance.count(), 2u); - BOOST_REQUIRE_EQUAL(instance.get(1)->size(), expected); - BOOST_REQUIRE_EQUAL(*instance.get(0)->begin(), 0x00_u8); - BOOST_REQUIRE_EQUAL(*instance.get(1)->begin(), 0x06_u8); + BOOST_REQUIRE_EQUAL(instance.get(1).size(), expected); + BOOST_REQUIRE_EQUAL(*instance.get(0).begin(), 0x00_u8); + BOOST_REQUIRE_EQUAL(*instance.get(1).begin(), 0x06_u8); BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(manager__get_capacity__terminal_record__terminal) +BOOST_AUTO_TEST_CASE(body__get_capacity__terminal_record__terminal) { - constexpr auto body = 14u; + constexpr auto bodie = 14u; constexpr auto element = 5u; - constexpr auto expected = to_signed(body - 1u * element); - data_chunk buffer(body, 0xff); + constexpr auto expected = to_signed(bodie - 1u * element); + data_chunk buffer(bodie, 0xff); test::chunk_storage file(buffer); - const manager, key0, element> instance(file); + const body, key0, element> instance(file); BOOST_REQUIRE_EQUAL(instance.count(), 2u); - BOOST_REQUIRE_EQUAL(instance.get(1)->size(), expected); + BOOST_REQUIRE_EQUAL(instance.get(1).size(), expected); BOOST_REQUIRE(!instance.get_capacity(linkage<2>::terminal)); BOOST_REQUIRE(!instance.get_fault()); } -BOOST_AUTO_TEST_CASE(manager__get_capacity__record__expected) +BOOST_AUTO_TEST_CASE(body__get_capacity__record__expected) { data_chunk buffer { @@ -369,14 +369,14 @@ BOOST_AUTO_TEST_CASE(manager__get_capacity__record__expected) }; constexpr auto element = 6u; - const auto body = buffer.size(); - const auto expected = to_signed(body - 1u * element); + const auto bodie = buffer.size(); + const auto expected = to_signed(bodie - 1u * element); test::chunk_storage file(buffer); - manager, key0, element> instance(file); + body, key0, element> instance(file); BOOST_REQUIRE_EQUAL(instance.count(), 2u); - BOOST_REQUIRE_EQUAL(instance.get(1)->size(), expected); - BOOST_REQUIRE_EQUAL(*instance.get_capacity(0)->begin(), 0x00_u8); - BOOST_REQUIRE_EQUAL(*instance.get_capacity(1)->begin(), 0x06_u8); + BOOST_REQUIRE_EQUAL(instance.get(1).size(), expected); + BOOST_REQUIRE_EQUAL(*instance.get_capacity(0).begin(), 0x00_u8); + BOOST_REQUIRE_EQUAL(*instance.get_capacity(1).begin(), 0x06_u8); BOOST_REQUIRE(!instance.get_fault()); } diff --git a/test/primitives/hashhead.cpp b/test/primitives/hashhead.cpp index 80feba828..f147405b2 100644 --- a/test/primitives/hashhead.cpp +++ b/test/primitives/hashhead.cpp @@ -48,9 +48,9 @@ class nullptr_storage public: using chunk_storages::chunk_storages; - memory_ptr get(size_t size) const NOEXCEPT override + memory get(size_t size) const NOEXCEPT override { - return is_zero(size) ? chunk_storages::get(size) : nullptr; + return is_zero(size) ? chunk_storages::get(size) : memory{}; } }; diff --git a/test/primitives/iterator.cpp b/test/primitives/iterator.cpp index 10143f2dc..3752d9b88 100644 --- a/test/primitives/iterator.cpp +++ b/test/primitives/iterator.cpp @@ -101,7 +101,7 @@ BOOST_AUTO_TEST_CASE(iterator__advance__slab__expected) slab_iterate iterator{ file.get(), start, key2 }; BOOST_REQUIRE(iterator); BOOST_REQUIRE_EQUAL(iterator.get(), 0x00u); - BOOST_REQUIRE(iterator++); + BOOST_REQUIRE(++iterator); BOOST_REQUIRE(iterator); BOOST_REQUIRE_EQUAL(iterator.get(), 0x03u); BOOST_REQUIRE(!iterator.advance()); diff --git a/test/primitives/nohead.cpp b/test/primitives/nohead.cpp index 671f4e0a2..da35b3958 100644 --- a/test/primitives/nohead.cpp +++ b/test/primitives/nohead.cpp @@ -37,17 +37,18 @@ static_assert(buckets == 0u); using link = linkage; using test_header = nohead; -class nullptr_storage - : public test::chunk_storages -{ -public: - using chunk_storages::chunk_storages; - - memory_ptr get(size_t size) const NOEXCEPT override - { - return is_zero(size) ? chunk_storages::get(size) : nullptr; - } -}; +// TODO: see hashhead. +////class nullptr_storage +//// : public test::chunk_storages +////{ +////public: +//// using chunk_storages::chunk_storages; +//// +//// memory get(size_t size) const NOEXCEPT override +//// { +//// return is_zero(size) ? chunk_storages::get(size) : memory{}; +//// } +////}; BOOST_AUTO_TEST_CASE(nohead__create__size__expected) { diff --git a/test/tables/optional/filter_bk.cpp b/test/tables/optional/filter_bk.cpp index 01b2a4649..8bbb0ffbc 100644 --- a/test/tables/optional/filter_bk.cpp +++ b/test/tables/optional/filter_bk.cpp @@ -91,24 +91,24 @@ BOOST_AUTO_TEST_CASE(filter_bk__put__ordered__expected) // Logical order is unaffected by put order. table::filter_bk::get_head get0{}; - table::filter_bk::get_head get1{}; + table::filter_bk::get_head get{}; table::filter_bk::get_head get2{}; table::filter_bk::get_head get3{}; table::filter_bk::get_head get4{}; BOOST_REQUIRE(instance.at(0, get0)); - BOOST_REQUIRE(instance.at(1, get1)); + BOOST_REQUIRE(instance.at(1, get)); BOOST_REQUIRE(instance.at(2, get2)); BOOST_REQUIRE(instance.at(3, get3)); BOOST_REQUIRE(instance.at(4, get4)); BOOST_REQUIRE_EQUAL(get0.hash, null_hash); - BOOST_REQUIRE_EQUAL(get1.hash, one_hash); + BOOST_REQUIRE_EQUAL(get.hash, one_hash); BOOST_REQUIRE_EQUAL(get2.hash, two_hash); BOOST_REQUIRE_EQUAL(get3.hash, three_hash); BOOST_REQUIRE_EQUAL(get4.hash, four_hash); BOOST_REQUIRE_EQUAL(get0.head, null_hash); - BOOST_REQUIRE_EQUAL(get1.head, five_hash); + BOOST_REQUIRE_EQUAL(get.head, five_hash); BOOST_REQUIRE_EQUAL(get2.head, six_hash); BOOST_REQUIRE_EQUAL(get3.head, seven_hash); BOOST_REQUIRE_EQUAL(get4.head, eight_hash); @@ -182,24 +182,24 @@ BOOST_AUTO_TEST_CASE(filter_bk__put__disordered__expected) // Logical order is unaffected by put order. table::filter_bk::get_head get0{}; - table::filter_bk::get_head get1{}; + table::filter_bk::get_head get{}; table::filter_bk::get_head get2{}; table::filter_bk::get_head get3{}; table::filter_bk::get_head get4{}; BOOST_REQUIRE(instance.at(0, get0)); - BOOST_REQUIRE(instance.at(1, get1)); + BOOST_REQUIRE(instance.at(1, get)); BOOST_REQUIRE(instance.at(2, get2)); BOOST_REQUIRE(instance.at(3, get3)); BOOST_REQUIRE(instance.at(4, get4)); BOOST_REQUIRE_EQUAL(get0.hash, null_hash); - BOOST_REQUIRE_EQUAL(get1.hash, one_hash); + BOOST_REQUIRE_EQUAL(get.hash, one_hash); BOOST_REQUIRE_EQUAL(get2.hash, two_hash); BOOST_REQUIRE_EQUAL(get3.hash, three_hash); BOOST_REQUIRE_EQUAL(get4.hash, four_hash); BOOST_REQUIRE_EQUAL(get0.head, null_hash); - BOOST_REQUIRE_EQUAL(get1.head, five_hash); + BOOST_REQUIRE_EQUAL(get.head, five_hash); BOOST_REQUIRE_EQUAL(get2.head, six_hash); BOOST_REQUIRE_EQUAL(get3.head, seven_hash); BOOST_REQUIRE_EQUAL(get4.head, eight_hash); diff --git a/test/tables/optional/filter_tx.cpp b/test/tables/optional/filter_tx.cpp index 71d033d1a..6b7ee11d3 100644 --- a/test/tables/optional/filter_tx.cpp +++ b/test/tables/optional/filter_tx.cpp @@ -89,17 +89,17 @@ BOOST_AUTO_TEST_CASE(filter_tx__put__ordered__expected) // Logical order is unaffected by put order. table::filter_tx::get_filter get0{}; - table::filter_tx::get_filter get1{}; + table::filter_tx::get_filter get{}; table::filter_tx::get_filter get2{}; table::filter_tx::get_filter get3{}; table::filter_tx::get_filter get4{}; BOOST_REQUIRE(instance.at(0, get0)); - BOOST_REQUIRE(instance.at(1, get1)); + BOOST_REQUIRE(instance.at(1, get)); BOOST_REQUIRE(instance.at(2, get2)); BOOST_REQUIRE(instance.at(3, get3)); BOOST_REQUIRE(instance.at(4, get4)); BOOST_REQUIRE_EQUAL(get0.filter, zero_data); - BOOST_REQUIRE_EQUAL(get1.filter, one_data); + BOOST_REQUIRE_EQUAL(get.filter, one_data); BOOST_REQUIRE_EQUAL(get2.filter, two_data); BOOST_REQUIRE_EQUAL(get3.filter, three_data); BOOST_REQUIRE_EQUAL(get4.filter, four_data); @@ -171,17 +171,17 @@ BOOST_AUTO_TEST_CASE(filter_tx__put__disordered__expected) // Logical order is unaffected by put order. table::filter_tx::get_filter get0{}; - table::filter_tx::get_filter get1{}; + table::filter_tx::get_filter get{}; table::filter_tx::get_filter get2{}; table::filter_tx::get_filter get3{}; table::filter_tx::get_filter get4{}; BOOST_REQUIRE(instance.at(0, get0)); - BOOST_REQUIRE(instance.at(1, get1)); + BOOST_REQUIRE(instance.at(1, get)); BOOST_REQUIRE(instance.at(2, get2)); BOOST_REQUIRE(instance.at(3, get3)); BOOST_REQUIRE(instance.at(4, get4)); BOOST_REQUIRE_EQUAL(get0.filter, zero_data); - BOOST_REQUIRE_EQUAL(get1.filter, one_data); + BOOST_REQUIRE_EQUAL(get.filter, one_data); BOOST_REQUIRE_EQUAL(get2.filter, two_data); BOOST_REQUIRE_EQUAL(get3.filter, three_data); BOOST_REQUIRE_EQUAL(get4.filter, four_data);