aboutsummaryrefslogtreecommitdiff
path: root/zenserver/cache/structuredcachestore.cpp
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2022-05-25 12:34:51 +0200
committerDan Engelbrecht <[email protected]>2022-05-25 12:35:50 +0200
commit49ad6da1f77daa8c91a087046d82ab78d2e41314 (patch)
tree0c46104a0e204b07c25bbe280043348f2313f7e3 /zenserver/cache/structuredcachestore.cpp
parentdrop bucket test (diff)
downloadzen-49ad6da1f77daa8c91a087046d82ab78d2e41314.tar.xz
zen-49ad6da1f77daa8c91a087046d82ab78d2e41314.zip
If a bucket is in m_BucketMap it is OK, no need for separate flag
Diffstat (limited to 'zenserver/cache/structuredcachestore.cpp')
-rw-r--r--zenserver/cache/structuredcachestore.cpp77
1 files changed, 21 insertions, 56 deletions
diff --git a/zenserver/cache/structuredcachestore.cpp b/zenserver/cache/structuredcachestore.cpp
index f3f6503f3..bb85f9824 100644
--- a/zenserver/cache/structuredcachestore.cpp
+++ b/zenserver/cache/structuredcachestore.cpp
@@ -572,7 +572,7 @@ ZenCacheMemoryLayer::CacheBucket::Put(const IoHash& HashKey, const ZenCacheValue
//////////////////////////////////////////////////////////////////////////
-ZenCacheDiskLayer::CacheBucket::CacheBucket(std::string BucketName) : m_BucketName(std::move(BucketName))
+ZenCacheDiskLayer::CacheBucket::CacheBucket(std::string BucketName) : m_BucketName(std::move(BucketName)), m_BucketId(Oid::Zero)
{
}
@@ -580,7 +580,7 @@ ZenCacheDiskLayer::CacheBucket::~CacheBucket()
{
}
-void
+bool
ZenCacheDiskLayer::CacheBucket::OpenOrCreate(std::filesystem::path BucketDir, bool AllowCreate)
{
using namespace std::literals;
@@ -598,7 +598,10 @@ ZenCacheDiskLayer::CacheBucket::OpenOrCreate(std::filesystem::path BucketDir, bo
if (Manifest)
{
m_BucketId = Manifest["BucketId"].AsObjectId();
- m_IsOk = m_BucketId != Oid::Zero;
+ if (m_BucketId == Oid::Zero)
+ {
+ return false;
+ }
}
else if (AllowCreate)
{
@@ -612,7 +615,7 @@ ZenCacheDiskLayer::CacheBucket::OpenOrCreate(std::filesystem::path BucketDir, bo
}
else
{
- return;
+ return false;
}
OpenLog(BucketDir, IsNew);
@@ -628,7 +631,7 @@ ZenCacheDiskLayer::CacheBucket::OpenOrCreate(std::filesystem::path BucketDir, bo
}
}
- m_IsOk = true;
+ return true;
}
void
@@ -1208,7 +1211,6 @@ void
ZenCacheDiskLayer::CacheBucket::Drop()
{
RwLock::ExclusiveLockScope _(m_IndexLock);
- m_IsOk = false;
std::vector<std::unique_ptr<RwLock::ExclusiveLockScope>> ShardLocks;
ShardLocks.reserve(256);
@@ -1724,10 +1726,6 @@ ZenCacheDiskLayer::CollectGarbage(GcContext& GcCtx)
for (auto& Kv : m_Buckets)
{
CacheBucket& Bucket = *Kv.second;
- if (!Bucket.IsOk())
- {
- continue;
- }
Bucket.CollectGarbage(GcCtx);
}
}
@@ -1742,10 +1740,6 @@ ZenCacheDiskLayer::UpdateAccessTimes(const zen::access_tracking::AccessTimes& Ac
if (auto It = m_Buckets.find(Kv.first); It != m_Buckets.end())
{
CacheBucket& Bucket = *It->second;
- if (!Bucket.IsOk())
- {
- continue;
- }
Bucket.UpdateAccessTimes(Kv.second);
}
}
@@ -1959,10 +1953,6 @@ ZenCacheDiskLayer::Get(std::string_view InBucket, const IoHash& HashKey, ZenCach
if (it != m_Buckets.end())
{
Bucket = it->second.get();
- if (!Bucket->IsOk())
- {
- return false;
- }
}
}
@@ -1984,9 +1974,9 @@ ZenCacheDiskLayer::Get(std::string_view InBucket, const IoHash& HashKey, ZenCach
std::filesystem::path BucketPath = m_RootDir;
BucketPath /= BucketName;
- Bucket->OpenOrCreate(BucketPath);
- if (!Bucket->IsOk())
+ if (!Bucket->OpenOrCreate(BucketPath))
{
+ m_Buckets.erase(BucketName);
return false;
}
}
@@ -2010,10 +2000,6 @@ ZenCacheDiskLayer::Put(std::string_view InBucket, const IoHash& HashKey, const Z
if (it != m_Buckets.end())
{
Bucket = it->second.get();
- if (!Bucket->IsOk())
- {
- return;
- }
}
}
@@ -2035,9 +2021,9 @@ ZenCacheDiskLayer::Put(std::string_view InBucket, const IoHash& HashKey, const Z
std::filesystem::path BucketPath = m_RootDir;
BucketPath /= BucketName;
- Bucket->OpenOrCreate(BucketPath);
- if (!Bucket->IsOk())
+ if (!Bucket->OpenOrCreate(BucketPath))
{
+ m_Buckets.erase(BucketName);
return;
}
}
@@ -2064,25 +2050,20 @@ ZenCacheDiskLayer::DiscoverBuckets()
// New bucket needs to be created
if (auto It = m_Buckets.find(BucketName); It != m_Buckets.end())
{
+ continue;
}
- else
- {
- auto InsertResult = m_Buckets.emplace(BucketName, std::make_unique<CacheBucket>(BucketName));
- CacheBucket& Bucket = *InsertResult.first->second;
- Bucket.OpenOrCreate(BucketPath, /* AllowCreate */ false);
+ auto InsertResult = m_Buckets.emplace(BucketName, std::make_unique<CacheBucket>(BucketName));
+ CacheBucket& Bucket = *InsertResult.first->second;
- if (Bucket.IsOk())
- {
- ZEN_INFO("Discovered bucket '{}'", BucketName);
- }
- else
- {
- ZEN_WARN("Found directory '{}' in our base directory '{}' but it is not a valid bucket", BucketName, m_RootDir);
+ if (!Bucket.OpenOrCreate(BucketPath, /* AllowCreate */ false))
+ {
+ ZEN_WARN("Found directory '{}' in our base directory '{}' but it is not a valid bucket", BucketName, m_RootDir);
- m_Buckets.erase(InsertResult.first);
- }
+ m_Buckets.erase(InsertResult.first);
+ continue;
}
+ ZEN_INFO("Discovered bucket '{}'", BucketName);
}
}
@@ -2098,10 +2079,6 @@ ZenCacheDiskLayer::DropBucket(std::string_view InBucket)
CacheBucket& Bucket = *it->second;
m_DroppedBuckets.push_back(std::move(it->second));
m_Buckets.erase(it);
- if (!Bucket.IsOk())
- {
- return false;
- }
Bucket.Drop();
@@ -2125,10 +2102,6 @@ ZenCacheDiskLayer::Flush()
for (auto& Kv : m_Buckets)
{
CacheBucket* Bucket = Kv.second.get();
- if (!Bucket->IsOk())
- {
- continue;
- }
Buckets.push_back(Bucket);
}
}
@@ -2147,10 +2120,6 @@ ZenCacheDiskLayer::Scrub(ScrubContext& Ctx)
for (auto& Kv : m_Buckets)
{
CacheBucket& Bucket = *Kv.second;
- if (!Bucket.IsOk())
- {
- continue;
- }
Bucket.Scrub(Ctx);
}
}
@@ -2163,10 +2132,6 @@ ZenCacheDiskLayer::GatherReferences(GcContext& GcCtx)
for (auto& Kv : m_Buckets)
{
CacheBucket& Bucket = *Kv.second;
- if (!Bucket.IsOk())
- {
- continue;
- }
Bucket.GatherReferences(GcCtx);
}
}