diff options
| author | Stefan Boberg <[email protected]> | 2021-11-01 18:36:00 +0100 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-11-01 18:36:00 +0100 |
| commit | 3e7d92fd42b57d8e437f92f86eed7905d9dcf85d (patch) | |
| tree | 7d77b7e6968471ec6366612ac8968f58a3c47b74 | |
| parent | caslog: Added GetLogSize, fixed issue with append offset computation (diff) | |
| download | zen-3e7d92fd42b57d8e437f92f86eed7905d9dcf85d.tar.xz zen-3e7d92fd42b57d8e437f92f86eed7905d9dcf85d.zip | |
cidstore: implemented validation of data during index initialization
| -rw-r--r-- | zenstore/cidstore.cpp | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/zenstore/cidstore.cpp b/zenstore/cidstore.cpp index 7a5d7bcf4..eaad0f5a8 100644 --- a/zenstore/cidstore.cpp +++ b/zenstore/cidstore.cpp @@ -4,7 +4,9 @@ #include <zencore/compress.h> #include <zencore/filesystem.h> +#include <zencore/fmtutils.h> #include <zencore/logging.h> +#include <zencore/string.h> #include <zenstore/CAS.h> #include <zenstore/caslog.h> @@ -65,9 +67,10 @@ struct CidStore::Impl LogMapping(DecompressedId, Compressed); } - void LogMapping(const IoHash& DecompressedId, const IoHash& Compressed) + void LogMapping(const IoHash& DecompressedId, const IoHash& CompressedHash) { - m_LogFile.Append({.Uncompressed = DecompressedId, .Compressed = Compressed}); + ZEN_ASSERT(DecompressedId != CompressedHash); + m_LogFile.Append({.Uncompressed = DecompressedId, .Compressed = CompressedHash}); } IoBuffer FindChunkByCid(const IoHash& DecompressedId) @@ -118,23 +121,35 @@ struct CidStore::Impl m_LogFile.Open(SlogPath, IsNew); + ZEN_DEBUG("Initializing index from '{}' ({})", SlogPath, NiceBytes(m_LogFile.GetLogSize())); + uint64_t TombstoneCount = 0; + uint64_t InvalidCount = 0; - m_LogFile.Replay([&](const IndexEntry& Ie) { - if (Ie.Compressed != IoHash::Zero) + m_LogFile.Replay([&](const IndexEntry& Entry) { + if (Entry.Compressed != IoHash::Zero) { // Update - m_CidMap.insert_or_assign(Ie.Uncompressed, Ie.Compressed); + m_CidMap.insert_or_assign(Entry.Uncompressed, Entry.Compressed); } else { - // Tombstone - m_CidMap.erase(Ie.Uncompressed); - ++TombstoneCount; + if (Entry.Uncompressed != IoHash::Zero) + { + // Tombstone + m_CidMap.erase(Entry.Uncompressed); + ++TombstoneCount; + } + else + { + // Completely uninitialized entry with both hashes set to zero indicates a + // problem. Might be an unwritten page due to BSOD or some other problem + ++InvalidCount; + } } }); - ZEN_INFO("CID index initialized: {} entries found ({} tombstones)", m_CidMap.size(), TombstoneCount); + ZEN_INFO("CID index initialized: {} entries found ({} tombstones, {} invalid)", m_CidMap.size(), TombstoneCount, InvalidCount); } void Flush() { m_LogFile.Flush(); } |