diff options
| author | Stefan Boberg <[email protected]> | 2021-08-23 19:12:14 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-08-23 19:12:14 +0200 |
| commit | 9497ba8cba4347112e4335ca02d143aec8a45f24 (patch) | |
| tree | 7c625a69063fc6aecbc4eb6384d5a561ce94e3ad /zenstore/filecas.cpp | |
| parent | Improved ZenCacheStore::DropBucket logic and added logging (diff) | |
| download | zen-9497ba8cba4347112e4335ca02d143aec8a45f24.tar.xz zen-9497ba8cba4347112e4335ca02d143aec8a45f24.zip | |
Implemented more formalised CAS chunk filtering (with plenty of room for optimization)
Diffstat (limited to 'zenstore/filecas.cpp')
| -rw-r--r-- | zenstore/filecas.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/zenstore/filecas.cpp b/zenstore/filecas.cpp index 04a6f7aa0..cddf22503 100644 --- a/zenstore/filecas.cpp +++ b/zenstore/filecas.cpp @@ -279,6 +279,45 @@ FileCasStrategy::FindChunk(const IoHash& ChunkHash) return Chunk; } +bool +FileCasStrategy::HaveChunk(const IoHash& ChunkHash) +{ + size_t Shard2len = 0; + ExtendableWideStringBuilder<128> ShardedPath; + ShardedPath.Append(m_Config.RootDirectory.c_str()); + ShardedPath.Append(std::filesystem::path::preferred_separator); + MakeShardedPath(ShardedPath, ChunkHash, /* out */ Shard2len); + + RwLock::SharedLockScope _(LockForHash(ChunkHash)); + + std::error_code Ec; + if (std::filesystem::exists(ShardedPath.c_str(), Ec)) + { + return true; + } + + return false; +} + +void +FileCasStrategy::FilterChunks(CasChunkSet& InOutChunks) +{ + std::unordered_set<IoHash> HaveSet; + + for (const IoHash& Hash : InOutChunks.GetChunkSet()) + { + if (HaveChunk(Hash)) + { + HaveSet.insert(Hash); + } + } + + for (const IoHash& Hash : HaveSet) + { + InOutChunks.RemoveIfPresent(Hash); + } +} + void FileCasStrategy::Flush() { |