From 9deb4d7904deff765e034c2528dfca93b6cdb714 Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Tue, 17 Aug 2021 15:18:37 +0200 Subject: Implemented support for dropping z$ buckets while online --- zenserver/cache/structuredcachestore.cpp | 67 ++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) (limited to 'zenserver/cache/structuredcachestore.cpp') 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() { @@ -153,6 +161,16 @@ ZenCacheMemoryLayer::Put(std::string_view InBucket, const zen::IoHash& HashKey, Bucket->Put(HashKey, Value); } +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) { @@ -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) { @@ -436,6 +469,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() { @@ -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() { -- cgit v1.2.3