diff options
| author | Stefan Boberg <[email protected]> | 2021-11-01 19:59:31 +0100 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-11-01 19:59:31 +0100 |
| commit | 2017dc2338e93af35f942953458466d7058fc80c (patch) | |
| tree | a43aaa7f9cc4f7cf68d5fde49f7d71a236bc356e /zenserver/projectstore.cpp | |
| parent | gc: added DeletionMode flag to allow gc dry runs (diff) | |
| download | zen-2017dc2338e93af35f942953458466d7058fc80c.tar.xz zen-2017dc2338e93af35f942953458466d7058fc80c.zip | |
projectstore: Implemented project/oplog discovery so we can take any persistent oplog into account even if it has not been opened in the current session
Diffstat (limited to 'zenserver/projectstore.cpp')
| -rw-r--r-- | zenserver/projectstore.cpp | 67 |
1 files changed, 66 insertions, 1 deletions
diff --git a/zenserver/projectstore.cpp b/zenserver/projectstore.cpp index a0287bf1b..2eea66be0 100644 --- a/zenserver/projectstore.cpp +++ b/zenserver/projectstore.cpp @@ -802,6 +802,35 @@ ProjectStore::Project::DeleteOplog(std::string_view OplogId) } void +ProjectStore::Project::DiscoverOplogs() +{ + FileSystemTraversal Traversal; + struct Visitor : public FileSystemTraversal::TreeVisitor + { + virtual void VisitFile([[maybe_unused]] const std::filesystem::path& Parent, + [[maybe_unused]] const path_view& File, + [[maybe_unused]] uint64_t FileSize) override + { + } + + virtual bool VisitDirectory([[maybe_unused]] const std::filesystem::path& Parent, const path_view& DirectoryName) override + { + Dirs.push_back(WideToUtf8(DirectoryName)); + return false; + } + + std::vector<std::string> Dirs; + } Visit; + + Traversal.TraverseFileSystem(m_OplogStoragePath, Visit); + + for (const std::string& Dir : Visit.Dirs) + { + OpenOplog(Dir); + } +} + +void ProjectStore::Project::IterateOplogs(std::function<void(const Oplog&)>&& Fn) const { // TODO: should also iterate over oplogs which are present on disk but not yet loaded @@ -869,6 +898,40 @@ ProjectStore::BasePathForProject(std::string_view ProjectId) } void +ProjectStore::DiscoverProjects() +{ + FileSystemTraversal Traversal; + struct Visitor : public FileSystemTraversal::TreeVisitor + { + virtual void VisitFile([[maybe_unused]] const std::filesystem::path& Parent, + [[maybe_unused]] const path_view& File, + [[maybe_unused]] uint64_t FileSize) override + { + } + + virtual bool VisitDirectory([[maybe_unused]] const std::filesystem::path& Parent, const path_view& DirectoryName) override + { + Dirs.push_back(WideToUtf8(DirectoryName)); + return false; + } + + std::vector<std::string> Dirs; + } Visit; + + Traversal.TraverseFileSystem(m_ProjectBasePath, Visit); + + for (const auto& Dir : Visit.Dirs) + { + Project* Project = OpenProject(Dir); + + if (Project) + { + Project->DiscoverOplogs(); + } + } +} + +void ProjectStore::Flush() { // TODO @@ -895,6 +958,8 @@ ProjectStore::Scrub(ScrubContext& Ctx) void ProjectStore::GatherReferences(GcContext& GcCtx) { + DiscoverProjects(); + RwLock::SharedLockScope _(m_ProjectsLock); for (auto& Kv : m_Projects) @@ -1525,7 +1590,7 @@ HttpProjectService::HttpProjectService(CidStore& Store, ProjectStore* Projects) return HttpReq.WriteResponse(HttpResponseCode::BadRequest); } - ZEN_INFO("'{}/{}' op #{} ({}) - '{}'", ProjectId, OplogId, OpLsn, NiceBytes(Payload.Size()) , Core["key"sv].AsString()); + ZEN_INFO("'{}/{}' op #{} ({}) - '{}'", ProjectId, OplogId, OpLsn, NiceBytes(Payload.Size()), Core["key"sv].AsString()); HttpReq.WriteResponse(HttpResponseCode::Created); }, |