diff options
| author | Dan Engelbrecht <[email protected]> | 2022-04-06 08:42:24 +0200 |
|---|---|---|
| committer | Dan Engelbrecht <[email protected]> | 2022-04-06 08:42:24 +0200 |
| commit | 99f5dc615227de982422ccc8f51d90ce999f8005 (patch) | |
| tree | 0589595ed1c31b10c7f69a20068c5fe6771c276e /zenstore/compactcas.cpp | |
| parent | fix migration when entries is out of data file range (diff) | |
| download | zen-99f5dc615227de982422ccc8f51d90ce999f8005.tar.xz zen-99f5dc615227de982422ccc8f51d90ce999f8005.zip | |
Only validate range of legacy entries on kept entries
Diffstat (limited to 'zenstore/compactcas.cpp')
| -rw-r--r-- | zenstore/compactcas.cpp | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/zenstore/compactcas.cpp b/zenstore/compactcas.cpp index a28068d24..ee51cdf5e 100644 --- a/zenstore/compactcas.cpp +++ b/zenstore/compactcas.cpp @@ -1147,6 +1147,7 @@ CasContainerStrategy::MigrateLegacyData(bool CleanSource) BlockFile.Open(LegacySobsPath, CleanSource ? BasicFile::Mode::kWrite : BasicFile::Mode::kRead); std::unordered_map<IoHash, LegacyCasDiskIndexEntry, IoHash::Hasher> LegacyDiskIndex; + uint64_t InvalidEntryCount = 0; TCasLogFile<LegacyCasDiskIndexEntry> LegacyCasLog; LegacyCasLog.Open(LegacyLogPath, CleanSource ? CasLogFile::Mode::kWrite : CasLogFile::Mode::kRead); @@ -1160,7 +1161,6 @@ CasContainerStrategy::MigrateLegacyData(bool CleanSource) }); if (LegacyCasLog.Initialize()) { - uint64_t BlockFileSize = BlockFile.FileSize(); LegacyDiskIndex.reserve(LegacyCasLog.GetLogCount()); LegacyCasLog.Replay( [&](const LegacyCasDiskIndexEntry& Record) { @@ -1173,23 +1173,38 @@ CasContainerStrategy::MigrateLegacyData(bool CleanSource) if (!ValidateLegacyEntry(Record, InvalidEntryReason)) { ZEN_WARN("skipping invalid entry in '{}', reason: '{}'", LegacyLogPath, InvalidEntryReason); + InvalidEntryCount++; return; } - if (Record.Location.GetOffset() + Record.Location.GetSize() > BlockFileSize) - { - ZEN_WARN("skipping invalid entry in '{}', reason: location is outside of file", LegacyLogPath); - return; - } - if (m_LocationMap.contains(Record.Key)) - { - return; - } - LegacyDiskIndex[Record.Key] = Record; + LegacyDiskIndex.insert_or_assign(Record.Key, Record); }, 0); + + std::vector<IoHash> BadEntries; + uint64_t BlockFileSize = BlockFile.FileSize(); + for (const auto& Entry : LegacyDiskIndex) + { + const LegacyCasDiskIndexEntry& Record(Entry.second); + if (Record.Location.GetOffset() + Record.Location.GetSize() <= BlockFileSize) + { + continue; + } + ZEN_WARN("skipping invalid entry in '{}', reason: location is outside of file", LegacyLogPath); + BadEntries.push_back(Entry.first); + } + for (const IoHash& BadHash : BadEntries) + { + LegacyDiskIndex.erase(BadHash); + } + InvalidEntryCount += BadEntries.size(); } } + if (InvalidEntryCount) + { + ZEN_WARN("found #{} invalid entries in '{}'", InvalidEntryCount, m_Config.RootDirectory / m_ContainerBaseName); + } + if (LegacyDiskIndex.empty()) { BlockFile.Close(); |