diff options
Diffstat (limited to 'zenserver/projectstore.cpp')
| -rw-r--r-- | zenserver/projectstore.cpp | 118 |
1 files changed, 58 insertions, 60 deletions
diff --git a/zenserver/projectstore.cpp b/zenserver/projectstore.cpp index 2bbc1dce3..404484edf 100644 --- a/zenserver/projectstore.cpp +++ b/zenserver/projectstore.cpp @@ -7,6 +7,7 @@ #include <zencore/compactbinaryvalidation.h> #include <zencore/filesystem.h> #include <zencore/fmtutils.h> +#include <zencore/logging.h> #include <zencore/stream.h> #include <zencore/string.h> #include <zencore/timer.h> @@ -22,11 +23,8 @@ # include <rocksdb/db.h> #endif -#include <ppl.h> -#include <spdlog/spdlog.h> #include <xxh3.h> #include <asio.hpp> -#include <future> #include <latch> #include <string> @@ -66,7 +64,7 @@ struct ProjectStore::OplogStorage : public RefCounted ~OplogStorage() { - Log().info("closing oplog storage at {}", m_OplogStoragePath); + ZEN_INFO("closing oplog storage at {}", m_OplogStoragePath); Flush(); #if USE_ROCKSDB @@ -82,7 +80,7 @@ struct ProjectStore::OplogStorage : public RefCounted if (!Status.ok()) { - Log().warn("db close error reported for '{}' : '{}'", m_OplogStoragePath, Status.getState()); + ZEN_WARN("db close error reported for '{}' : '{}'", m_OplogStoragePath, Status.getState()); } } #endif @@ -98,7 +96,7 @@ struct ProjectStore::OplogStorage : public RefCounted void Open(bool IsCreate) { - Log().info("initializing oplog storage at '{}'", m_OplogStoragePath); + ZEN_INFO("initializing oplog storage at '{}'", m_OplogStoragePath); if (IsCreate) { @@ -118,7 +116,7 @@ struct ProjectStore::OplogStorage : public RefCounted { std::string RocksdbPath = WideToUtf8((m_OplogStoragePath / "ops.rdb").native().c_str()); - Log().debug("opening rocksdb db at '{}'", RocksdbPath); + ZEN_DEBUG("opening rocksdb db at '{}'", RocksdbPath); rocksdb::DB* Db; rocksdb::DBOptions Options; @@ -144,14 +142,14 @@ struct ProjectStore::OplogStorage : public RefCounted } else { - throw std::exception("column family iteration failed for '{}': '{}'"_format(RocksdbPath, Status.getState()).c_str()); + throw std::runtime_error("column family iteration failed for '{}': '{}'"_format(RocksdbPath, Status.getState()).c_str()); } Status = rocksdb::DB::Open(Options, RocksdbPath, ColumnDescriptors, &m_RocksDbColumnHandles, &Db); if (!Status.ok()) { - throw std::exception("database open failed for '{}': '{}'"_format(RocksdbPath, Status.getState()).c_str()); + throw std::runtime_error("database open failed for '{}': '{}'"_format(RocksdbPath, Status.getState()).c_str()); } m_RocksDb.reset(Db); @@ -163,7 +161,7 @@ struct ProjectStore::OplogStorage : public RefCounted { // This could use memory mapping or do something clever but for now it just reads the file sequentially - spdlog::info("replaying log for '{}'", m_OplogStoragePath); + ZEN_INFO("replaying log for '{}'", m_OplogStoragePath); Stopwatch Timer; @@ -179,7 +177,7 @@ struct ProjectStore::OplogStorage : public RefCounted if (OpCoreHash != LogEntry.OpCoreHash) { - Log().warn("skipping oplog entry with bad checksum!"); + ZEN_WARN("skipping oplog entry with bad checksum!"); return; } @@ -192,10 +190,10 @@ struct ProjectStore::OplogStorage : public RefCounted Handler(Op, LogEntry); }); - spdlog::info("Oplog replay completed in {} - Max LSN# {}, Next offset: {}", - NiceTimeSpanMs(Timer.getElapsedTimeMs()), - m_MaxLsn, - m_NextOpsOffset); + ZEN_INFO("Oplog replay completed in {} - Max LSN# {}, Next offset: {}", + NiceTimeSpanMs(Timer.getElapsedTimeMs()), + m_MaxLsn, + m_NextOpsOffset); } void ReplayLog(const std::vector<OplogEntryAddress>& Entries, std::function<void(CbObject)>&& Handler) @@ -466,7 +464,7 @@ ProjectStore::Oplog::RegisterOplogEntry(CbObject Core, const OplogEntry& OpEntry AddChunkMapping(PackageId, PackageHash); - Log().debug("package data {} -> {}", PackageId, PackageHash); + ZEN_DEBUG("package data {} -> {}", PackageId, PackageHash); } for (CbFieldView& Entry : Core["bulkdata"sv]) @@ -478,7 +476,7 @@ ProjectStore::Oplog::RegisterOplogEntry(CbObject Core, const OplogEntry& OpEntry AddChunkMapping(BulkDataId, BulkDataHash); - Log().debug("bulkdata {} -> {}", BulkDataId, BulkDataHash); + ZEN_DEBUG("bulkdata {} -> {}", BulkDataId, BulkDataHash); } if (Core["files"sv]) @@ -500,11 +498,11 @@ ProjectStore::Oplog::RegisterOplogEntry(CbObject Core, const OplogEntry& OpEntry } else { - Log().warn("invalid file"); + ZEN_WARN("invalid file"); } } - Log().debug("added {} file(s) in {}", FileCount, NiceTimeSpanMs(Timer.getElapsedTimeMs())); + ZEN_DEBUG("added {} file(s) in {}", FileCount, NiceTimeSpanMs(Timer.getElapsedTimeMs())); } for (CbFieldView& Entry : Core["meta"sv]) @@ -516,7 +514,7 @@ ProjectStore::Oplog::RegisterOplogEntry(CbObject Core, const OplogEntry& OpEntry AddMetaMapping(MetaId, MetaDataHash); - Log().debug("meta data ({}) {} -> {}", NameString, MetaId, MetaDataHash); + ZEN_DEBUG("meta data ({}) {} -> {}", NameString, MetaId, MetaDataHash); } m_OpAddressMap.emplace(OpEntry.OpLsn, OplogEntryAddress{.Offset = OpEntry.OpCoreOffset, .Size = OpEntry.OpCoreSize}); @@ -579,10 +577,10 @@ ProjectStore::Oplog::AppendNewOplogEntry(CbPackage OpPackage) const uint32_t EntryId = RegisterOplogEntry(Core, OpEntry, kUpdateNewEntry); - Log().debug("oplog entry #{} attachments: {}B new, {}B total", - EntryId, - zen::NiceBytes(NewAttachmentBytes), - zen::NiceBytes(AttachmentBytes)); + ZEN_DEBUG("oplog entry #{} attachments: {} new, {} total", + EntryId, + zen::NiceBytes(NewAttachmentBytes), + zen::NiceBytes(AttachmentBytes)); return EntryId; } @@ -611,7 +609,7 @@ ProjectStore::Project::Read() { std::filesystem::path ProjectStateFilePath = m_OplogStoragePath / "Project.zcb"; - spdlog::info("reading config for project '{}' from {}", Identifier, ProjectStateFilePath); + ZEN_INFO("reading config for project '{}' from {}", Identifier, ProjectStateFilePath); BasicFile Blob; Blob.Open(ProjectStateFilePath, false); @@ -630,7 +628,7 @@ ProjectStore::Project::Read() } else { - spdlog::error("validation error {} hit for '{}'", int(ValidationError), ProjectStateFilePath); + ZEN_ERROR("validation error {} hit for '{}'", int(ValidationError), ProjectStateFilePath); } } @@ -652,7 +650,7 @@ ProjectStore::Project::Write() std::filesystem::path ProjectStateFilePath = m_OplogStoragePath / "Project.zcb"; - spdlog::info("persisting config for project '{}' to {}", Identifier, ProjectStateFilePath); + ZEN_INFO("persisting config for project '{}' to {}", Identifier, ProjectStateFilePath); BasicFile Blob; Blob.Open(ProjectStateFilePath, true); @@ -729,7 +727,7 @@ ProjectStore::Project::OpenOplog(std::string_view OplogId) } catch (std::exception& ex) { - spdlog::error("failed to open oplog '{}' @ '{}': {}", OplogId, OplogBasePath, ex.what()); + ZEN_ERROR("failed to open oplog '{}' @ '{}': {}", OplogId, OplogBasePath, ex.what()); m_Oplogs.erase(std::string{OplogId}); } @@ -785,17 +783,17 @@ ProjectStore::Project::Flush() ////////////////////////////////////////////////////////////////////////// ProjectStore::ProjectStore(CasStore& Store, std::filesystem::path BasePath) -: m_Log("project", begin(spdlog::default_logger()->sinks()), end(spdlog::default_logger()->sinks())) +: m_Log(zen::logging::Get("project")) , m_ProjectBasePath(BasePath) , m_CasStore(Store) { - m_Log.info("initializing project store at '{}'", BasePath); - m_Log.set_level(spdlog::level::debug); + ZEN_INFO("initializing project store at '{}'", BasePath); + // m_Log.set_level(spdlog::level::debug); } ProjectStore::~ProjectStore() { - m_Log.info("closing project store ('{}')", m_ProjectBasePath); + ZEN_INFO("closing project store ('{}')", m_ProjectBasePath); } std::filesystem::path @@ -839,7 +837,7 @@ ProjectStore::OpenProject(std::string_view ProjectId) { try { - Log().info("opening project {} @ {}", ProjectId, ProjectBasePath); + ZEN_INFO("opening project {} @ {}", ProjectId, ProjectBasePath); ProjectStore::Project& Prj = m_Projects.try_emplace(std::string{ProjectId}, this, m_CasStore, ProjectBasePath).first->second; Prj.Identifier = ProjectId; @@ -848,7 +846,7 @@ ProjectStore::OpenProject(std::string_view ProjectId) } catch (std::exception& e) { - Log().warn("failed to open {} @ {} ({})", ProjectId, ProjectBasePath, e.what()); + ZEN_WARN("failed to open {} @ {} ({})", ProjectId, ProjectBasePath, e.what()); m_Projects.erase(std::string{ProjectId}); } } @@ -880,7 +878,7 @@ ProjectStore::DeleteProject(std::string_view ProjectId) { std::filesystem::path ProjectBasePath = BasePathForProject(ProjectId); - Log().info("deleting project {} @ {}", ProjectId, ProjectBasePath); + ZEN_INFO("deleting project {} @ {}", ProjectId, ProjectBasePath); m_Projects.erase(std::string{ProjectId}); @@ -908,7 +906,7 @@ ProjectStore::OpenProjectOplog(std::string_view ProjectId, std::string_view Oplo HttpProjectService::HttpProjectService(CasStore& Store, ProjectStore* Projects) : m_CasStore(Store) -, m_Log("project", begin(spdlog::default_logger()->sinks()), end(spdlog::default_logger()->sinks())) +, m_Log(logging::Get("project")) , m_ProjectStore(Projects) { using namespace std::literals; @@ -1163,7 +1161,7 @@ HttpProjectService::HttpProjectService(CasStore& Store, ProjectStore* Projects) } } - m_Log.debug("chunk - {} / {} / {}", ProjectId, OplogId, ChunkId); + ZEN_DEBUG("chunk - {} / {} / {}", ProjectId, OplogId, ChunkId); ProjectStore::Oplog* FoundLog = m_ProjectStore->OpenProjectOplog(ProjectId, OplogId); @@ -1256,7 +1254,7 @@ HttpProjectService::HttpProjectService(CasStore& Store, ProjectStore* Projects) } } - m_Log.debug("oplog hash - {} / {} / {}", ProjectId, OplogId, HashString); + ZEN_DEBUG("oplog hash - {} / {} / {}", ProjectId, OplogId, HashString); IoHash Hash = IoHash::FromHexString(HashString); IoBuffer Value = m_CasStore.FindChunk(Hash); @@ -1317,7 +1315,7 @@ HttpProjectService::HttpProjectService(CasStore& Store, ProjectStore* Projects) if (!m_CasStore.FindChunk(FileHash)) { - spdlog::debug("NEED: {}", FileHash); + ZEN_DEBUG("NEED: {}", FileHash); NeedList.push_back(FileHash); } @@ -1365,7 +1363,7 @@ HttpProjectService::HttpProjectService(CasStore& Store, ProjectStore* Projects) return HttpReq.WriteResponse(HttpResponseCode::NotFound); } - ProjectStore::Oplog& Log = *FoundLog; + ProjectStore::Oplog& Oplog = *FoundLog; IoBuffer Payload = HttpReq.ReadPayload(); @@ -1389,7 +1387,7 @@ HttpProjectService::HttpProjectService(CasStore& Store, ProjectStore* Projects) AttachmentId = Hash; } - std::filesystem::path AttachmentPath = Log.TempPath() / AttachmentId.ToHexString(); + std::filesystem::path AttachmentPath = Oplog.TempPath() / AttachmentId.ToHexString(); if (IoBuffer Data = m_CasStore.FindChunk(Hash)) { @@ -1412,7 +1410,7 @@ HttpProjectService::HttpProjectService(CasStore& Store, ProjectStore* Projects) if (!legacy::TryLoadCbPackage(Package, Payload, &UniqueBuffer::Alloc, &Resolver)) { - m_Log.error("Received malformed package!"); + ZEN_ERROR("Received malformed package!"); return HttpReq.WriteResponse(HttpResponseCode::BadRequest, HttpContentType::kText, "Invalid package"); } @@ -1433,14 +1431,14 @@ HttpProjectService::HttpProjectService(CasStore& Store, ProjectStore* Projects) // Write core to oplog - const uint32_t OpLsn = Log.AppendNewOplogEntry(Package); + const uint32_t OpLsn = Oplog.AppendNewOplogEntry(Package); if (OpLsn == ProjectStore::Oplog::kInvalidOp) { return HttpReq.WriteResponse(HttpResponseCode::BadRequest); } - m_Log.info("new op #{:4} - {}/{} ({:>6}) {}", OpLsn, ProjectId, OplogId, NiceBytes(Payload.Size()), Core["key"sv].AsString()); + ZEN_INFO("new op #{:4} - {}/{} ({:>6}) {}", OpLsn, ProjectId, OplogId, NiceBytes(Payload.Size()), Core["key"sv].AsString()); HttpReq.WriteResponse(HttpResponseCode::Created); }, @@ -1510,7 +1508,7 @@ HttpProjectService::HttpProjectService(CasStore& Store, ProjectStore* Projects) return Req.ServerRequest().WriteResponse(HttpResponseCode::InternalServerError); } - m_Log.info("established oplog {} / {}", ProjectId, OplogId); + ZEN_INFO("established oplog {} / {}", ProjectId, OplogId); return Req.ServerRequest().WriteResponse(HttpResponseCode::Created); } @@ -1524,7 +1522,7 @@ HttpProjectService::HttpProjectService(CasStore& Store, ProjectStore* Projects) case HttpVerb::kDelete: { - spdlog::info("deleting oplog {}/{}", ProjectId, OplogId); + ZEN_INFO("deleting oplog {}/{}", ProjectId, OplogId); ProjectIt->DeleteOplog(OplogId); @@ -1603,12 +1601,12 @@ HttpProjectService::HttpProjectService(CasStore& Store, ProjectStore* Projects) const std::filesystem::path BasePath = m_ProjectStore->BasePath() / ProjectId; m_ProjectStore->NewProject(BasePath, ProjectId, Root, EngineRoot, ProjectRoot); - m_Log.info("established project - {} (id: '{}', roots: '{}', '{}', '{}')", - ProjectId, - Id, - Root, - EngineRoot, - ProjectRoot); + ZEN_INFO("established project - {} (id: '{}', roots: '{}', '{}', '{}')", + ProjectId, + Id, + Root, + EngineRoot, + ProjectRoot); Req.ServerRequest().WriteResponse(HttpResponseCode::Created); } @@ -1672,7 +1670,7 @@ HttpProjectService::HandleRequest(HttpServerRequest& Request) { if (m_Router.HandleRequest(Request) == false) { - m_Log.warn("No route found for {0}", Request.RelativeUri()); + ZEN_WARN("No route found for {0}", Request.RelativeUri()); } } @@ -1738,7 +1736,7 @@ struct LocalProjectService::LocalProjectImpl } catch (std::exception& ex) { - spdlog::error("exception caught in pipe project service loop: {}", ex.what()); + ZEN_ERROR("exception caught in pipe project service loop: {}", ex.what()); } m_ShutdownLatch.count_down(); @@ -1823,7 +1821,7 @@ private: if (hPipe == INVALID_HANDLE_VALUE) { - spdlog::warn("failed while creating named pipe {}", PipeName.c_str()); + ZEN_WARN("failed while creating named pipe {}", PipeName.c_str()); // TODO: error - how to best handle? } @@ -1870,13 +1868,13 @@ private: return; } - spdlog::warn("pipe connection error: {}", Ec.message()); + ZEN_WARN("pipe connection error: {}", Ec.message()); // TODO: should disconnect and issue a new connect return; } - spdlog::debug("pipe connection established"); + ZEN_DEBUG("pipe connection established"); IssueRead(); } @@ -1898,13 +1896,13 @@ private: return; } - spdlog::warn("pipe read error: {}", Ec.message()); + ZEN_WARN("pipe read error: {}", Ec.message()); // TODO: should disconnect and issue a new connect return; } - spdlog::debug("received message: {} bytes", Bytes); + ZEN_DEBUG("received message: {} bytes", Bytes); // TODO: Actually process request @@ -1926,7 +1924,7 @@ private: return; } - spdlog::warn("pipe write error: {}", Ec.message()); + ZEN_WARN("pipe write error: {}", Ec.message()); // TODO: should disconnect and issue a new connect return; |