diff options
| author | Dan Engelbrecht <[email protected]> | 2023-08-18 10:39:33 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-08-18 10:39:33 +0200 |
| commit | b1b30c7cdd9d39b42827b941a100d4f2418426c2 (patch) | |
| tree | 93acdbfca75bd26a6c5dc13d3cdc8fcbc43d3200 /src | |
| parent | Cache process handles for FormatPackageMessage (#360) (diff) | |
| download | zen-b1b30c7cdd9d39b42827b941a100d4f2418426c2.tar.xz zen-b1b30c7cdd9d39b42827b941a100d4f2418426c2.zip | |
check oplog op attachments when gathering references for GC (#363)
* Make sure to check oplog op attachments when gathering references for GC
* Add oplog op content to error result if attachment is missing when doing `oplog-export`
Diffstat (limited to 'src')
| -rw-r--r-- | src/zenserver/projectstore/projectstore.cpp | 28 | ||||
| -rw-r--r-- | src/zenserver/projectstore/remoteprojectstore.cpp | 23 |
2 files changed, 24 insertions, 27 deletions
diff --git a/src/zenserver/projectstore/projectstore.cpp b/src/zenserver/projectstore/projectstore.cpp index 40fd3d30b..38674d28d 100644 --- a/src/zenserver/projectstore/projectstore.cpp +++ b/src/zenserver/projectstore/projectstore.cpp @@ -435,26 +435,16 @@ ProjectStore::Oplog::ScrubStorage(ScrubContext& Ctx) const void ProjectStore::Oplog::GatherReferences(GcContext& GcCtx) { - RwLock::SharedLockScope _(m_OplogLock); - - std::vector<IoHash> Hashes; - Hashes.reserve(Max(m_ChunkMap.size(), m_MetaMap.size())); - - for (const auto& Kv : m_ChunkMap) - { - Hashes.push_back(Kv.second); - } - - GcCtx.AddRetainedCids(Hashes); + ZEN_TRACE_CPU("ProjectStore::Oplog::GatherReferences"); - Hashes.clear(); - - for (const auto& Kv : m_MetaMap) - { - Hashes.push_back(Kv.second); - } - - GcCtx.AddRetainedCids(Hashes); + std::unordered_set<IoHash> AttachmentHashes; + IterateOplog([&](CbObject Op) { + Op.IterateAttachments([&](CbFieldView Visitor) { + IoHash Attachment = Visitor.AsAttachment(); + AttachmentHashes.insert(Attachment); + }); + }); + GcCtx.AddRetainedCids(std::vector<IoHash>(AttachmentHashes.begin(), AttachmentHashes.end())); } uint64_t diff --git a/src/zenserver/projectstore/remoteprojectstore.cpp b/src/zenserver/projectstore/remoteprojectstore.cpp index 20acdf159..1abd18a5c 100644 --- a/src/zenserver/projectstore/remoteprojectstore.cpp +++ b/src/zenserver/projectstore/remoteprojectstore.cpp @@ -220,21 +220,28 @@ BuildContainer(CidStore& ChunkStore, size_t BlockSize = 0; std::vector<SharedBuffer> ChunksInBlock; - std::unordered_set<IoHash, IoHash::Hasher> Attachments; - Oplog.IterateOplog([&Attachments, &SectionOpsWriter, &OpCount](CbObject Op) { - Op.IterateAttachments([&](CbFieldView FieldView) { Attachments.insert(FieldView.AsAttachment()); }); + std::unordered_map<IoHash, int, IoHash::Hasher> Attachments; + Oplog.IterateOplogWithKey([&Attachments, &SectionOpsWriter, &OpCount](int LSN, const Oid&, CbObject Op) { + Op.IterateAttachments([&](CbFieldView FieldView) { Attachments.insert_or_assign(FieldView.AsAttachment(), LSN); }); (SectionOpsWriter) << Op; OpCount++; }); - for (const IoHash& AttachmentHash : Attachments) + for (const auto& It : Attachments) { - IoBuffer Payload = ChunkStore.FindChunkByCid(AttachmentHash); + const IoHash& AttachmentHash(It.first); + IoBuffer Payload = ChunkStore.FindChunkByCid(AttachmentHash); if (!Payload) { - RemoteResult.SetError(gsl::narrow<int>(HttpResponseCode::NotFound), - fmt::format("Failed to find attachment {} for op", AttachmentHash), - {}); + std::optional<CbObject> Op = Oplog.GetOpByIndex(It.second); + ZEN_ASSERT(Op.has_value()); + ExtendableStringBuilder<1024> Sb; + Sb.Append("Failed to find attachment '"); + Sb.Append(AttachmentHash.ToHexString()); + Sb.Append("' for op: \n"); + Op.value().ToJson(Sb); + + RemoteResult.SetError(gsl::narrow<int>(HttpResponseCode::NotFound), Sb.ToString(), {}); ZEN_ERROR("Failed to build container ({}). Reason: '{}'", RemoteResult.GetError(), RemoteResult.GetErrorReason()); BlockCreateLatch.CountDown(); |