From 50db703d78ceaaef43c82e2e4198500d23e1de7e Mon Sep 17 00:00:00 2001 From: Green Sky Date: Sat, 18 Jan 2025 01:01:26 +0100 Subject: [PATCH] os backend refactor --- plugins/plugin_mfs_wip.cpp | 2 +- src/convert_frag_to_obj.cpp | 8 +++---- .../message_fragment_store.cpp | 21 ++++++++++++------- .../message_fragment_store.hpp | 6 ++++-- 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/plugins/plugin_mfs_wip.cpp b/plugins/plugin_mfs_wip.cpp index e120bf2..2ab024f 100644 --- a/plugins/plugin_mfs_wip.cpp +++ b/plugins/plugin_mfs_wip.cpp @@ -42,7 +42,7 @@ SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_start(struct SolanaAPI* solana_api) // static store, could be anywhere tho // construct with fetched dependencies g_fsb = std::make_unique(*os, "test2_message_store/"); // TODO: use config? - g_mfs = std::make_unique(*cr, *rmm, *os, *g_fsb, *msnj); + g_mfs = std::make_unique(*cr, *rmm, *os, *g_fsb, *g_fsb, *msnj); // register types PLUG_PROVIDE_INSTANCE(MessageFragmentStore, plugin_name, g_mfs.get()); diff --git a/src/convert_frag_to_obj.cpp b/src/convert_frag_to_obj.cpp index 420a9af..8401890 100644 --- a/src/convert_frag_to_obj.cpp +++ b/src/convert_frag_to_obj.cpp @@ -40,9 +40,9 @@ int main(int argc, const char** argv) { // they only exist for the serializers (for now) // TODO: version MessageSerializerNJ msnj_src{cr, os_src, {}, {}}; - MessageFragmentStore mfs_src(cr, rmm, os_src, fsb_src, msnj_src); + MessageFragmentStore mfs_src(cr, rmm, os_src, fsb_src, fsb_src, msnj_src); MessageSerializerNJ msnj_dst{cr, os_dst, {}, {}}; - MessageFragmentStore mfs_dst(cr, rmm, os_dst, fsb_dst, msnj_dst); + MessageFragmentStore mfs_dst(cr, rmm, os_dst, fsb_dst, fsb_dst, msnj_dst); // add message fragment store too (adds meta?) @@ -78,7 +78,7 @@ int main(int argc, const char** argv) { // technically we could just copy the file, but meh // read src and write dst data std::vector tmp_buffer; - std::function cb = [&tmp_buffer](const ByteSpan buffer) { + std::function cb = [&tmp_buffer](const ByteSpan buffer) { tmp_buffer.insert(tmp_buffer.end(), buffer.cbegin(), buffer.cend()); }; if (!_fsb_src.read(e.e, cb)) { @@ -140,7 +140,7 @@ int main(int argc, const char** argv) { } } - static_cast(_fsb_dst).write(oh, ByteSpan{tmp_buffer}); + static_cast(_fsb_dst).write(oh, ByteSpan{tmp_buffer}); //assert(std::filesystem::file_size(e.e.get().path) == std::filesystem::file_size(oh.get().path)); diff --git a/src/solanaceae/message_fragment_store/message_fragment_store.cpp b/src/solanaceae/message_fragment_store/message_fragment_store.cpp index 242b667..c2e1a43 100644 --- a/src/solanaceae/message_fragment_store/message_fragment_store.cpp +++ b/src/solanaceae/message_fragment_store/message_fragment_store.cpp @@ -1,6 +1,8 @@ #include "./message_fragment_store.hpp" #include "./internal_mfs_contexts.hpp" +#include "solanaceae/object_store/meta_components.hpp" +#include "solanaceae/object_store/object_store.hpp" #include @@ -41,12 +43,12 @@ namespace ObjectStore::Components { } // ObjectStore::Component static nlohmann::json loadFromStorageNJ(ObjectHandle oh) { - assert(oh.all_of()); - auto* backend = oh.get().ptr; + assert(oh.all_of()); + auto* backend = oh.get().ptr; assert(backend != nullptr); std::vector tmp_buffer; - std::function cb = [&tmp_buffer](const ByteSpan buffer) { + std::function cb = [&tmp_buffer](const ByteSpan buffer) { tmp_buffer.insert(tmp_buffer.end(), buffer.cbegin(), buffer.cend()); }; if (!backend->read(oh, cb)) { @@ -184,7 +186,9 @@ void MessageFragmentStore::handleMessage(const Message3Handle& m) { if (!_os.registry().valid(fragment_id)) { const auto new_uuid = _session_uuid_gen(); _fs_ignore_event = true; - auto fh = _sb.newObject(ByteSpan{new_uuid}); + auto fh = _sbm.newObject(ByteSpan{new_uuid}); + // TODO: the backend should have done that? + fh.emplace_or_replace(&_sba); _fs_ignore_event = false; if (!static_cast(fh)) { std::cout << "MFS error: failed to create new object for message\n"; @@ -482,8 +486,8 @@ bool MessageFragmentStore::syncFragToStorage(ObjectHandle fh, Message3Registry& std::cerr << "MFS error: unknown object version\n"; assert(false); } - assert(fh.all_of()); - auto* backend = fh.get().ptr; + assert(fh.all_of()); + auto* backend = fh.get().ptr; if (backend->write(fh, {reinterpret_cast(data_to_save.data()), data_to_save.size()})) { // TODO: make this better, should this be called on fail? should this be called before sync? (prob not) _fs_ignore_event = true; @@ -503,9 +507,10 @@ MessageFragmentStore::MessageFragmentStore( Contact3Registry& cr, RegistryMessageModelI& rmm, ObjectStore2& os, - StorageBackendI& sb, + StorageBackendIMeta& sbm, + StorageBackendIAtomic& sba, MessageSerializerNJ& scnj -) : _cr(cr), _rmm(rmm), _rmm_sr(_rmm.newSubRef(this)), _os(os), _os_sr(_os.newSubRef(this)), _sb(sb), _scnj(scnj) { +) : _cr(cr), _rmm(rmm), _rmm_sr(_rmm.newSubRef(this)), _os(os), _os_sr(_os.newSubRef(this)), _sbm(sbm), _sba(sba), _scnj(scnj) { _rmm_sr .subscribe(RegistryMessageModel_Event::message_construct) .subscribe(RegistryMessageModel_Event::message_updated) diff --git a/src/solanaceae/message_fragment_store/message_fragment_store.hpp b/src/solanaceae/message_fragment_store/message_fragment_store.hpp index 68411ee..f883920 100644 --- a/src/solanaceae/message_fragment_store/message_fragment_store.hpp +++ b/src/solanaceae/message_fragment_store/message_fragment_store.hpp @@ -55,7 +55,8 @@ class MessageFragmentStore : public RegistryMessageModelEventI, public ObjectSto RegistryMessageModelI::SubscriptionReference _rmm_sr; ObjectStore2& _os; ObjectStore2::SubscriptionReference _os_sr; - StorageBackendI& _sb; + StorageBackendIMeta& _sbm; + StorageBackendIAtomic& _sba; MessageSerializerNJ& _scnj; bool _fs_ignore_event {false}; @@ -94,7 +95,8 @@ class MessageFragmentStore : public RegistryMessageModelEventI, public ObjectSto Contact3Registry& cr, RegistryMessageModelI& rmm, ObjectStore2& os, - StorageBackendI& sb, + StorageBackendIMeta& sbm, + StorageBackendIAtomic& sba, MessageSerializerNJ& scnj ); virtual ~MessageFragmentStore(void);