diff options
| author | Dan Engelbrecht <[email protected]> | 2025-10-03 14:17:07 +0200 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2025-10-03 14:17:07 +0200 |
| commit | 158d4d50392ff1d416828ca2a17d4c3f4b877bd9 (patch) | |
| tree | 2c4a84bd3c6e9bce22567895a6e213a6e43bcd48 /src/zenstore/include | |
| parent | fix missing chunk (#548) (diff) | |
| download | zen-158d4d50392ff1d416828ca2a17d4c3f4b877bd9.tar.xz zen-158d4d50392ff1d416828ca2a17d4c3f4b877bd9.zip | |
move zen vfs implementation to zenstore (#549)
* move zen vfs implementation to zenstore
Diffstat (limited to 'src/zenstore/include')
| -rw-r--r-- | src/zenstore/include/zenstore/vfsimpl.h | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/src/zenstore/include/zenstore/vfsimpl.h b/src/zenstore/include/zenstore/vfsimpl.h new file mode 100644 index 000000000..22ca07a27 --- /dev/null +++ b/src/zenstore/include/zenstore/vfsimpl.h @@ -0,0 +1,103 @@ +// Copyright Epic Games, Inc. All Rights Reserved. + +#pragma once + +#include <zencore/logging.h> +#include <zenvfs/vfs.h> + +#include <memory> +#include <unordered_map> + +namespace zen { + +#if ZEN_WITH_VFS + +class ProjectStore; +class ZenCacheStore; +struct VfsServiceImpl; + +struct VfsOplogDataSource : public VfsTreeDataSource +{ + VfsOplogDataSource(std::string_view ProjectId, std::string_view OplogId, Ref<ProjectStore> InProjectStore); + + virtual void ReadNamedData(std::string_view Path, void* Buffer, uint64_t ByteOffset, uint64_t ByteCount) override; + virtual void ReadChunkData(const Oid& ChunkId, void* Buffer, uint64_t ByteOffset, uint64_t ByteCount) override; + virtual void PopulateDirectory(std::string NodePath, VfsTreeNode& DirNode) override; + +private: + std::string m_ProjectId; + std::string m_OplogId; + Ref<ProjectStore> m_ProjectStore; +}; + +struct VfsCacheDataSource : public VfsTreeDataSource +{ + VfsCacheDataSource(std::string_view NamespaceId, std::string_view BucketId, Ref<ZenCacheStore> InCacheStore); + ~VfsCacheDataSource(); + + virtual void ReadNamedData(std::string_view Path, void* Buffer, uint64_t ByteOffset, uint64_t ByteCount) override; + virtual void ReadChunkData(const Oid& ChunkId, void* Buffer, uint64_t ByteOffset, uint64_t ByteCount) override; + virtual void PopulateDirectory(std::string NodePath, VfsTreeNode& DirNode) override; + +private: + std::string m_NamespaceId; + std::string m_BucketId; + Ref<ZenCacheStore> m_CacheStore; +}; + +struct VfsServiceDataSource : public VfsTreeDataSource +{ + VfsServiceDataSource(VfsServiceImpl* VfsImpl) : m_VfsImpl(VfsImpl) {} + + virtual void ReadNamedData(std::string_view Path, void* Buffer, uint64_t ByteOffset, uint64_t ByteCount) override; + virtual void ReadChunkData(const Oid& ChunkId, void* Buffer, uint64_t ByteOffset, uint64_t ByteCount) override; + virtual void PopulateDirectory(std::string NodePath, VfsTreeNode& DirNode) override; + +private: + VfsServiceImpl* m_VfsImpl = nullptr; + + RwLock m_Lock; + std::unordered_map<std::string, Ref<VfsOplogDataSource>> m_OplogSourceMap; + std::unordered_map<std::string, Ref<VfsCacheDataSource>> m_CacheSourceMap; + + Ref<VfsOplogDataSource> GetOplogDataSource(std::string_view ProjectId, std::string_view OplogId); + Ref<VfsCacheDataSource> GetCacheDataSource(std::string_view NamespaceId, std::string_view BucketId); +}; + +#endif // ZEN_WITH_VFS + +////////////////////////////////////////////////////////////////////////// + +struct VfsServiceImpl +{ +#if ZEN_WITH_VFS + VfsServiceImpl(); + ~VfsServiceImpl(); + + void Mount(std::string_view MountPoint); + void Unmount(); + void AddService(Ref<ProjectStore>&&); + void AddService(Ref<ZenCacheStore>&&); + + inline std::string GetMountpointPath() { return m_MountpointPath; } + inline bool IsVfsRunning() const { return !!m_VfsHost.get(); } + +private: + Ref<ProjectStore> m_ProjectStore; + Ref<ZenCacheStore> m_ZenCacheStore; + Ref<VfsServiceDataSource> m_VfsDataSource; + std::string m_MountpointPath; + + std::unique_ptr<VfsHost> m_VfsHost; + std::thread m_VfsThread; + Event m_VfsThreadRunning; + std::exception_ptr m_VfsThreadException; + + void RefreshVfs(); + void VfsThread(); + + friend struct VfsServiceDataSource; +#endif // ZEN_WITH_VFS +}; + +} // namespace zen |