aboutsummaryrefslogtreecommitdiff
path: root/src/zenserver/projectstore/remoteprojectstore.cpp
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2023-08-18 10:39:33 +0200
committerGitHub <[email protected]>2023-08-18 10:39:33 +0200
commitb1b30c7cdd9d39b42827b941a100d4f2418426c2 (patch)
tree93acdbfca75bd26a6c5dc13d3cdc8fcbc43d3200 /src/zenserver/projectstore/remoteprojectstore.cpp
parentCache process handles for FormatPackageMessage (#360) (diff)
downloadzen-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/zenserver/projectstore/remoteprojectstore.cpp')
-rw-r--r--src/zenserver/projectstore/remoteprojectstore.cpp23
1 files changed, 15 insertions, 8 deletions
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();