rename fs atomic impl and add simple testcase

pre refactor
This commit is contained in:
Green Sky
2025-04-30 16:10:56 +02:00
parent 738e1a2071
commit 889761f538
6 changed files with 102 additions and 15 deletions

View File

@@ -40,8 +40,8 @@ target_link_libraries(solanaceae_file2_zstd PUBLIC
add_library(solanaceae_object_store_backend_filesystem
./solanaceae/object_store/backends/file2_stack.hpp
./solanaceae/object_store/backends/file2_stack.cpp
./solanaceae/object_store/backends/filesystem_storage.hpp
./solanaceae/object_store/backends/filesystem_storage.cpp
./solanaceae/object_store/backends/filesystem_storage_atomic.hpp
./solanaceae/object_store/backends/filesystem_storage_atomic.cpp
)
target_include_directories(solanaceae_object_store_backend_filesystem PUBLIC .)

View File

@@ -1,4 +1,4 @@
#include "./filesystem_storage.hpp"
#include "./filesystem_storage_atomic.hpp"
#include <solanaceae/object_store/meta_components.hpp>
#include <solanaceae/object_store/serializer_json.hpp>
@@ -29,17 +29,17 @@ static const char* metaFileTypeSuffix(MetaFileType mft) {
namespace Backends {
FilesystemStorage::FilesystemStorage(
FilesystemStorageAtomic::FilesystemStorageAtomic(
ObjectStore2& os,
std::string_view storage_path,
MetaFileType mft_new
) : _os(os), _storage_path(storage_path), _mft_new(mft_new) {
}
FilesystemStorage::~FilesystemStorage(void) {
FilesystemStorageAtomic::~FilesystemStorageAtomic(void) {
}
ObjectHandle FilesystemStorage::newObject(ByteSpan id, bool throw_construct) {
ObjectHandle FilesystemStorageAtomic::newObject(ByteSpan id, bool throw_construct) {
{ // first check if id is already used (TODO: solve the multi obj/backend problem)
auto exising_oh = _os.getOneObjectByID(id);
if (static_cast<bool>(exising_oh)) {
@@ -96,7 +96,7 @@ ObjectHandle FilesystemStorage::newObject(ByteSpan id, bool throw_construct) {
return oh;
}
bool FilesystemStorage::write(Object o, std::function<write_to_storage_fetch_data_cb>& data_cb) {
bool FilesystemStorageAtomic::write(Object o, std::function<write_to_storage_fetch_data_cb>& data_cb) {
auto& reg = _os.registry();
if (!reg.valid(o)) {
@@ -303,7 +303,7 @@ bool FilesystemStorage::write(Object o, std::function<write_to_storage_fetch_dat
return true;
}
bool FilesystemStorage::read(Object o, std::function<read_from_storage_put_data_cb>& data_cb) {
bool FilesystemStorageAtomic::read(Object o, std::function<read_from_storage_put_data_cb>& data_cb) {
auto& reg = _os.registry();
if (!reg.valid(o)) {
@@ -355,11 +355,11 @@ bool FilesystemStorage::read(Object o, std::function<read_from_storage_put_data_
return true;
}
void FilesystemStorage::scanAsync(void) {
void FilesystemStorageAtomic::scanAsync(void) {
scanPathAsync(_storage_path);
}
size_t FilesystemStorage::scanPath(std::string_view path) {
size_t FilesystemStorageAtomic::scanPath(std::string_view path) {
// TODO: extract so async can work (or/and make iteratable generator)
if (path.empty() || !std::filesystem::is_directory(path)) {
@@ -615,7 +615,7 @@ size_t FilesystemStorage::scanPath(std::string_view path) {
return scanned_objs.size();
}
void FilesystemStorage::scanPathAsync(std::string path) {
void FilesystemStorageAtomic::scanPathAsync(std::string path) {
// add path to queue
// HACK: if path is known/any fragment is in the path, this operation blocks (non async)
scanPath(path); // TODO: make async and post result

View File

@@ -9,15 +9,15 @@ namespace Backends {
// TODO: rename to atomic filesystem store?
// provides meta and atomic read/write on your filesystem
struct FilesystemStorage : public StorageBackendIMeta, public StorageBackendIAtomic {
struct FilesystemStorageAtomic : public StorageBackendIMeta, public StorageBackendIAtomic {
ObjectStore2& _os;
FilesystemStorage(
FilesystemStorageAtomic(
ObjectStore2& os,
std::string_view storage_path = "test_obj_store",
MetaFileType mft_new = MetaFileType::BINARY_MSGPACK
);
~FilesystemStorage(void);
~FilesystemStorageAtomic(void);
// TODO: fix the path for this specific fs?
// for now we assume a single storage path per backend (there can be multiple per type)

View File

@@ -49,7 +49,7 @@ struct StorageBackendIFile2 {
FILE2_READ = 1u << 0,
FILE2_WRITE = 1u << 1,
// only relevant for backend implementing this (ideally all)
// only relevant for backends implementing this (ideally all)
FILE2_NO_COMP = 1u << 2,// dont do any de-/compression
FILE2_NO_ENC = 1u << 3, // dont do any de-/encryption