small optimizations and os backend refactor

This commit is contained in:
Green Sky 2025-01-18 01:44:46 +01:00
parent a9ebaa2c2f
commit db73c90e34
No known key found for this signature in database
4 changed files with 12 additions and 9 deletions

View File

@ -25,7 +25,7 @@ bool RecvSequenceBuffer::canPop(void) const {
std::vector<uint8_t> 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;

View File

@ -28,7 +28,7 @@ struct SHA1MappedFilesystem_InfoBuilderState {
SHA1MappedFilesystem::SHA1MappedFilesystem(
ObjectStore2& os
) : StorageBackendI::StorageBackendI(os), _ibs(std::make_unique<SHA1MappedFilesystem_InfoBuilderState>()) {
) : _os(os), _ibs(std::make_unique<SHA1MappedFilesystem_InfoBuilderState>()) {
}
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<ObjComp::Ephemeral::Backend>(this);
o.emplace<ObjComp::Ephemeral::BackendMeta>(this);
o.emplace<ObjComp::Ephemeral::BackendFile2>(this);
o.emplace<ObjComp::ID>(std::vector<uint8_t>{id});
//o.emplace<ObjComp::Ephemeral::FilePath>(object_file_path.generic_u8string());

View File

@ -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<SHA1MappedFilesystem_InfoBuilderState> _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

View File

@ -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 <iostream>
#include <filesystem>
@ -168,7 +169,7 @@ File2I* SHA1_NGCFT1::objGetFile2Write(ObjectHandle o) {
auto* file2_comp_ptr = o.try_get<Components::FT1File2>();
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<Components::FT1File2>();
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<Components::SuspectedParticipants>()) {
std::cout << "accepted ft has " << e.e.get<Components::SuspectedParticipants>().participants.size() << " sp\n";
std::cout << "SHA1_NGCFT1: accepted ft has " << e.e.get<Components::SuspectedParticipants>().participants.size() << " sp\n";
for (const auto cv : e.e.get<Components::SuspectedParticipants>().participants) {
_cr.emplace_or_replace<ChunkPickerUpdateTag>(cv);
}