diff options
| author | Stefan Boberg <[email protected]> | 2021-11-01 16:48:55 +0100 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-11-01 16:48:55 +0100 |
| commit | a8f9941f5c8dff75f606e130f7132babda6265bb (patch) | |
| tree | b5d424562420223495fdbcdd6c9dab051519e8ce /zenserver/cache | |
| parent | filecas: Fixed debug logging (diff) | |
| parent | Merged from main (diff) | |
| download | zen-a8f9941f5c8dff75f606e130f7132babda6265bb.tar.xz zen-a8f9941f5c8dff75f606e130f7132babda6265bb.zip | |
Merge branch 'gc' of https://github.com/EpicGames/zen into gc
Diffstat (limited to 'zenserver/cache')
| -rw-r--r-- | zenserver/cache/cacheagent.cpp | 5 | ||||
| -rw-r--r-- | zenserver/cache/cacheagent.h | 9 | ||||
| -rw-r--r-- | zenserver/cache/structuredcachestore.cpp | 68 | ||||
| -rw-r--r-- | zenserver/cache/structuredcachestore.h | 4 |
4 files changed, 70 insertions, 16 deletions
diff --git a/zenserver/cache/cacheagent.cpp b/zenserver/cache/cacheagent.cpp deleted file mode 100644 index f4d1cabe6..000000000 --- a/zenserver/cache/cacheagent.cpp +++ /dev/null @@ -1,5 +0,0 @@ -// Copyright Epic Games, Inc. All Rights Reserved. - -#include "cacheagent.h" - -#include <gsl/gsl-lite.hpp> diff --git a/zenserver/cache/cacheagent.h b/zenserver/cache/cacheagent.h deleted file mode 100644 index 145d0f79f..000000000 --- a/zenserver/cache/cacheagent.h +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright Epic Games, Inc. All Rights Reserved. - -#pragma once - -class CacheAgent -{ -public: -private: -}; diff --git a/zenserver/cache/structuredcachestore.cpp b/zenserver/cache/structuredcachestore.cpp index f964c3102..b120f3955 100644 --- a/zenserver/cache/structuredcachestore.cpp +++ b/zenserver/cache/structuredcachestore.cpp @@ -6,21 +6,28 @@ #include <zencore/windows.h> #include <zencore/compactbinary.h> +#include <zencore/compactbinarybuilder.h> +#include <zencore/compactbinarypackage.h> #include <zencore/compactbinaryvalidation.h> +#include <zencore/compress.h> #include <zencore/filesystem.h> #include <zencore/fmtutils.h> #include <zencore/iobuffer.h> #include <zencore/logging.h> #include <zencore/string.h> +#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> #include <zenstore/gc.h> #include <concepts> #include <filesystem> #include <memory_resource> +#include <ranges> #include <unordered_map> ZEN_THIRD_PARTY_INCLUDES_START @@ -236,7 +243,12 @@ ZenCacheMemoryLayer::Scrub(ScrubContext& Ctx) void ZenCacheMemoryLayer::GatherReferences(GcContext& GcCtx) { - ZEN_UNUSED(GcCtx); + RwLock::SharedLockScope _(m_Lock); + + for (auto& Kv : m_Buckets) + { + Kv.second.GatherReferences(GcCtx); + } } void @@ -1079,4 +1091,58 @@ ZenCacheDiskLayer::GatherReferences(GcContext& GcCtx) } } +////////////////////////////////////////////////////////////////////////// + +#if ZEN_WITH_TESTS + +TEST_CASE("z$.store") +{ + using namespace fmt::literals; + using namespace std::literals; + + ScopedTemporaryDirectory TempDir; + + CasGc Gc; + + ZenCacheStore Zcs(Gc, TempDir.Path() / "cache"); + + const int kIterationCount = 100; + + for (int i = 0; i < kIterationCount; ++i) + { + const IoHash Key = IoHash::HashBuffer(&i, sizeof i); + + CbObjectWriter Cbo; + Cbo << "hey" << i; + CbObject Obj = Cbo.Save(); + + ZenCacheValue Value; + Value.Value = Obj.GetBuffer().AsIoBuffer(); + Value.Value.SetContentType(ZenContentType::kCbObject); + + Zcs.Put("test_bucket"sv, Key, Value); + } + + for (int i = 0; i < kIterationCount; ++i) + { + const IoHash Key = IoHash::HashBuffer(&i, sizeof i); + + ZenCacheValue Value; + Zcs.Get("test_bucket"sv, Key, /* out */ Value); + + REQUIRE(Value.Value); + CHECK(Value.Value.GetContentType() == ZenContentType::kCbObject); + CHECK_EQ(ValidateCompactBinary(Value.Value, CbValidateMode::All), CbValidateError::None); + CbObject Obj = LoadCompactBinaryObject(Value.Value); + CHECK_EQ(Obj["hey"].AsInt32(), i); + } +} + +#endif + +void +z$_forcelink() +{ +} + } // namespace zen diff --git a/zenserver/cache/structuredcachestore.h b/zenserver/cache/structuredcachestore.h index da3e74126..6beecf78b 100644 --- a/zenserver/cache/structuredcachestore.h +++ b/zenserver/cache/structuredcachestore.h @@ -105,7 +105,7 @@ private: class ZenCacheDiskLayer { public: - ZenCacheDiskLayer(const std::filesystem::path& RootDir); + explicit ZenCacheDiskLayer(const std::filesystem::path& RootDir); ~ZenCacheDiskLayer(); bool Get(std::string_view Bucket, const IoHash& HashKey, ZenCacheValue& OutValue); @@ -149,4 +149,6 @@ private: uint64_t m_LastScrubTime = 0; }; +void z$_forcelink(); + } // namespace zen |