aboutsummaryrefslogtreecommitdiff
path: root/zenserver/cache/structuredcachestore.cpp
diff options
context:
space:
mode:
authorMartin Ridgers <[email protected]>2021-11-01 12:44:12 +0100
committerMartin Ridgers <[email protected]>2021-11-01 12:44:12 +0100
commit584855c4684204aa3cb0867ffb3fdbce61a936b3 (patch)
tree80a04bf289ec5930b709d76dd2f44e3f64e62cdd /zenserver/cache/structuredcachestore.cpp
parentAdded missing link-time dependencies to xmake.lua scripts (diff)
downloadzen-584855c4684204aa3cb0867ffb3fdbce61a936b3.tar.xz
zen-584855c4684204aa3cb0867ffb3fdbce61a936b3.zip
Moved declaration of ZenDiskCacheLayer::CacheBucket in the .h
GCC fails to compile if CacheBucket is only forward-declared within the class, issuing an "incomplete type" error in relation to the m_Buckets unordered map.
Diffstat (limited to 'zenserver/cache/structuredcachestore.cpp')
-rw-r--r--zenserver/cache/structuredcachestore.cpp122
1 files changed, 31 insertions, 91 deletions
diff --git a/zenserver/cache/structuredcachestore.cpp b/zenserver/cache/structuredcachestore.cpp
index 45241eb68..119062833 100644
--- a/zenserver/cache/structuredcachestore.cpp
+++ b/zenserver/cache/structuredcachestore.cpp
@@ -18,7 +18,6 @@
#include <zencore/testing.h>
#include <zencore/testutils.h>
#include <zencore/thread.h>
-#include <zenstore/basicfile.h>
#include <zenstore/cas.h>
#include <zenstore/caslog.h>
#include <zenstore/cidstore.h>
@@ -317,107 +316,48 @@ ZenCacheMemoryLayer::CacheBucket::Put(const IoHash& HashKey, const ZenCacheValue
//////////////////////////////////////////////////////////////////////////
-#pragma pack(push)
-#pragma pack(1)
+inline DiskLocation::DiskLocation() = default;
-struct DiskLocation
+inline DiskLocation::DiskLocation(uint64_t Offset, uint64_t ValueSize, uint32_t IndexSize, uint64_t Flags)
+: OffsetAndFlags(CombineOffsetAndFlags(Offset, Flags))
+, LowerSize(ValueSize & 0xFFFFffff)
+, IndexDataSize(IndexSize)
{
- inline DiskLocation() = default;
-
- inline DiskLocation(uint64_t Offset, uint64_t ValueSize, uint32_t IndexSize, uint64_t Flags)
- : OffsetAndFlags(CombineOffsetAndFlags(Offset, Flags))
- , LowerSize(ValueSize & 0xFFFFffff)
- , IndexDataSize(IndexSize)
- {
- }
-
- static const uint64_t kOffsetMask = 0x0000'ffFF'ffFF'ffFFull;
- static const uint64_t kSizeMask = 0x00FF'0000'0000'0000ull;
- static const uint64_t kFlagsMask = 0xff00'0000'0000'0000ull;
- static const uint64_t kStandaloneFile = 0x8000'0000'0000'0000ull;
- static const uint64_t kStructured = 0x4000'0000'0000'0000ull;
- static const uint64_t kTombStone = 0x2000'0000'0000'0000ull;
-
- static uint64_t CombineOffsetAndFlags(uint64_t Offset, uint64_t Flags) { return Offset | Flags; }
+}
- inline uint64_t Offset() const { return OffsetAndFlags & kOffsetMask; }
- inline uint64_t Size() const { return LowerSize; }
- inline uint64_t IsFlagSet(uint64_t Flag) const { return OffsetAndFlags & Flag; }
- inline ZenContentType GetContentType() const
- {
- ZenContentType ContentType = ZenContentType::kBinary;
+inline uint64_t DiskLocation::CombineOffsetAndFlags(uint64_t Offset, uint64_t Flags)
+{
+ return Offset | Flags;
+}
- if (IsFlagSet(DiskLocation::kStructured))
- {
- ContentType = ZenContentType::kCbObject;
- }
+inline uint64_t DiskLocation::Offset() const
+{
+ return OffsetAndFlags & kOffsetMask;
+}
- return ContentType;
- }
+inline uint64_t DiskLocation::Size() const
+{
+ return LowerSize;
+}
-private:
- uint64_t OffsetAndFlags = 0;
- uint32_t LowerSize = 0;
- uint32_t IndexDataSize = 0;
-};
+inline uint64_t DiskLocation::IsFlagSet(uint64_t Flag) const
+{
+ return OffsetAndFlags & Flag;
+}
-struct DiskIndexEntry
+inline ZenContentType DiskLocation::GetContentType() const
{
- IoHash Key;
- DiskLocation Location;
-};
+ ZenContentType ContentType = ZenContentType::kBinary;
-#pragma pack(pop)
+ if (IsFlagSet(DiskLocation::kStructured))
+ {
+ ContentType = ZenContentType::kCbObject;
+ }
-static_assert(sizeof(DiskIndexEntry) == 36);
+ return ContentType;
+}
-struct ZenCacheDiskLayer::CacheBucket
-{
- CacheBucket();
- ~CacheBucket();
-
- void OpenOrCreate(std::filesystem::path BucketDir, bool AllowCreate = true);
- static bool Delete(std::filesystem::path BucketDir);
-
- bool Get(const IoHash& HashKey, ZenCacheValue& OutValue);
- void Put(const IoHash& HashKey, const ZenCacheValue& Value);
- void Drop();
- void Flush();
- void Scrub(ScrubContext& Ctx);
- void GarbageCollect(GcContext& GcCtx);
-
- inline bool IsOk() const { return m_IsOk; }
-
-private:
- std::filesystem::path m_BucketDir;
- Oid m_BucketId;
- bool m_IsOk = false;
- uint64_t m_LargeObjectThreshold = 64 * 1024;
-
- // These files are used to manage storage of small objects for this bucket
-
- BasicFile m_SobsFile;
- TCasLogFile<DiskIndexEntry> m_SlogFile;
-
- RwLock m_IndexLock;
- tsl::robin_map<IoHash, DiskLocation, IoHash::Hasher> m_Index;
- uint64_t m_WriteCursor = 0;
-
- void BuildPath(WideStringBuilderBase& Path, const IoHash& HashKey);
- void PutStandaloneCacheValue(const IoHash& HashKey, const ZenCacheValue& Value);
- bool GetStandaloneCacheValue(const DiskLocation& Loc, const IoHash& HashKey, ZenCacheValue& OutValue);
- bool GetInlineCacheValue(const DiskLocation& Loc, ZenCacheValue& OutValue);
-
- // These locks are here to avoid contention on file creation, therefore it's sufficient
- // that we take the same lock for the same hash
- //
- // These locks are small and should really be spaced out so they don't share cache lines,
- // but we don't currently access them at particularly high frequency so it should not be
- // an issue in practice
-
- RwLock m_ShardedLocks[256];
- inline RwLock& LockForHash(const IoHash& Hash) { return m_ShardedLocks[Hash.Hash[19]]; }
-};
+//////////////////////////////////////////////////////////////////////////
ZenCacheDiskLayer::CacheBucket::CacheBucket()
{