From db73c90e34be09847e5b90d79ae958341680c463 Mon Sep 17 00:00:00 2001 From: Green Sky Date: Sat, 18 Jan 2025 01:44:46 +0100 Subject: [PATCH] small optimizations and os backend refactor --- solanaceae/ngc_ft1/rcv_buf.cpp | 2 +- .../ngc_ft1_sha1/backends/sha1_mapped_filesystem.cpp | 7 ++++--- .../ngc_ft1_sha1/backends/sha1_mapped_filesystem.hpp | 5 +++-- solanaceae/ngc_ft1_sha1/sha1_ngcft1.cpp | 7 ++++--- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/solanaceae/ngc_ft1/rcv_buf.cpp b/solanaceae/ngc_ft1/rcv_buf.cpp index 21fc336..b87228b 100644 --- a/solanaceae/ngc_ft1/rcv_buf.cpp +++ b/solanaceae/ngc_ft1/rcv_buf.cpp @@ -25,7 +25,7 @@ bool RecvSequenceBuffer::canPop(void) const { std::vector RecvSequenceBuffer::pop(void) { assert(canPop()); - auto tmp_data = entries.at(next_seq_id).data; + auto tmp_data = std::move(entries.at(next_seq_id).data); erase(next_seq_id); next_seq_id++; return tmp_data; diff --git a/solanaceae/ngc_ft1_sha1/backends/sha1_mapped_filesystem.cpp b/solanaceae/ngc_ft1_sha1/backends/sha1_mapped_filesystem.cpp index a14a4df..f354664 100644 --- a/solanaceae/ngc_ft1_sha1/backends/sha1_mapped_filesystem.cpp +++ b/solanaceae/ngc_ft1_sha1/backends/sha1_mapped_filesystem.cpp @@ -28,7 +28,7 @@ struct SHA1MappedFilesystem_InfoBuilderState { SHA1MappedFilesystem::SHA1MappedFilesystem( ObjectStore2& os -) : StorageBackendI::StorageBackendI(os), _ibs(std::make_unique()) { +) : _os(os), _ibs(std::make_unique()) { } SHA1MappedFilesystem::~SHA1MappedFilesystem(void) { @@ -46,10 +46,11 @@ void SHA1MappedFilesystem::tick(void) { } } -ObjectHandle SHA1MappedFilesystem::newObject(ByteSpan id) { +ObjectHandle SHA1MappedFilesystem::newObject(ByteSpan id, bool throw_construct) { ObjectHandle o{_os.registry(), _os.registry().create()}; - o.emplace(this); + o.emplace(this); + o.emplace(this); o.emplace(std::vector{id}); //o.emplace(object_file_path.generic_u8string()); diff --git a/solanaceae/ngc_ft1_sha1/backends/sha1_mapped_filesystem.hpp b/solanaceae/ngc_ft1_sha1/backends/sha1_mapped_filesystem.hpp index d2db2df..67cc975 100644 --- a/solanaceae/ngc_ft1_sha1/backends/sha1_mapped_filesystem.hpp +++ b/solanaceae/ngc_ft1_sha1/backends/sha1_mapped_filesystem.hpp @@ -11,7 +11,8 @@ namespace Backends { // fwd to hide the threading headers struct SHA1MappedFilesystem_InfoBuilderState; -struct SHA1MappedFilesystem : public StorageBackendI { +struct SHA1MappedFilesystem : public StorageBackendIMeta, public StorageBackendIFile2 { + ObjectStore2& _os; std::unique_ptr _ibs; SHA1MappedFilesystem( @@ -23,7 +24,7 @@ struct SHA1MappedFilesystem : public StorageBackendI { // call from main thread (os thread?) often void tick(void); - ObjectHandle newObject(ByteSpan id) override; + ObjectHandle newObject(ByteSpan id, bool throw_construct = true) override; // performs async file hashing // create message in cb diff --git a/solanaceae/ngc_ft1_sha1/sha1_ngcft1.cpp b/solanaceae/ngc_ft1_sha1/sha1_ngcft1.cpp index 431bb11..2d3c940 100644 --- a/solanaceae/ngc_ft1_sha1/sha1_ngcft1.cpp +++ b/solanaceae/ngc_ft1_sha1/sha1_ngcft1.cpp @@ -28,6 +28,7 @@ #include "./re_announce_systems.hpp" #include "./chunk_picker_systems.hpp" #include "./transfer_stats_systems.hpp" +#include "solanaceae/object_store/object_store.hpp" #include #include @@ -168,7 +169,7 @@ File2I* SHA1_NGCFT1::objGetFile2Write(ObjectHandle o) { auto* file2_comp_ptr = o.try_get(); if (file2_comp_ptr == nullptr || !file2_comp_ptr->file || !file2_comp_ptr->file->can_write || !file2_comp_ptr->file->isGood()) { // (re)request file2 from backend - auto new_file = _mfb.file2(o, StorageBackendI::FILE2_WRITE); + auto new_file = _mfb.file2(o, StorageBackendIFile2::FILE2_WRITE); if (!new_file || !new_file->can_write || !new_file->isGood()) { std::cerr << "SHA1_NGCFT1 error: failed to open object for writing\n"; return nullptr; // early out @@ -185,7 +186,7 @@ File2I* SHA1_NGCFT1::objGetFile2Read(ObjectHandle o) { auto* file2_comp_ptr = o.try_get(); if (file2_comp_ptr == nullptr || !file2_comp_ptr->file || !file2_comp_ptr->file->can_read || !file2_comp_ptr->file->isGood()) { // (re)request file2 from backend - auto new_file = _mfb.file2(o, StorageBackendI::FILE2_READ); + auto new_file = _mfb.file2(o, StorageBackendIFile2::FILE2_READ); if (!new_file || !new_file->can_read || !new_file->isGood()) { std::cerr << "SHA1_NGCFT1 error: failed to open object for reading\n"; return nullptr; // early out @@ -744,7 +745,7 @@ bool SHA1_NGCFT1::onEvent(const ObjectStore::Events::ObjectUpdate& e) { // start requesting from all participants if (e.e.all_of()) { - std::cout << "accepted ft has " << e.e.get().participants.size() << " sp\n"; + std::cout << "SHA1_NGCFT1: accepted ft has " << e.e.get().participants.size() << " sp\n"; for (const auto cv : e.e.get().participants) { _cr.emplace_or_replace(cv); }