forked from Green-Sky/tomato
some more backend interface changes i realized i had to do
This commit is contained in:
parent
10b689ca95
commit
73180195fe
@ -42,13 +42,17 @@ static ByteSpan spanFromRead(const std::variant<ByteSpan, std::vector<uint8_t>>&
|
|||||||
|
|
||||||
namespace backend {
|
namespace backend {
|
||||||
|
|
||||||
FilesystemStorage::FilesystemStorage(ObjectStore2& os, std::string_view storage_path) : StorageBackendI::StorageBackendI(os), _storage_path(storage_path) {
|
FilesystemStorage::FilesystemStorage(
|
||||||
|
ObjectStore2& os,
|
||||||
|
std::string_view storage_path,
|
||||||
|
MetaFileType mft_new
|
||||||
|
) : StorageBackendI::StorageBackendI(os), _storage_path(storage_path), _mft_new(mft_new) {
|
||||||
}
|
}
|
||||||
|
|
||||||
FilesystemStorage::~FilesystemStorage(void) {
|
FilesystemStorage::~FilesystemStorage(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjectHandle FilesystemStorage::newObject(MetaFileType mft, ByteSpan id) {
|
ObjectHandle FilesystemStorage::newObject(ByteSpan id) {
|
||||||
{ // first check if id is already used (TODO: solve the multi obj/backend problem)
|
{ // first check if id is already used (TODO: solve the multi obj/backend problem)
|
||||||
auto exising_oh = _os.getOneObjectByID(id);
|
auto exising_oh = _os.getOneObjectByID(id);
|
||||||
if (static_cast<bool>(exising_oh)) {
|
if (static_cast<bool>(exising_oh)) {
|
||||||
@ -85,7 +89,7 @@ ObjectHandle FilesystemStorage::newObject(MetaFileType mft, ByteSpan id) {
|
|||||||
oh.emplace<ObjComp::Ephemeral::Backend>(this);
|
oh.emplace<ObjComp::Ephemeral::Backend>(this);
|
||||||
oh.emplace<ObjComp::ID>(std::vector<uint8_t>{id});
|
oh.emplace<ObjComp::ID>(std::vector<uint8_t>{id});
|
||||||
oh.emplace<ObjComp::Ephemeral::FilePath>(object_file_path.generic_u8string());
|
oh.emplace<ObjComp::Ephemeral::FilePath>(object_file_path.generic_u8string());
|
||||||
oh.emplace<ObjComp::Ephemeral::MetaFileType>(mft);
|
oh.emplace<ObjComp::Ephemeral::MetaFileType>(_mft_new);
|
||||||
|
|
||||||
// meta needs to be synced to file
|
// meta needs to be synced to file
|
||||||
std::function<write_to_storage_fetch_data_cb> empty_data_cb = [](auto*, auto) -> uint64_t { return 0; };
|
std::function<write_to_storage_fetch_data_cb> empty_data_cb = [](auto*, auto) -> uint64_t { return 0; };
|
||||||
|
@ -3,17 +3,26 @@
|
|||||||
#include "../types.hpp"
|
#include "../types.hpp"
|
||||||
#include "../object_store.hpp"
|
#include "../object_store.hpp"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace backend {
|
namespace backend {
|
||||||
|
|
||||||
struct FilesystemStorage : public StorageBackendI {
|
struct FilesystemStorage : public StorageBackendI {
|
||||||
FilesystemStorage(ObjectStore2& os, std::string_view storage_path = "test_obj_store");
|
FilesystemStorage(
|
||||||
|
ObjectStore2& os,
|
||||||
|
std::string_view storage_path = "test_obj_store",
|
||||||
|
MetaFileType mft_new = MetaFileType::BINARY_MSGPACK
|
||||||
|
);
|
||||||
~FilesystemStorage(void);
|
~FilesystemStorage(void);
|
||||||
|
|
||||||
// TODO: fix the path for this specific fs?
|
// TODO: fix the path for this specific fs?
|
||||||
// for now we assume a single storage path per backend (there can be multiple per type)
|
// for now we assume a single storage path per backend (there can be multiple per type)
|
||||||
std::string _storage_path;
|
std::string _storage_path;
|
||||||
|
|
||||||
ObjectHandle newObject(MetaFileType mft, ByteSpan id);
|
// meta file type for new objects
|
||||||
|
MetaFileType _mft_new {MetaFileType::BINARY_MSGPACK};
|
||||||
|
|
||||||
|
ObjectHandle newObject(ByteSpan id) override;
|
||||||
|
|
||||||
bool write(Object o, std::function<write_to_storage_fetch_data_cb>& data_cb) override;
|
bool write(Object o, std::function<write_to_storage_fetch_data_cb>& data_cb) override;
|
||||||
bool read(Object o, std::function<read_from_storage_put_data_cb>& data_cb) override;
|
bool read(Object o, std::function<read_from_storage_put_data_cb>& data_cb) override;
|
||||||
|
@ -85,7 +85,8 @@ int main(int argc, const char** argv) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto oh = _fsb_dst.newObject(e.e.get<ObjComp::Ephemeral::MetaFileType>().type, ByteSpan{e.e.get<ObjComp::ID>().v});
|
// we dont copy meta file type, it will be the same for all "new" objects
|
||||||
|
auto oh = _fsb_dst.newObject(ByteSpan{e.e.get<ObjComp::ID>().v});
|
||||||
|
|
||||||
if (!static_cast<bool>(oh)) {
|
if (!static_cast<bool>(oh)) {
|
||||||
// already exists
|
// already exists
|
||||||
|
@ -52,6 +52,11 @@ static bool deserl_json_data_comp_type(ObjectHandle oh, const nlohmann::json& in
|
|||||||
StorageBackendI::StorageBackendI(ObjectStore2& os) : _os(os) {
|
StorageBackendI::StorageBackendI(ObjectStore2& os) : _os(os) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ObjectHandle StorageBackendI::newObject(ByteSpan) {
|
||||||
|
//return {_os.registry(), entt::null};
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
bool StorageBackendI::write(Object o, const ByteSpan data) {
|
bool StorageBackendI::write(Object o, const ByteSpan data) {
|
||||||
std::function<write_to_storage_fetch_data_cb> fn_cb = [read = 0ull, data](uint8_t* request_buffer, uint64_t buffer_size) mutable -> uint64_t {
|
std::function<write_to_storage_fetch_data_cb> fn_cb = [read = 0ull, data](uint8_t* request_buffer, uint64_t buffer_size) mutable -> uint64_t {
|
||||||
uint64_t i = 0;
|
uint64_t i = 0;
|
||||||
|
@ -22,11 +22,13 @@ struct StorageBackendI {
|
|||||||
|
|
||||||
StorageBackendI(ObjectStore2& os);
|
StorageBackendI(ObjectStore2& os);
|
||||||
|
|
||||||
|
// default impl fails, acting like a read only store
|
||||||
|
virtual ObjectHandle newObject(ByteSpan id);
|
||||||
|
|
||||||
// ========== write object to storage ==========
|
// ========== write object to storage ==========
|
||||||
using write_to_storage_fetch_data_cb = uint64_t(uint8_t* request_buffer, uint64_t buffer_size);
|
using write_to_storage_fetch_data_cb = uint64_t(uint8_t* request_buffer, uint64_t buffer_size);
|
||||||
// calls data_cb with a buffer to be filled in, cb returns actual count of data. if returned < max, its the last buffer.
|
// calls data_cb with a buffer to be filled in, cb returns actual count of data. if returned < max, its the last buffer.
|
||||||
virtual bool write(Object o, std::function<write_to_storage_fetch_data_cb>& data_cb) = 0;
|
virtual bool write(Object o, std::function<write_to_storage_fetch_data_cb>& data_cb) = 0;
|
||||||
//virtual bool write(Object o, const uint8_t* data, const uint64_t data_size); // default impl
|
|
||||||
bool write(Object o, const ByteSpan data);
|
bool write(Object o, const ByteSpan data);
|
||||||
|
|
||||||
// ========== read object from storage ==========
|
// ========== read object from storage ==========
|
||||||
|
Loading…
Reference in New Issue
Block a user