diff options
| author | Stefan Boberg <[email protected]> | 2021-09-23 12:38:13 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-09-23 12:38:13 +0200 |
| commit | c20289a3bd781682b5ba6afebdaf228fb202f42c (patch) | |
| tree | 9680e0bf86594da457275ad70924c6eaa9866214 | |
| parent | Fixed dumb bug in CasChunkSet::IterateChunks which would cause infinite loop (diff) | |
| download | zen-c20289a3bd781682b5ba6afebdaf228fb202f42c.tar.xz zen-c20289a3bd781682b5ba6afebdaf228fb202f42c.zip | |
cidstore: made all updates log using LogMapping()
also fixed issue with FindChunkByCid() which would assert when it should not
| -rw-r--r-- | zenstore/cidstore.cpp | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/zenstore/cidstore.cpp b/zenstore/cidstore.cpp index 08a3192ff..d76058bd1 100644 --- a/zenstore/cidstore.cpp +++ b/zenstore/cidstore.cpp @@ -45,11 +45,23 @@ struct CidStore::Impl ZEN_ASSERT(Compressed != IoHash::Zero); RwLock::ExclusiveLockScope _(m_Lock); - m_CidMap.insert_or_assign(DecompressedId, Compressed); - // TODO: it's pretty wasteful to log even idempotent updates - // however we can't simply use the boolean returned by insert_or_assign - // since there's not a 1:1 mapping between compressed and uncompressed - // so if we want a last-write-wins policy then we have to log each update + + auto It = m_CidMap.try_emplace(DecompressedId, Compressed); + if (!It.second) + { + if (It.first.value() != Compressed) + { + It.first.value() = Compressed; + } + else + { + // No point logging an update that won't change anything + return; + } + } + + // It's not ideal to do this while holding the lock in case + // we end up in blocking I/O but that's for later LogMapping(DecompressedId, Compressed); } @@ -68,6 +80,10 @@ struct CidStore::Impl { CompressedHash = It->second; } + else + { + return {}; + } } ZEN_ASSERT(CompressedHash != IoHash::Zero); @@ -84,7 +100,7 @@ struct CidStore::Impl if (It == m_CidMap.end()) { - // Not in map, or tombstone + // Not in map return false; } @@ -171,7 +187,7 @@ struct CidStore::Impl const IoHash& BadHash = It->first; // Log a tombstone record - m_LogFile.Append({.Uncompressed = BadHash, .Compressed = IoHash::Zero}); + LogMapping(BadHash, IoHash::Zero); BadChunks.push_back(BadHash); |