diff options
| author | Per Larsson <[email protected]> | 2021-08-31 15:01:46 +0200 |
|---|---|---|
| committer | Per Larsson <[email protected]> | 2021-08-31 15:16:22 +0200 |
| commit | fd3946f2b2b013af01fdf60f67afb655c38c1901 (patch) | |
| tree | eca4abed5d71a157e185699f4e9668a92b756ca8 /zenstore/cidstore.cpp | |
| parent | Removed unused packages from vcpkg.json (diff) | |
| download | zen-fd3946f2b2b013af01fdf60f67afb655c38c1901.tar.xz zen-fd3946f2b2b013af01fdf60f67afb655c38c1901.zip | |
Asynchronous upstream caching to Jupiter
Co-authored-by: Stefan Boberg <[email protected]>
Diffstat (limited to 'zenstore/cidstore.cpp')
| -rw-r--r-- | zenstore/cidstore.cpp | 25 |
1 files changed, 23 insertions, 2 deletions
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() { |