From fd3946f2b2b013af01fdf60f67afb655c38c1901 Mon Sep 17 00:00:00 2001 From: Per Larsson Date: Tue, 31 Aug 2021 15:01:46 +0200 Subject: Asynchronous upstream caching to Jupiter Co-authored-by: Stefan Boberg --- zenstore/cidstore.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'zenstore/cidstore.cpp') diff --git a/zenstore/cidstore.cpp b/zenstore/cidstore.cpp index 3460e1df2..4e5188f1c 100644 --- a/zenstore/cidstore.cpp +++ b/zenstore/cidstore.cpp @@ -36,14 +36,29 @@ struct CidStore::CidState IoBuffer FindChunkByCid(const IoHash& DecompressedId) { - if (auto It = m_CidMap.find(DecompressedId); It != m_CidMap.end()) + IoHash CompressedHash; { - return m_CasStore.FindChunk(It->second); + RwLock::SharedLockScope _(m_Lock); + if (auto It = m_CidMap.find(DecompressedId); It != m_CidMap.end()) + { + CompressedHash = It->second; + } + } + + if (CompressedHash != IoHash::Zero) + { + return m_CasStore.FindChunk(CompressedHash); } return IoBuffer(); } + bool ContainsChunk(const IoHash& DecompressedId) + { + RwLock::SharedLockScope _(m_Lock); + return m_CidMap.find(DecompressedId) != m_CidMap.end(); + } + void InitializeIndex(const std::filesystem::path& RootDir) { zen::CreateDirectories(RootDir); @@ -84,6 +99,12 @@ CidStore::FindChunkByCid(const IoHash& DecompressedId) return m_Impl->FindChunkByCid(DecompressedId); } +bool +CidStore::ContainsChunk(const IoHash& DecompressedId) +{ + return m_Impl->ContainsChunk(DecompressedId); +} + void CidStore::Flush() { -- cgit v1.2.3