From a19eee841d7ce0c9c868dced40a6380f55cdb9bd Mon Sep 17 00:00:00 2001 From: Dan Engelbrecht Date: Tue, 3 May 2022 23:04:45 +0200 Subject: handle that more than one block can be written to in parallel --- zenstore/compactcas.cpp | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) (limited to 'zenstore/compactcas.cpp') diff --git a/zenstore/compactcas.cpp b/zenstore/compactcas.cpp index 7cc742beb..cc0e2241c 100644 --- a/zenstore/compactcas.cpp +++ b/zenstore/compactcas.cpp @@ -250,15 +250,16 @@ CasContainerStrategy::InsertChunk(const void* ChunkData, size_t ChunkSize, const // This should be a rare occasion and the current flow reduces the time we block for // reads, insert and GC. - BlockStoreLocation Location = m_BlockStore.WriteChunk(ChunkData, ChunkSize, m_PayloadAlignment); - BlockStoreDiskLocation DiskLocation(Location, m_PayloadAlignment); - const CasDiskIndexEntry IndexEntry{.Key = ChunkHash, .Location = DiskLocation}; - m_CasLog.Append(IndexEntry); - { - RwLock::ExclusiveLockScope _(m_LocationMapLock); - m_LocationMap.emplace(ChunkHash, DiskLocation); - } - m_TotalSize.fetch_add(static_cast(ChunkSize), std::memory_order::relaxed); + m_BlockStore.WriteChunk(ChunkData, ChunkSize, m_PayloadAlignment, [&](const BlockStoreLocation& Location) { + BlockStoreDiskLocation DiskLocation(Location, m_PayloadAlignment); + const CasDiskIndexEntry IndexEntry{.Key = ChunkHash, .Location = DiskLocation}; + m_CasLog.Append(IndexEntry); + { + RwLock::ExclusiveLockScope _(m_LocationMapLock); + m_LocationMap.emplace(ChunkHash, DiskLocation); + } + m_TotalSize.fetch_add(static_cast(ChunkSize), std::memory_order::relaxed); + }); return CasStore::InsertResult{.New = true}; } @@ -1685,7 +1686,7 @@ TEST_CASE("compactcas.legacyconversion") } } -TEST_CASE("compactcas.threadedinsert") // * doctest::skip(true)) +TEST_CASE("compactcas.threadedinsert") { // for (uint32_t i = 0; i < 100; ++i) { @@ -1887,13 +1888,7 @@ TEST_CASE("compactcas.threadedinsert") // * doctest::skip(true)) { ThreadPool.ScheduleWork([&Cas, &WorkCompleted, ChunkHash]() { CHECK(Cas.HaveChunk(ChunkHash)); - if (ChunkHash != IoHash::HashBuffer(Cas.FindChunk(ChunkHash))) - { - IoBuffer Buffer = Cas.FindChunk(ChunkHash); - CHECK(Buffer); - IoHash BufferHash = IoHash::HashBuffer(Buffer); - CHECK(ChunkHash == BufferHash); - } + CHECK(ChunkHash == IoHash::HashBuffer(Cas.FindChunk(ChunkHash))); WorkCompleted.fetch_add(1); }); } -- cgit v1.2.3