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/structuredcachestore.cpp | |
| 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/structuredcachestore.cpp')
| -rw-r--r-- | zenserver/cache/structuredcachestore.cpp | 68 |
1 files changed, 67 insertions, 1 deletions
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 |