diff options
| author | Stefan Boberg <[email protected]> | 2021-06-02 10:17:38 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-06-02 10:17:38 +0200 |
| commit | 819c214d2ec5608861b3e74f006114dae7f980d0 (patch) | |
| tree | bc2931d5a8259a5d26975271bc8d72d664800e97 | |
| parent | clang-format fixes (diff) | |
| download | zen-819c214d2ec5608861b3e74f006114dae7f980d0.tar.xz zen-819c214d2ec5608861b3e74f006114dae7f980d0.zip | |
Added support for salt in oplog append operations, which can be used to avoid payload file conflicts when multiple operations end up producing the same large output chunks
| -rw-r--r-- | zenserver/projectstore.cpp | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/zenserver/projectstore.cpp b/zenserver/projectstore.cpp index eccaacff5..2aac5fe50 100644 --- a/zenserver/projectstore.cpp +++ b/zenserver/projectstore.cpp @@ -28,6 +28,7 @@ #include <asio.hpp> #include <future> #include <latch> +#include <string> namespace zen { @@ -1070,6 +1071,18 @@ HttpProjectService::HttpProjectService(CasStore& Store, ProjectStore* Projects) const auto& ProjectId = Req.GetCapture(1); const auto& OplogId = Req.GetCapture(2); + HttpServerRequest::QueryParams Params = HttpReq.GetQueryParams(); + + bool IsUsingSalt = false; + IoHash SaltHash = IoHash::Zero; + + if (std::string_view SaltParam = Params.GetValue("salt"); SaltParam.empty() == false) + { + const uint32_t Salt = std::stoi(std::string(SaltParam)); + SaltHash = IoHash::HashMemory(&Salt, sizeof Salt); + IsUsingSalt = true; + } + ProjectStore::Oplog* FoundLog = m_ProjectStore->OpenProjectOplog(ProjectId, OplogId); if (FoundLog == nullptr) @@ -1089,13 +1102,25 @@ HttpProjectService::HttpProjectService(CasStore& Store, ProjectStore* Projects) std::vector<IoHash> MissingChunks; CbPackage::AttachmentResolver Resolver = [&](const IoHash& Hash) -> SharedBuffer { - std::filesystem::path AttachmentPath = Log.TempPath() / Hash.ToHexString(); + IoHash AttachmentId; + + if (IsUsingSalt) + { + IoHash AttachmentSpec[]{SaltHash, Hash}; + AttachmentId = IoHash::HashMemory(MakeMemoryView(AttachmentSpec)); + } + else + { + AttachmentId = Hash; + } + + std::filesystem::path AttachmentPath = Log.TempPath() / AttachmentId.ToHexString(); - if (IoBuffer Data = IoBufferBuilder::MakeFromTemporaryFile(AttachmentPath.native().c_str())) + if (IoBuffer Data = m_CasStore.FindChunk(Hash)) { return SharedBuffer(std::move(Data)); } - else if (Data = m_CasStore.FindChunk(Hash)) + else if (Data = IoBufferBuilder::MakeFromTemporaryFile(AttachmentPath.native().c_str())) { return SharedBuffer(std::move(Data)); } |