aboutsummaryrefslogtreecommitdiff
path: root/src/zenstore/filecas.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/zenstore/filecas.cpp')
-rw-r--r--src/zenstore/filecas.cpp19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/zenstore/filecas.cpp b/src/zenstore/filecas.cpp
index 428183827..0f3e2ab5a 100644
--- a/src/zenstore/filecas.cpp
+++ b/src/zenstore/filecas.cpp
@@ -729,19 +729,28 @@ FileCasStrategy::FindChunk(const IoHash& ChunkHash)
ZEN_ASSERT(m_IsInitialized);
+ uint64_t ExpectedSize = 0;
{
RwLock::SharedLockScope _(m_Lock);
- if (!m_Index.contains(ChunkHash))
+ if (auto It = m_Index.find(ChunkHash); It != m_Index.end())
+ {
+ ExpectedSize = It->second.Size;
+ }
+ else
{
return {};
}
}
- ShardingHelper Name(m_RootDirectory.c_str(), ChunkHash);
-
+ ShardingHelper Name(m_RootDirectory.c_str(), ChunkHash);
RwLock::SharedLockScope _(LockForHash(ChunkHash));
- return IoBufferBuilder::MakeFromFile(Name.ShardedPath.c_str());
+ if (IoBuffer Chunk = IoBufferBuilder::MakeFromFile(Name.ShardedPath.c_str()); Chunk.GetSize() == ExpectedSize)
+ {
+ return Chunk;
+ }
+
+ return {};
}
bool
@@ -1201,7 +1210,7 @@ FileCasStrategy::MakeIndexSnapshot()
EntryCount = Entries.size();
m_LogFlushPosition = IndexLogPosition;
}
- catch (std::exception& Err)
+ catch (const std::exception& Err)
{
ZEN_WARN("snapshot FAILED, reason: '{}'", Err.what());