diff options
Diffstat (limited to 'zenserver/cache/structuredcachestore.cpp')
| -rw-r--r-- | zenserver/cache/structuredcachestore.cpp | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/zenserver/cache/structuredcachestore.cpp b/zenserver/cache/structuredcachestore.cpp index 9ed3cf53e..e6eda05aa 100644 --- a/zenserver/cache/structuredcachestore.cpp +++ b/zenserver/cache/structuredcachestore.cpp @@ -81,6 +81,14 @@ ZenCacheStore::Put(std::string_view InBucket, const zen::IoHash& HashKey, const } } +bool +ZenCacheStore::DropBucket(std::string_view Bucket) +{ + // TODO: should ensure this is done atomically across all layers + + return m_MemLayer.DropBucket(Bucket) && m_DiskLayer.DropBucket(Bucket); +} + void ZenCacheStore::Flush() { @@ -154,6 +162,16 @@ ZenCacheMemoryLayer::Put(std::string_view InBucket, const zen::IoHash& HashKey, } bool +ZenCacheMemoryLayer::DropBucket(std::string_view Bucket) +{ + RwLock::ExclusiveLockScope _(m_Lock); + + m_Buckets.erase(std::string(Bucket)); + + return true; +} + +bool ZenCacheMemoryLayer::CacheBucket::Get(const zen::IoHash& HashKey, ZenCacheValue& OutValue) { RwLock::SharedLockScope _(m_bucketLock); @@ -216,9 +234,11 @@ struct ZenCacheDiskLayer::CacheBucket ~CacheBucket(); void OpenOrCreate(std::filesystem::path BucketDir); + static bool Delete(std::filesystem::path BucketDir); bool Get(const zen::IoHash& HashKey, ZenCacheValue& OutValue); void Put(const zen::IoHash& HashKey, const ZenCacheValue& Value); + void Drop(); void Flush(); inline bool IsOk() const { return m_Ok; } @@ -249,6 +269,19 @@ ZenCacheDiskLayer::CacheBucket::~CacheBucket() { } +bool +ZenCacheDiskLayer::CacheBucket::Delete(std::filesystem::path BucketDir) +{ + if (std::filesystem::exists(BucketDir)) + { + zen::DeleteDirectories(BucketDir); + + return true; + } + + return false; +} + void ZenCacheDiskLayer::CacheBucket::OpenOrCreate(std::filesystem::path BucketDir) { @@ -437,6 +470,16 @@ ZenCacheDiskLayer::CacheBucket::Put(const zen::IoHash& HashKey, const ZenCacheVa } void +ZenCacheDiskLayer::CacheBucket::Drop() +{ + // TODO: add error handling + + m_SobsFile.Close(); + m_SlogFile.Close(); + zen::DeleteDirectories(m_BucketDir); +} + +void ZenCacheDiskLayer::CacheBucket::Flush() { m_SobsFile.Flush(); @@ -584,6 +627,30 @@ ZenCacheDiskLayer::Put(std::string_view InBucket, const zen::IoHash& HashKey, co } } +bool +ZenCacheDiskLayer::DropBucket(std::string_view InBucket) +{ + zen::RwLock::ExclusiveLockScope _(m_Lock); + + auto it = m_Buckets.find(std::string(InBucket)); + + if (it != m_Buckets.end()) + { + CacheBucket* Bucket = &it->second; + + Bucket->Drop(); + + m_Buckets.erase(it); + + return true; + } + + std::filesystem::path BucketPath = m_RootDir; + BucketPath /= std::string(InBucket); + + return CacheBucket::Delete(BucketPath); +} + void ZenCacheDiskLayer::Flush() { |