aboutsummaryrefslogtreecommitdiff
path: root/zenstore/compactcas.cpp
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2022-03-25 12:19:56 +0100
committerDan Engelbrecht <[email protected]>2022-03-31 11:29:27 +0200
commit72ce488dabb1b4ca1c5f83a4397c79f1165aae84 (patch)
tree5f8aa1bde9e83ceb5da917879425dd85d6ca3396 /zenstore/compactcas.cpp
parentincremental migration with optional clean of source (diff)
downloadzen-72ce488dabb1b4ca1c5f83a4397c79f1165aae84.tar.xz
zen-72ce488dabb1b4ca1c5f83a4397c79f1165aae84.zip
caslog represents what's on disk, not memory state
Diffstat (limited to 'zenstore/compactcas.cpp')
-rw-r--r--zenstore/compactcas.cpp18
1 files changed, 9 insertions, 9 deletions
diff --git a/zenstore/compactcas.cpp b/zenstore/compactcas.cpp
index e389adb84..eb99dd3ba 100644
--- a/zenstore/compactcas.cpp
+++ b/zenstore/compactcas.cpp
@@ -600,16 +600,16 @@ CasContainerStrategy::InsertChunk(const void* ChunkData, size_t ChunkSize, const
WriteBlock = m_WriteBlock;
}
- WriteBlock->Write(ChunkData, ChunkSize, InsertOffset);
-
BlockStoreDiskLocation Location({.BlockIndex = WriteBlockIndex, .Offset = InsertOffset, .Size = ChunkSize}, m_PayloadAlignment);
const CasDiskIndexEntry IndexEntry{.Key = ChunkHash, .Location = Location};
+ WriteBlock->Write(ChunkData, ChunkSize, InsertOffset);
+ m_CasLog.Append(IndexEntry);
+
m_TotalSize.fetch_add(static_cast<uint64_t>(ChunkSize), std::memory_order_release);
{
RwLock::ExclusiveLockScope __(m_LocationMapLock);
m_LocationMap.emplace(ChunkHash, Location);
- m_CasLog.Append(IndexEntry);
}
return CasStore::InsertResult{.New = true};
@@ -735,7 +735,7 @@ CasContainerStrategy::Scrub(ScrubContext& Ctx)
if (Entry.first != ComputedHash)
{
// Hash mismatch
- BadChunks.push_back({.Key = Entry.first, .Location = Entry.second});
+ BadChunks.push_back({.Key = Entry.first, .Location = Entry.second, .Flags = CasDiskIndexEntry::kTombstone});
}
}
}
@@ -757,7 +757,7 @@ CasContainerStrategy::Scrub(ScrubContext& Ctx)
if (Entry.Key != ComputedHash)
{
- BadChunks.push_back(Entry);
+ BadChunks.push_back({.Key = Entry.Key, .Location = Entry.Location, .Flags = CasDiskIndexEntry::kTombstone});
}
}
}
@@ -774,13 +774,13 @@ CasContainerStrategy::Scrub(ScrubContext& Ctx)
std::vector<IoHash> BadChunkHashes;
BadChunkHashes.reserve(BadChunks.size());
+ m_CasLog.Append(BadChunks);
{
RwLock::ExclusiveLockScope _(m_LocationMapLock);
for (const CasDiskIndexEntry& Entry : BadChunks)
{
BadChunkHashes.push_back(Entry.Key);
m_LocationMap.erase(Entry.Key);
- m_CasLog.Append({.Key = Entry.Key, .Location = Entry.Location, .Flags = CasDiskIndexEntry::kTombstone});
}
}
@@ -1001,12 +1001,12 @@ CasContainerStrategy::CollectGarbage(GcContext& GcCtx)
{
const auto& DeleteMap = DeleteChunks[ChunkMapIndex];
auto LogEntries = MakeCasDiskEntries({}, DeleteMap);
+ m_CasLog.Append(LogEntries);
{
RwLock::ExclusiveLockScope _i(m_LocationMapLock);
Stopwatch Timer;
const auto TimerGuard = MakeGuard([&Timer, &ReadBlockTimeUs] { ReadBlockTimeUs += Timer.GetElapsedTimeUs(); });
UpdateLocations(LogEntries);
- m_CasLog.Append(LogEntries);
m_ChunkBlocks[BlockIndex].reset();
}
DeletedChunks.insert(DeletedChunks.end(), DeleteMap.begin(), DeleteMap.end());
@@ -1034,12 +1034,12 @@ CasContainerStrategy::CollectGarbage(GcContext& GcCtx)
{
uint32_t NextBlockIndex = m_WriteBlockIndex.load(std::memory_order::memory_order_relaxed);
auto LogEntries = MakeCasDiskEntries(MovedBlockChunks, {});
+ m_CasLog.Append(LogEntries);
{
RwLock::ExclusiveLockScope _l(m_LocationMapLock);
Stopwatch Timer;
const auto TimerGuard = MakeGuard([&Timer, &ReadBlockTimeUs] { ReadBlockTimeUs += Timer.GetElapsedTimeUs(); });
UpdateLocations(LogEntries);
- m_CasLog.Append(LogEntries);
if (m_ChunkBlocks.size() == BlockStoreDiskLocation::MaxBlockIndex)
{
ZEN_ERROR("unable to allocate a new block in {}, count limit {} exeeded",
@@ -1108,12 +1108,12 @@ CasContainerStrategy::CollectGarbage(GcContext& GcCtx)
const auto& DeleteMap = DeleteChunks[ChunkMapIndex];
auto LogEntries = MakeCasDiskEntries(MovedBlockChunks, DeleteMap);
+ m_CasLog.Append(LogEntries);
{
RwLock::ExclusiveLockScope _i(m_LocationMapLock);
Stopwatch Timer;
const auto TimerGuard = MakeGuard([&Timer, &ReadBlockTimeUs] { ReadBlockTimeUs += Timer.GetElapsedTimeUs(); });
UpdateLocations(LogEntries);
- m_CasLog.Append(LogEntries);
m_ChunkBlocks[BlockIndex].reset();
}
MovedCount += MovedBlockChunks.size();