diff options
Diffstat (limited to 'src/zenserver/projectstore/projectstore.h')
| -rw-r--r-- | src/zenserver/projectstore/projectstore.h | 73 |
1 files changed, 43 insertions, 30 deletions
diff --git a/src/zenserver/projectstore/projectstore.h b/src/zenserver/projectstore/projectstore.h index 2595d7198..028ad0c6d 100644 --- a/src/zenserver/projectstore/projectstore.h +++ b/src/zenserver/projectstore/projectstore.h @@ -78,22 +78,31 @@ 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(); [[nodiscard]] static bool ExistsAt(const std::filesystem::path& BasePath); bool Exists() const; - void Read(); + enum class EState + { + kUnread, + kBasicNoLookups, + kFull + }; + + void Read(EState State); void Write(); void Update(const std::filesystem::path& MarkerPath); bool Reset(); + bool CanUnload(); struct ChunkInfo { @@ -107,7 +116,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 +129,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 +164,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); @@ -169,8 +179,6 @@ public: void ResetState(); bool PrepareForDelete(std::filesystem::path& OutRemoveDirectory); - void AddChunkMappings(const std::unordered_map<Oid, IoHash, Oid::Hasher>& ChunkMappings); - void EnableUpdateCapture(); void DisableUpdateCapture(); void CaptureAddedAttachments(std::span<const IoHash> AttachmentHashes); @@ -186,8 +194,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 +230,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 +244,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; @@ -242,6 +253,8 @@ public: std::filesystem::path m_TempPath; std::filesystem::path m_MetaPath; + EState m_State = EState::kUnread; + mutable RwLock m_OplogLock; OidMap<IoHash> m_ChunkMap; // output data chunk id -> CAS address OidMap<IoHash> m_MetaMap; // meta chunk id -> CAS address @@ -266,7 +279,7 @@ public: */ uint32_t GetUnusedSpacePercentLocked() const; void WriteIndexSnapshot(); - void ReadIndexSnapshot(); + void ReadIndexSnapshot(EState ReadMode); struct OplogEntryMapping { @@ -308,8 +321,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 +375,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; |