aboutsummaryrefslogtreecommitdiff
path: root/src/zenserver/projectstore/projectstore.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2024-12-13 11:59:13 +0100
committerStefan Boberg <[email protected]>2024-12-13 11:59:13 +0100
commit6512c8214676662180a62d89a1aebb7b53df5e9b (patch)
treedd40a36dd89564d7f93df8a50fb880fb4438e559 /src/zenserver/projectstore/projectstore.cpp
parentadded xxhash unit tests (which currently fail) (diff)
downloadzen-6512c8214676662180a62d89a1aebb7b53df5e9b.tar.xz
zen-6512c8214676662180a62d89a1aebb7b53df5e9b.zip
added ComputeOpKey so all instances of mapping key -> Oid is in a single place
Diffstat (limited to 'src/zenserver/projectstore/projectstore.cpp')
-rw-r--r--src/zenserver/projectstore/projectstore.cpp39
1 files changed, 19 insertions, 20 deletions
diff --git a/src/zenserver/projectstore/projectstore.cpp b/src/zenserver/projectstore/projectstore.cpp
index 63a80fbd8..d153e7274 100644
--- a/src/zenserver/projectstore/projectstore.cpp
+++ b/src/zenserver/projectstore/projectstore.cpp
@@ -407,6 +407,21 @@ namespace {
//////////////////////////////////////////////////////////////////////////
+Oid
+ComputeOpKey(const CbObjectView& Op)
+{
+ using namespace std::literals;
+
+ XXH3_128Stream KeyHasher;
+ Op["key"sv].WriteToStream([&](const void* Data, size_t Size) { KeyHasher.Append(Data, Size); });
+ XXH3_128 KeyHash128 = KeyHasher.GetHash();
+
+ Oid KeyHash;
+ memcpy(&KeyHash, KeyHash128.Hash, sizeof KeyHash);
+
+ return KeyHash;
+}
+
struct ProjectStore::OplogStorage : public RefCounted
{
OplogStorage(ProjectStore::Oplog* OwnerOplog, std::filesystem::path BasePath) : m_OwnerOplog(OwnerOplog), m_OplogStoragePath(BasePath)
@@ -900,10 +915,7 @@ struct ProjectStore::OplogStorage : public RefCounted
ZEN_ASSERT(WriteSize != 0);
- XXH3_128Stream KeyHasher;
- Core["key"sv].WriteToStream([&](const void* Data, size_t Size) { KeyHasher.Append(Data, Size); });
- XXH3_128 KeyHash128 = KeyHasher.GetHash();
- memcpy(&OpData.KeyHash, KeyHash128.Hash, sizeof OpData.KeyHash);
+ OpData.KeyHash = ComputeOpKey(Core);
return OpData;
}
@@ -1107,11 +1119,7 @@ ProjectStore::Oplog::ScrubStorage(ScrubContext& Ctx)
Op.IterateAttachments([&](CbFieldView Visitor) { Cids.emplace_back(Visitor.AsAttachment()); });
{
- XXH3_128Stream KeyHasher;
- Op["key"sv].WriteToStream([&](const void* Data, size_t Size) { KeyHasher.Append(Data, Size); });
- XXH3_128 KeyHash128 = KeyHasher.GetHash();
- Oid KeyHash;
- memcpy(&KeyHash, KeyHash128.Hash, sizeof KeyHash);
+ const Oid KeyHash = ComputeOpKey(Op);
ZEN_ASSERT_FORMAT(KeyHash == Key, "oplog data does not match information from index (op:{} != index:{})", KeyHash, Key);
}
@@ -2366,11 +2374,7 @@ ProjectStore::Oplog::GetAttachmentsLocked(std::vector<IoHash>& OutAttachments, b
Op.IterateAttachments([&](CbFieldView Visitor) { OutAttachments.emplace_back(Visitor.AsAttachment()); });
if (StoreMetaDataOnDisk)
{
- XXH3_128Stream KeyHasher;
- Op["key"sv].WriteToStream([&](const void* Data, size_t Size) { KeyHasher.Append(Data, Size); });
- XXH3_128 KeyHash128 = KeyHasher.GetHash();
- Oid KeyHash;
- memcpy(&KeyHash, KeyHash128.Hash, sizeof KeyHash);
+ const Oid KeyHash = ComputeOpKey(Op);
Keys.push_back(KeyHash);
AttachmentCounts.push_back(gsl::narrow<uint32_t>(OutAttachments.size() - CurrentAttachmentCount));
}
@@ -6541,12 +6545,7 @@ OpKeyStringAsOid(std::string_view OpKey)
CbObjectWriter Writer;
Writer << "key"sv << OpKey;
- XXH3_128Stream KeyHasher;
- Writer.Save()["key"sv].WriteToStream([&](const void* Data, size_t Size) { KeyHasher.Append(Data, Size); });
- XXH3_128 KeyHash = KeyHasher.GetHash();
-
- Oid OpId;
- memcpy(OpId.OidBits, &KeyHash, sizeof(OpId.OidBits));
+ const Oid OpId = ComputeOpKey(Writer.Save());
return OpId;
}