From 9fe305c7d28e993e55c55427f377ae7e3251ea4f Mon Sep 17 00:00:00 2001 From: "Douglas B. Rumbaugh" Date: Fri, 6 Dec 2024 13:13:51 -0500 Subject: Interface update (#5) * Query Interface Adjustments/Refactoring Began the process of adjusting the query interface (and also the shard interface, to a lesser degree) to better accommodate the user. In particular the following changes have been made, 1. The number of necessary template arguments for the query type has been drastically reduced, while also removing the void pointers and manual delete functions from the interface. This was accomplished by requiring many of the sub-types associated with a query (parameters, etc.) to be nested inside the main query class, and by forcing the SHARD type to expose its associated record type. 2. User-defined query return types are now supported. Queries no longer are required to return strictly sets of records. Instead, the query now has LocalResultType and ResultType template parameters (which can be defaulted using a typedef in the Query type itself), allowing much more flexibility. Note that, at least for the short term, the LocalResultType must still expose the same is_deleted/is_tombstone interface as a Wrapped used to, as this is currently needed for delete filtering. A better approach to this is, hopefully, forthcoming. 3. Updated the ISAMTree.h shard and rangequery.h query to use the new interfaces, and adjusted the associated unit tests as well. 4. Dropped the unnecessary "get_data()" function from the ShardInterface concept. 5. Dropped the need to specify a record type in the ShardInterface concept. This is now handled using a required Shard::RECORD member of the Shard class itself, which should expose the name of the record type. * Updates to framework to support new Query/Shard interfaces Pretty extensive adjustments to the framework, particularly to the templates themselves, along with some type-renaming work, to support the new query and shard interfaces. Adjusted the external query interface to take an rvalue reference, rather than a pointer, to the query parameters. * Removed framework-level delete filtering This was causing some issues with the new query interface, and should probably be reworked anyway, so I'm temporarily (TM) removing the feature. * Updated benchmarks + remaining code for new interface --- include/framework/structure/BufferView.h | 258 +++++++++++++++---------------- 1 file changed, 121 insertions(+), 137 deletions(-) (limited to 'include/framework/structure/BufferView.h') diff --git a/include/framework/structure/BufferView.h b/include/framework/structure/BufferView.h index e95a799..acf1201 100644 --- a/include/framework/structure/BufferView.h +++ b/include/framework/structure/BufferView.h @@ -1,7 +1,7 @@ /* * include/framework/structure/BufferView.h * - * Copyright (C) 2023 Douglas B. Rumbaugh + * Copyright (C) 2023-2024 Douglas B. Rumbaugh * * Distributed under the Modified BSD License. * @@ -9,166 +9,150 @@ */ #pragma once -#include #include +#include #include #include -#include "psu-util/alignment.h" -#include "psu-ds/BloomFilter.h" #include "framework/interface/Record.h" +#include "psu-ds/BloomFilter.h" +#include "psu-util/alignment.h" namespace de { -typedef std::function ReleaseFunction; +typedef std::function ReleaseFunction; -template -class BufferView { +template class BufferView { public: - BufferView() = default; - - /* - * the BufferView's lifetime is tightly linked to buffer versioning, and so - * copying and assignment are disabled. - */ - BufferView(const BufferView&) = delete; - BufferView &operator=(BufferView &) = delete; - - BufferView(BufferView &&other) - : m_data(std::exchange(other.m_data, nullptr)) - , m_release(std::move(other.m_release)) - , m_head(std::exchange(other.m_head, 0)) - , m_tail(std::exchange(other.m_tail, 0)) - , m_start(std::exchange(other.m_start, 0)) - , m_stop(std::exchange(other.m_stop, 0)) - , m_cap(std::exchange(other.m_cap, 0)) - , m_approx_ts_cnt(std::exchange(other.m_approx_ts_cnt, 0)) - , m_tombstone_filter(std::exchange(other.m_tombstone_filter, nullptr)) - , m_active(std::exchange(other.m_active, false)) {} - - BufferView &operator=(BufferView &&other) = delete; - - - BufferView(Wrapped *buffer, size_t cap, size_t head, size_t tail, size_t tombstone_cnt, psudb::BloomFilter *filter, - ReleaseFunction release) - : m_data(buffer) - , m_release(release) - , m_head(head) - , m_tail(tail) - , m_start(m_head % cap) - , m_stop(m_tail % cap) - , m_cap(cap) - , m_approx_ts_cnt(tombstone_cnt) - , m_tombstone_filter(filter) - , m_active(true) {} - - ~BufferView() { - if (m_active) { - m_release(); - } + BufferView() = default; + + /* + * the BufferView's lifetime is tightly linked to buffer versioning, so + * copying and assignment are disabled. + */ + BufferView(const BufferView &) = delete; + BufferView &operator=(BufferView &) = delete; + + BufferView(BufferView &&other) + : m_data(std::exchange(other.m_data, nullptr)), + m_release(std::move(other.m_release)), + m_head(std::exchange(other.m_head, 0)), + m_tail(std::exchange(other.m_tail, 0)), + m_start(std::exchange(other.m_start, 0)), + m_stop(std::exchange(other.m_stop, 0)), + m_cap(std::exchange(other.m_cap, 0)), + m_approx_ts_cnt(std::exchange(other.m_approx_ts_cnt, 0)), + m_tombstone_filter(std::exchange(other.m_tombstone_filter, nullptr)), + m_active(std::exchange(other.m_active, false)) {} + + BufferView &operator=(BufferView &&other) = delete; + + BufferView(Wrapped *buffer, size_t cap, size_t head, size_t tail, + size_t tombstone_cnt, psudb::BloomFilter *filter, + ReleaseFunction release) + : m_data(buffer), m_release(release), m_head(head), m_tail(tail), + m_start(m_head % cap), m_stop(m_tail % cap), m_cap(cap), + m_approx_ts_cnt(tombstone_cnt), m_tombstone_filter(filter), + m_active(true) {} + + ~BufferView() { + if (m_active) { + m_release(); } + } - bool check_tombstone(const R& rec) { - if (m_tombstone_filter && !m_tombstone_filter->lookup(rec)) return false; - - for (size_t i=0; ilookup(rec)) + return false; - return false; + for (size_t i = 0; i < get_record_count(); i++) { + if (m_data[to_idx(i)].rec == rec && m_data[to_idx(i)].is_tombstone()) { + return true; + } } - bool delete_record(const R& rec) { - if (m_start < m_stop) { - for (size_t i=m_start; i *get(size_t i) { - //assert(i < get_record_count()); - return m_data + to_idx(i); - } - - void copy_to_buffer(psudb::byte *buffer) { - /* check if the region to be copied circles back to start. If so, do it in two steps */ - if (m_start > m_stop) { - size_t split_idx = m_cap - m_start; - - memcpy(buffer, (std::byte*) (m_data + m_start), split_idx* sizeof(Wrapped)); - memcpy(buffer + (split_idx * sizeof(Wrapped)), (std::byte*) m_data, m_stop * sizeof(Wrapped)); - } else { - memcpy(buffer, (std::byte*) (m_data + m_start), get_record_count() * sizeof(Wrapped)); + for (size_t i = 0; i < m_stop; i++) { + if (m_data[i].rec == rec) { + m_data[i].set_delete(); + return true; } + } } - size_t get_tail() { - return m_tail; + return false; + } + + size_t get_record_count() { return m_tail - m_head; } + + size_t get_capacity() { return m_cap; } + + /* + * NOTE: This function returns an upper bound on the number + * of tombstones within the view. There may be less than + * this, due to synchronization issues during view creation. + */ + size_t get_tombstone_count() { return m_approx_ts_cnt; } + + Wrapped *get(size_t i) { + return m_data + to_idx(i); + } + + void copy_to_buffer(psudb::byte *buffer) { + /* check if the region to be copied circles back to start. If so, do it in + * two steps */ + if (m_start > m_stop) { + size_t split_idx = m_cap - m_start; + + memcpy(buffer, (std::byte *)(m_data + m_start), + split_idx * sizeof(Wrapped)); + memcpy(buffer + (split_idx * sizeof(Wrapped)), (std::byte *)m_data, + m_stop * sizeof(Wrapped)); + } else { + memcpy(buffer, (std::byte *)(m_data + m_start), + get_record_count() * sizeof(Wrapped)); } + } - size_t get_head() { - return m_head; - } + size_t get_tail() { return m_tail; } + + size_t get_head() { return m_head; } private: - Wrapped* m_data; - ReleaseFunction m_release; - size_t m_head; - size_t m_tail; - size_t m_start; - size_t m_stop; - size_t m_cap; - size_t m_approx_ts_cnt; - psudb::BloomFilter *m_tombstone_filter; - bool m_active; - - size_t to_idx(size_t i) { - size_t idx = (m_start + i >= m_cap) ? i - (m_cap - m_start) - : m_start + i; - assert(idx < m_cap); - return idx; - } + Wrapped *m_data; + ReleaseFunction m_release; + size_t m_head; + size_t m_tail; + size_t m_start; + size_t m_stop; + size_t m_cap; + size_t m_approx_ts_cnt; + psudb::BloomFilter *m_tombstone_filter; + bool m_active; + + size_t to_idx(size_t i) { + size_t idx = (m_start + i >= m_cap) ? i - (m_cap - m_start) : m_start + i; + assert(idx < m_cap); + return idx; + } }; -} +} // namespace de -- cgit v1.2.3