From d795184a5c29727079903298a762c0059362d478 Mon Sep 17 00:00:00 2001 From: Per Larsson Date: Fri, 21 May 2021 09:52:28 +0200 Subject: =?UTF-8?q?Added=20support=20for=20package=20additional=20files.?= =?UTF-8?q?=20Added=20io=20hash=20chunk=20id=20to=E2=80=A6=20(#2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added support for attaching additional files to oplog entries in project store --- zenserver/projectstore.cpp | 132 +++++++++++++++------------------------------ 1 file changed, 42 insertions(+), 90 deletions(-) (limited to 'zenserver/projectstore.cpp') diff --git a/zenserver/projectstore.cpp b/zenserver/projectstore.cpp index 0d7ad0f16..8753d50fc 100644 --- a/zenserver/projectstore.cpp +++ b/zenserver/projectstore.cpp @@ -276,9 +276,9 @@ ProjectStore::Oplog::FindChunk(Oid ChunkId) return m_CasStore.FindChunk(ChunkIt->second); } - if (auto FileIt = m_ServerFileMap.find(ChunkId); FileIt != m_ServerFileMap.end()) + if (auto FileIt = m_FileMap.find(ChunkId); FileIt != m_FileMap.end()) { - std::filesystem::path FilePath = m_OuterProject->RootDir / FileIt->second; + std::filesystem::path FilePath = m_OuterProject->RootDir / FileIt->second.ServerPath; return IoBufferBuilder::MakeFromFile(FilePath.native().c_str()); } @@ -296,20 +296,35 @@ ProjectStore::Oplog::IterateFileMap(std::function {}", BulkDataId, BulkDataHash); } - if (CbFieldView FilesArray = Core["files"sv]) + if (Core["files"sv]) { - int FileCount = 0; - int ServerFileCount = 0; - - std::atomic InvalidOp{false}; - Stopwatch Timer; + int32_t FileCount = 0; - std::future f0 = std::async(std::launch::async, [&] { - for (CbFieldView& Entry : FilesArray) - { - CbObjectView FileObj = Entry.AsObjectView(); - const Oid FileId = FileObj["id"sv].AsObjectId(); - - if (auto PathField = FileObj["path"sv]) - { - AddFileMapping(FileId, PathField.AsString()); - - // Log().debug("file {} -> {}", FileId, PathString); - - ++FileCount; - } - else - { - // Every file entry needs to specify a path - InvalidOp = true; - break; - } - - if (InvalidOp.load(std::memory_order::relaxed)) - { - break; - } - } - }); - - std::future f1 = std::async(std::launch::async, [&] { - CbArrayView ServerFilesArray = Core["serverfiles"sv].AsArrayView(); + for (CbFieldView& Entry : Core["files"sv]) + { + CbObjectView FileObj = Entry.AsObjectView(); + const Oid FileId = FileObj["id"sv].AsObjectId(); + IoHash FileDataHash = FileObj["data"sv].AsBinaryAttachment(); + std::string_view ServerPath = FileObj["serverpath"sv].AsString(); + std::string_view ClientPath = FileObj["clientpath"sv].AsString(); - for (CbFieldView& Entry : ServerFilesArray) + if (AddFileMapping(FileId, FileDataHash, ServerPath, ClientPath)) { - CbObjectView FileObj = Entry.AsObjectView(); - const Oid FileId = FileObj["id"sv].AsObjectId(); - - if (auto PathField = FileObj["path"sv]) - { - AddServerFileMapping(FileId, PathField.AsString()); - - // m_log.debug("file {} -> {}", FileId, PathString); - - ++ServerFileCount; - } - else - { - // Every file entry needs to specify a path - InvalidOp = true; - break; - } - - if (InvalidOp.load(std::memory_order::relaxed)) - { - break; - } + ++FileCount; } - }); - - f0.wait(); - f1.wait(); - - if (InvalidOp) - { - return kInvalidOp; - } - - if (FileCount || ServerFileCount) - { - Log().debug("{} files registered, {} server files (took {})", - FileCount, - ServerFileCount, - NiceTimeSpanMs(Timer.getElapsedTimeMs())); - - if (FileCount != ServerFileCount) + else { - Log().warn("client/server file list mismatch: {} vs {}", FileCount, ServerFileCount); + Log().warn("invalid file"); } } + + Log().debug("added {} file(s) in {}", FileCount, NiceTimeSpanMs(Timer.getElapsedTimeMs())); } for (CbFieldView& Entry : Core["meta"sv]) @@ -1114,7 +1066,7 @@ HttpProjectService::HttpProjectService(CasStore& Store, ProjectStore* Projects) // the prep step rejected the chunk. This should be fixed since there's // a performance cost associated with any file system activity - bool IsValid = true; + bool IsValid = true; std::vector MissingChunks; CbPackage::AttachmentResolver Resolver = [&](const IoHash& Hash) -> SharedBuffer { -- cgit v1.2.3