diff options
Diffstat (limited to 'src/zenstore/compactcas.cpp')
| -rw-r--r-- | src/zenstore/compactcas.cpp | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/src/zenstore/compactcas.cpp b/src/zenstore/compactcas.cpp index 5d8f95c9e..43dc389e2 100644 --- a/src/zenstore/compactcas.cpp +++ b/src/zenstore/compactcas.cpp @@ -153,7 +153,7 @@ CasContainerStrategy::~CasContainerStrategy() } catch (const std::exception& Ex) { - ZEN_ERROR("~CasContainerStrategy failed with: ", Ex.what()); + ZEN_ERROR("~CasContainerStrategy failed with: {}", Ex.what()); } m_Gc.RemoveGcReferenceStore(*this); m_Gc.RemoveGcStorage(this); @@ -440,9 +440,9 @@ CasContainerStrategy::IterateChunks(std::span<const IoHash> ChunkHas return true; } - std::atomic<bool> AbortFlag; + std::atomic<bool> AbortFlag{false}; { - std::atomic<bool> PauseFlag; + std::atomic<bool> PauseFlag{false}; ParallelWork Work(AbortFlag, PauseFlag, WorkerThreadPool::EMode::DisableBacklog); try { @@ -559,8 +559,8 @@ CasContainerStrategy::ScrubStorage(ScrubContext& Ctx) std::vector<BlockStoreLocation> ChunkLocations; std::vector<IoHash> ChunkIndexToChunkHash; - std::atomic<bool> Abort; - std::atomic<bool> Pause; + std::atomic<bool> Abort{false}; + std::atomic<bool> Pause{false}; ParallelWork Work(Abort, Pause, WorkerThreadPool::EMode::DisableBacklog); try @@ -1007,7 +1007,7 @@ CasContainerStrategy::CompactIndex(RwLock::ExclusiveLockScope&) std::vector<BlockStoreDiskLocation> Locations; Locations.reserve(EntryCount); LocationMap.reserve(EntryCount); - for (auto It : m_LocationMap) + for (const auto& It : m_LocationMap) { size_t EntryIndex = Locations.size(); Locations.push_back(m_Locations[It.second]); @@ -1106,7 +1106,7 @@ CasContainerStrategy::MakeIndexSnapshot(bool ResetLog) { // This is non-critical, it only means that we will replay the events of the log over the snapshot - inefficent but in // the end it will be the same result - ZEN_WARN("Snapshot failed to clean log file '{}', reason: '{}'", LogPath, IndexPath, Ec.message()); + ZEN_WARN("Snapshot failed to clean log file '{}', reason: '{}'", LogPath, Ec.message()); } m_CasLog.Open(LogPath, CasLogFile::Mode::kWrite); } @@ -1136,7 +1136,7 @@ CasContainerStrategy::ReadIndexFile(const std::filesystem::path& IndexPath, uint uint64_t Size = ObjectIndexFile.FileSize(); if (Size >= sizeof(CasDiskIndexHeader)) { - uint64_t ExpectedEntryCount = (Size - sizeof(sizeof(CasDiskIndexHeader))) / sizeof(CasDiskIndexEntry); + uint64_t ExpectedEntryCount = (Size - sizeof(CasDiskIndexHeader)) / sizeof(CasDiskIndexEntry); CasDiskIndexHeader Header; ObjectIndexFile.Read(&Header, sizeof(Header), 0); if ((Header.Magic == CasDiskIndexHeader::ExpectedMagic) && (Header.Version == CasDiskIndexHeader::CurrentVersion) && @@ -1348,6 +1348,8 @@ CasContainerStrategy::OpenContainer(bool IsNewStore) #if ZEN_WITH_TESTS +TEST_SUITE_BEGIN("store.compactcas"); + TEST_CASE("compactcas.hex") { uint32_t Value; @@ -1927,19 +1929,26 @@ TEST_CASE("compactcas.restart") ValidateChunks(Cas, Hashes, true); if (true) { - std::vector<IoHash> DropHashes; - std::vector<IoHash> KeepHashes; + std::vector<IoHash> DropHashes; + std::vector<IoHash> KeepHashes; + tsl::robin_set<IoHash, IoHash::Hasher> KeepSet; for (size_t Index = 0; Index < Hashes.size(); Index++) { if (Index % 5 == 0) { KeepHashes.push_back(Hashes[Index]); + KeepSet.insert(Hashes[Index]); } else { DropHashes.push_back(Hashes[Index]); } } + // Remove any hash from DropHashes that also appears in KeepHashes. + // CreateSemiRandomBlob uses a thread_local PRNG with a fixed seed, + // so different GenerateChunks calls can produce duplicate hashes + // when threads hit the same PRNG state with the same blob size. + std::erase_if(DropHashes, [&KeepSet](const IoHash& H) { return KeepSet.contains(H); }); // std::span<const IoHash> KeepHashes(Hashes); // ZEN_ASSERT(ExpectedGcCount < Hashes.size()); // KeepHashes = KeepHashes.subspan(ExpectedGcCount); @@ -2159,6 +2168,8 @@ TEST_CASE("compactcas.iteratechunks") } } +TEST_SUITE_END(); + #endif void |