diff options
| author | Douglas B. Rumbaugh <dbr4@psu.edu> | 2024-12-06 13:13:51 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-06 18:13:51 +0000 |
| commit | 9fe305c7d28e993e55c55427f377ae7e3251ea4f (patch) | |
| tree | 384b687f64b84eb81bde2becac8a5f24916b07b4 /include/framework/scheduling/Epoch.h | |
| parent | 47916da2ba5ed5bee2dda3cbcc58d39e1e931bfc (diff) | |
| download | dynamic-extension-9fe305c7d28e993e55c55427f377ae7e3251ea4f.tar.gz | |
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<R> 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
Diffstat (limited to 'include/framework/scheduling/Epoch.h')
| -rw-r--r-- | include/framework/scheduling/Epoch.h | 209 |
1 files changed, 98 insertions, 111 deletions
diff --git a/include/framework/scheduling/Epoch.h b/include/framework/scheduling/Epoch.h index 9377fb0..03675b1 100644 --- a/include/framework/scheduling/Epoch.h +++ b/include/framework/scheduling/Epoch.h @@ -1,7 +1,7 @@ /* * include/framework/scheduling/Epoch.h * - * Copyright (C) 2023 Douglas B. Rumbaugh <drumbaugh@psu.edu> + * Copyright (C) 2023-2024 Douglas B. Rumbaugh <drumbaugh@psu.edu> * * Distributed under the Modified BSD License. * @@ -11,133 +11,120 @@ #include <condition_variable> #include <mutex> -#include "framework/structure/MutableBuffer.h" -#include "framework/structure/ExtensionStructure.h" #include "framework/structure/BufferView.h" +#include "framework/structure/ExtensionStructure.h" +#include "framework/structure/MutableBuffer.h" namespace de { - -template <RecordInterface R, ShardInterface<R> S, QueryInterface<R, S> Q, LayoutPolicy L> +template <ShardInterface ShardType, QueryInterface<ShardType> QueryType, + LayoutPolicy L> class Epoch { private: - typedef MutableBuffer<R> Buffer; - typedef ExtensionStructure<R, S, Q, L> Structure; - typedef BufferView<R> BufView; -public: - Epoch(size_t number=0) - : m_buffer(nullptr) - , m_structure(nullptr) - , m_active_merge(false) - , m_epoch_number(number) - , m_buffer_head(0) - {} - - Epoch(size_t number, Structure *structure, Buffer *buff, size_t head) - : m_buffer(buff) - , m_structure(structure) - , m_active_merge(false) - , m_epoch_number(number) - , m_buffer_head(head) - { - structure->take_reference(); - } - - ~Epoch() { - if (m_structure) { - m_structure->release_reference(); - } - - if (m_structure->get_reference_count() == 0) { - delete m_structure; - } + typedef typename ShardType::RECORD RecordType; + typedef MutableBuffer<RecordType> Buffer; + typedef ExtensionStructure<ShardType, QueryType, L> Structure; + typedef BufferView<RecordType> BufView; +public: + Epoch(size_t number = 0) + : m_buffer(nullptr), m_structure(nullptr), m_active_merge(false), + m_epoch_number(number), m_buffer_head(0) {} + + Epoch(size_t number, Structure *structure, Buffer *buff, size_t head) + : m_buffer(buff), m_structure(structure), m_active_merge(false), + m_epoch_number(number), m_buffer_head(head) { + structure->take_reference(); + } + + ~Epoch() { + if (m_structure) { + m_structure->release_reference(); } - /* - * Epochs are *not* copyable or movable. Only one can exist, and all users - * of it work with pointers - */ - Epoch(const Epoch&) = delete; - Epoch(Epoch&&) = delete; - Epoch &operator=(const Epoch&) = delete; - Epoch &operator=(Epoch&&) = delete; - - size_t get_epoch_number() { - return m_epoch_number; + if (m_structure->get_reference_count() == 0) { + delete m_structure; } - - Structure *get_structure() { - return m_structure; + } + + /* + * Epochs are *not* copyable or movable. Only one can exist, and all users + * of it work with pointers + */ + Epoch(const Epoch &) = delete; + Epoch(Epoch &&) = delete; + Epoch &operator=(const Epoch &) = delete; + Epoch &operator=(Epoch &&) = delete; + + size_t get_epoch_number() { return m_epoch_number; } + + Structure *get_structure() { return m_structure; } + + BufView get_buffer() { return m_buffer->get_buffer_view(m_buffer_head); } + + /* + * Returns a new Epoch object that is a copy of this one. The new object + * will also contain a copy of the m_structure, rather than a reference to + * the same one. The epoch number of the new epoch will be set to the + * provided argument. + */ + Epoch *clone(size_t number) { + std::unique_lock<std::mutex> m_buffer_lock; + auto epoch = new Epoch(number); + epoch->m_buffer = m_buffer; + epoch->m_buffer_head = m_buffer_head; + + if (m_structure) { + epoch->m_structure = m_structure->copy(); + /* the copy routine returns a structure with 0 references */ + epoch->m_structure->take_reference(); } - BufView get_buffer() { - return m_buffer->get_buffer_view(m_buffer_head); + return epoch; + } + + /* + * Check if a merge can be started from this Epoch. At present, without + * concurrent merging, this simply checks if there is currently a scheduled + * merge based on this Epoch. If there is, returns false. If there isn't, + * return true and set a flag indicating that there is an active merge. + */ + bool prepare_reconstruction() { + auto old = m_active_merge.load(); + if (old) { + return false; } - /* - * Returns a new Epoch object that is a copy of this one. The new object - * will also contain a copy of the m_structure, rather than a reference to - * the same one. The epoch number of the new epoch will be set to the - * provided argument. - */ - Epoch *clone(size_t number) { - std::unique_lock<std::mutex> m_buffer_lock; - auto epoch = new Epoch(number); - epoch->m_buffer = m_buffer; - epoch->m_buffer_head = m_buffer_head; - - if (m_structure) { - epoch->m_structure = m_structure->copy(); - /* the copy routine returns a structure with 0 references */ - epoch->m_structure->take_reference(); - } - - return epoch; + // FIXME: this needs cleaned up + while (!m_active_merge.compare_exchange_strong(old, true)) { + old = m_active_merge.load(); + if (old) { + return false; + } } - /* - * Check if a merge can be started from this Epoch. At present, without - * concurrent merging, this simply checks if there is currently a scheduled - * merge based on this Epoch. If there is, returns false. If there isn't, - * return true and set a flag indicating that there is an active merge. - */ - bool prepare_reconstruction() { - auto old = m_active_merge.load(); - if (old) { - return false; - } - - // FIXME: this needs cleaned up - while (!m_active_merge.compare_exchange_strong(old, true)) { - old = m_active_merge.load(); - if (old) { - return false; - } - } - - return true; - } + return true; + } - bool advance_buffer_head(size_t head) { - m_buffer_head = head; - return m_buffer->advance_head(m_buffer_head); - } + bool advance_buffer_head(size_t head) { + m_buffer_head = head; + return m_buffer->advance_head(m_buffer_head); + } private: - Structure *m_structure; - Buffer *m_buffer; - - std::mutex m_buffer_lock; - std::atomic<bool> m_active_merge; - - /* - * The number of currently active jobs - * (queries/merges) operating on this - * epoch. An epoch can only be retired - * when this number is 0. - */ - size_t m_epoch_number; - size_t m_buffer_head; + Buffer *m_buffer; + Structure *m_structure; + + std::mutex m_buffer_lock; + std::atomic<bool> m_active_merge; + + /* + * The number of currently active jobs + * (queries/merges) operating on this + * epoch. An epoch can only be retired + * when this number is 0. + */ + size_t m_epoch_number; + size_t m_buffer_head; }; -} +} // namespace de |