diff options
Diffstat (limited to 'src/zenserver/projectstore/projectstore.h')
| -rw-r--r-- | src/zenserver/projectstore/projectstore.h | 58 |
1 files changed, 32 insertions, 26 deletions
diff --git a/src/zenserver/projectstore/projectstore.h b/src/zenserver/projectstore/projectstore.h index 2595d7198..b41862f40 100644 --- a/src/zenserver/projectstore/projectstore.h +++ b/src/zenserver/projectstore/projectstore.h @@ -78,12 +78,13 @@ public: struct Project; - struct Oplog + struct Oplog : public RefCounted { - Oplog(std::string_view Id, - Project* Project, + Oplog(const LoggerRef& Log, + std::string_view ProjectIdentifier, + std::string_view Id, CidStore& Store, - std::filesystem::path BasePath, + const std::filesystem::path& BasePath, const std::filesystem::path& MarkerPath); ~Oplog(); @@ -94,6 +95,7 @@ public: void Write(); void Update(const std::filesystem::path& MarkerPath); bool Reset(); + bool CanUnload(); struct ChunkInfo { @@ -107,7 +109,7 @@ public: int32_t Count = -1; }; - std::vector<ChunkInfo> GetAllChunksInfo(); + std::vector<ChunkInfo> GetAllChunksInfo(const std::filesystem::path& ProjectRootDir); void IterateChunkMap(std::function<void(const Oid&, const IoHash& Hash)>&& Fn); void IterateFileMap(std::function<void(const Oid&, const std::string_view& ServerPath, const std::string_view& ClientPath)>&& Fn); void IterateOplog(std::function<void(CbObjectView)>&& Fn, const Paging& EntryPaging); @@ -120,18 +122,19 @@ public: std::optional<CbObject> GetOpByIndex(uint32_t Index); std::optional<uint32_t> GetOpIndexByKey(const Oid& Key); - IoBuffer FindChunk(const Oid& ChunkId, uint64_t* OptOutModificationTag); - IoBuffer GetChunkByRawHash(const IoHash& RawHash); - bool IterateChunks(std::span<IoHash> RawHashes, - bool IncludeModTag, - const std::function<bool(size_t Index, const IoBuffer& Payload, uint64_t ModTag)>& AsyncCallback, - WorkerThreadPool* OptionalWorkerPool, - uint64_t LargeSizeLimit); - bool IterateChunks(std::span<Oid> ChunkIds, - bool IncludeModTag, - const std::function<bool(size_t Index, const IoBuffer& Payload, uint64_t ModTag)>& AsyncCallback, - WorkerThreadPool* OptionalWorkerPool, - uint64_t LargeSizeLimit); + IoBuffer FindChunk(const std::filesystem::path& ProjectRootDir, const Oid& ChunkId, uint64_t* OptOutModificationTag); + IoBuffer GetChunkByRawHash(const IoHash& RawHash); + bool IterateChunks(std::span<IoHash> RawHashes, + bool IncludeModTag, + const std::function<bool(size_t Index, const IoBuffer& Payload, uint64_t ModTag)>& AsyncCallback, + WorkerThreadPool* OptionalWorkerPool, + uint64_t LargeSizeLimit); + bool IterateChunks(const std::filesystem::path& ProjectRootDir, + std::span<Oid> ChunkIds, + bool IncludeModTag, + const std::function<bool(size_t Index, const IoBuffer& Payload, uint64_t ModTag)>& AsyncCallback, + WorkerThreadPool* OptionalWorkerPool, + uint64_t LargeSizeLimit); inline static const uint32_t kInvalidOp = ~0u; /** Persist a new oplog entry @@ -154,7 +157,7 @@ public: const std::filesystem::path& TempPath() const { return m_TempPath; } const std::filesystem::path& MarkerPath() const { return m_MarkerPath; } - LoggerRef Log() { return m_OuterProject->Log(); } + LoggerRef Log() const { return m_Log; } void Flush(); void Scrub(ScrubContext& Ctx); static uint64_t TotalSize(const std::filesystem::path& BasePath); @@ -186,8 +189,8 @@ public: void GetAttachmentsLocked(std::vector<IoHash>& OutAttachments, bool StoreMetaDataOnDisk); - Project* GetOuterProject() const { return m_OuterProject; } - void CompactIfUnusedExceeds(bool DryRun, uint32_t CompactUnusedThreshold, std::string_view LogPrefix); + std::string_view GetOuterProjectIdentifier() const { return m_OuterProjectId; } + void CompactIfUnusedExceeds(bool DryRun, uint32_t CompactUnusedThreshold, std::string_view LogPrefix); static std::optional<CbObject> ReadStateFile(const std::filesystem::path& BasePath, std::function<LoggerRef()>&& Log); @@ -222,7 +225,9 @@ public: } }; - ValidationResult Validate(std::atomic_bool& IsCancelledFlag, WorkerThreadPool* OptionalWorkerPool); + ValidationResult Validate(const std::filesystem::path& ProjectRootDir, + std::atomic_bool& IsCancelledFlag, + WorkerThreadPool* OptionalWorkerPool); private: struct FileMapEntry @@ -234,7 +239,8 @@ public: template<class V> using OidMap = tsl::robin_map<Oid, V, Oid::Hasher>; - Project* m_OuterProject = nullptr; + LoggerRef m_Log; + const std::string m_OuterProjectId; const std::string m_OplogId; CidStore& m_CidStore; const std::filesystem::path m_BasePath; @@ -308,8 +314,9 @@ public: std::filesystem::path ProjectRootDir; std::filesystem::path ProjectFilePath; - Oplog* NewOplog(std::string_view OplogId, const std::filesystem::path& MarkerPath); - Oplog* OpenOplog(std::string_view OplogId, bool AllowCompact, bool VerifyPathOnDisk); + Ref<Oplog> NewOplog(std::string_view OplogId, const std::filesystem::path& MarkerPath); + Ref<Oplog> OpenOplog(std::string_view OplogId, bool AllowCompact, bool VerifyPathOnDisk); + bool TryUnloadOplog(std::string_view OplogId); bool DeleteOplog(std::string_view OplogId); bool RemoveOplog(std::string_view OplogId, std::filesystem::path& OutDeletePath); void IterateOplogs(std::function<void(const RwLock::SharedLockScope&, const Oplog&)>&& Fn) const; @@ -361,8 +368,7 @@ public: ProjectStore* m_ProjectStore; CidStore& m_CidStore; mutable RwLock m_ProjectLock; - std::map<std::string, std::unique_ptr<Oplog>> m_Oplogs; - std::vector<std::unique_ptr<Oplog>> m_DeletedOplogs; + std::map<std::string, Ref<Oplog>> m_Oplogs; std::filesystem::path m_OplogStoragePath; mutable RwLock m_LastAccessTimesLock; mutable tsl::robin_map<std::string, GcClock::Tick> m_LastAccessTimes; |