aboutsummaryrefslogtreecommitdiff
path: root/zenserver/cache/structuredcachestore.cpp
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2022-05-25 14:17:59 +0200
committerDan Engelbrecht <[email protected]>2022-05-25 14:20:00 +0200
commit1a3709fd35f592b146d794835ab0e1a95ee078e0 (patch)
tree02aefdeda10c8ae58625f12e3b8e3ca459fe5afc /zenserver/cache/structuredcachestore.cpp
parentnamespace drop (diff)
downloadzen-1a3709fd35f592b146d794835ab0e1a95ee078e0.tar.xz
zen-1a3709fd35f592b146d794835ab0e1a95ee078e0.zip
clean up namespace folders
Diffstat (limited to 'zenserver/cache/structuredcachestore.cpp')
-rw-r--r--zenserver/cache/structuredcachestore.cpp78
1 files changed, 42 insertions, 36 deletions
diff --git a/zenserver/cache/structuredcachestore.cpp b/zenserver/cache/structuredcachestore.cpp
index 6af673ebc..aa3be3974 100644
--- a/zenserver/cache/structuredcachestore.cpp
+++ b/zenserver/cache/structuredcachestore.cpp
@@ -205,6 +205,36 @@ namespace {
return true;
}
+ bool MoveAndDeleteDirectory(const std::filesystem::path& Dir)
+ {
+ int DropIndex = 0;
+ do
+ {
+ if (!std::filesystem::exists(Dir))
+ {
+ return false;
+ }
+
+ std::string DroppedName = fmt::format("[dropped]{}({})", Dir.filename().string(), DropIndex);
+ std::filesystem::path DroppedBucketPath = Dir.parent_path() / DroppedName;
+ if (std::filesystem::exists(DroppedBucketPath))
+ {
+ DropIndex++;
+ continue;
+ }
+
+ std::error_code Ec;
+ std::filesystem::rename(Dir, DroppedBucketPath, Ec);
+ if (!Ec)
+ {
+ DeleteDirectories(DroppedBucketPath);
+ return true;
+ }
+ // TODO: Do we need to bail at some point?
+ zen::Sleep(100);
+ } while (true);
+ }
+
} // namespace
namespace fs = std::filesystem;
@@ -346,8 +376,11 @@ bool
ZenCacheNamespace::Drop()
{
m_MemLayer.Drop();
- const bool DiskDropped = m_DiskLayer.Drop();
- return DiskDropped;
+ if (!m_DiskLayer.Drop())
+ {
+ return false;
+ }
+ return MoveAndDeleteDirectory(m_RootDir);
}
void
@@ -1219,37 +1252,6 @@ ZenCacheDiskLayer::CacheBucket::Put(const IoHash& HashKey, const ZenCacheValue&
PutInlineCacheValue(HashKey, Value);
}
-static bool
-DeleteBucketFromDisk(const std::filesystem::path& BucketDir, std::string_view BucketName)
-{
- int DropIndex = 0;
- do
- {
- if (!std::filesystem::exists(BucketDir))
- {
- return false;
- }
-
- std::string DroppedBucketName = fmt::format("[dropped]{}({})", BucketName, DropIndex);
- std::filesystem::path DroppedBucketPath = BucketDir.parent_path() / DroppedBucketName;
- if (std::filesystem::exists(DroppedBucketPath))
- {
- DropIndex++;
- continue;
- }
-
- std::error_code Ec;
- std::filesystem::rename(BucketDir, DroppedBucketPath, Ec);
- if (!Ec)
- {
- DeleteDirectories(DroppedBucketPath);
- return true;
- }
- // TODO: Do we need to bail at some point?
- zen::Sleep(100);
- } while (true);
-}
-
bool
ZenCacheDiskLayer::CacheBucket::Drop()
{
@@ -1264,7 +1266,7 @@ ZenCacheDiskLayer::CacheBucket::Drop()
m_BlockStore.Close();
m_SlogFile.Close();
- bool Deleted = DeleteBucketFromDisk(m_BucketDir, m_BucketName);
+ bool Deleted = MoveAndDeleteDirectory(m_BucketDir);
m_Index.clear();
return Deleted;
@@ -2130,7 +2132,7 @@ ZenCacheDiskLayer::DropBucket(std::string_view InBucket)
// Make sure we remove the folder even if we don't know about the bucket
std::filesystem::path BucketPath = m_RootDir;
BucketPath /= std::string(InBucket);
- return DeleteBucketFromDisk(BucketPath, InBucket);
+ return MoveAndDeleteDirectory(BucketPath);
}
bool
@@ -2150,6 +2152,7 @@ ZenCacheDiskLayer::Drop()
{
return false;
}
+ return MoveAndDeleteDirectory(m_RootDir);
}
return true;
}
@@ -2321,7 +2324,10 @@ ZenCacheStore::DropNamespace(std::string_view InNamespace)
ZenCacheNamespace& Namespace = *It->second;
m_DroppedNamespaces.push_back(std::move(It->second));
m_Namespaces.erase(It);
- return Namespace.Drop();
+ if (!Namespace.Drop())
+ {
+ return false;
+ }
}
ZEN_WARN("request for unknown namespace '{}' in ZenCacheStore::DropNamespace", InNamespace);
return false;