From 65bbed5725dc6b8e5b8886b51ec3c85c7dcaa4b2 Mon Sep 17 00:00:00 2001 From: Per Larsson Date: Fri, 29 Oct 2021 14:29:59 +0200 Subject: Added option --zen-upstream-dns that will be resolved to one or more endpoint. --- zenserver/config.cpp | 7 +++++++ zenserver/config.h | 1 + zenserver/zenserver.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 59 insertions(+), 3 deletions(-) diff --git a/zenserver/config.cpp b/zenserver/config.cpp index cbdbebb03..f512f8015 100644 --- a/zenserver/config.cpp +++ b/zenserver/config.cpp @@ -232,6 +232,13 @@ ParseGlobalCliOptions(int argc, char* argv[], ZenServerOptions& GlobalOptions, Z cxxopts::value>(ServiceConfig.UpstreamCacheConfig.ZenConfig.Urls)->default_value(""), ""); + options.add_option("cache", + "", + "upstream-zen-dns", + "DNS that resolves to one or more Zen server instance(s)", + cxxopts::value>(ServiceConfig.UpstreamCacheConfig.ZenConfig.Dns)->default_value(""), + ""); + options.add_option("cache", "", "upstream-thread-count", diff --git a/zenserver/config.h b/zenserver/config.h index 2a5a17fb9..72a4f31bb 100644 --- a/zenserver/config.h +++ b/zenserver/config.h @@ -42,6 +42,7 @@ struct ZenUpstreamJupiterConfig struct ZenUpstreamZenConfig { std::vector Urls; + std::vector Dns; }; enum class UpstreamCachePolicy : uint8_t diff --git a/zenserver/zenserver.cpp b/zenserver/zenserver.cpp index 00abed513..80bc6a6d4 100644 --- a/zenserver/zenserver.cpp +++ b/zenserver/zenserver.cpp @@ -117,6 +117,37 @@ namespace zen { using namespace std::literals; using namespace fmt::literals; +namespace utils { + asio::error_code ResolveHostname(asio::io_context& Ctx, + std::string_view Host, + std::string_view DefaultPort, + std::vector& OutEndpoints) + { + std::string_view Port = DefaultPort; + + if (const size_t Idx = Host.find(":"); Idx != std::string_view::npos) + { + Port = Host.substr(Idx + 1); + Host = Host.substr(0, Idx); + } + + asio::ip::tcp::resolver Resolver(Ctx); + + asio::error_code ErrorCode; + asio::ip::tcp::resolver::results_type Endpoints = Resolver.resolve(Host, Port, ErrorCode); + + if (!ErrorCode) + { + for (const asio::ip::tcp::endpoint& Ep : Endpoints) + { + OutEndpoints.push_back("http://{}:{}"_format(Ep.address().to_string(), Ep.port())); + } + } + + return ErrorCode; + } +} // namespace utils + class ZenServer : public IHttpStatusProvider { public: @@ -616,12 +647,29 @@ ZenServer::InitializeStructuredCache(ZenServiceConfig& ServiceConfig) UpstreamCache = zen::MakeUpstreamCache(UpstreamOptions, *m_CacheStore, *m_CidStore); - if (!UpstreamConfig.ZenConfig.Urls.empty()) + // Zen upstream { - std::unique_ptr ZenEndpoint = zen::MakeZenUpstreamEndpoint(UpstreamConfig.ZenConfig.Urls); - UpstreamCache->RegisterEndpoint(std::move(ZenEndpoint)); + std::vector ZenUrls = UpstreamConfig.ZenConfig.Urls; + if (!UpstreamConfig.ZenConfig.Dns.empty()) + { + for (const std::string& Dns : UpstreamConfig.ZenConfig.Dns) + { + const asio::error_code Err = zen::utils::ResolveHostname(m_IoContext, Dns, "1337"sv, ZenUrls); + if (Err) + { + ZEN_ERROR("resolve '{}' FAILED, reason '{}'", Err.message()); + } + } + } + + if (!ZenUrls.empty()) + { + std::unique_ptr ZenEndpoint = zen::MakeZenUpstreamEndpoint(ZenUrls); + UpstreamCache->RegisterEndpoint(std::move(ZenEndpoint)); + } } + // Jupiter upstream { zen::CloudCacheClientOptions Options; if (UpstreamConfig.JupiterConfig.UseProductionSettings) -- cgit v1.2.3 From 96eebb30391cd89923926dfde80754d486fc9db4 Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Fri, 29 Oct 2021 18:10:34 +0200 Subject: Added SharedBuffer::MakeView implementation accepting container argument, to make tests easier to write --- zencore/include/zencore/sharedbuffer.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/zencore/include/zencore/sharedbuffer.h b/zencore/include/zencore/sharedbuffer.h index 640c3fe74..1f87dc639 100644 --- a/zencore/include/zencore/sharedbuffer.h +++ b/zencore/include/zencore/sharedbuffer.h @@ -143,6 +143,12 @@ public: /** Make a non-owned view of the input */ [[nodiscard]] inline static SharedBuffer MakeView(MemoryView View) { return MakeView(View.GetData(), View.GetSize()); } + /** Make a non-owning view of the memory of the contiguous container. */ + [[nodiscard]] inline static SharedBuffer MakeView(const std::ranges::contiguous_range auto& Container) + { + std::span Span = Container; + return MakeView(Span.data(), Span.size() * sizeof(typename decltype(Span)::element_type)); + } /** Make a non-owned view of the input */ [[nodiscard]] ZENCORE_API static SharedBuffer MakeView(const void* Data, uint64_t Size); /** Make a non-owned view of the input */ -- cgit v1.2.3 From a5b64d784227e09bd71e78f0b74438bf579673fb Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Fri, 29 Oct 2021 18:11:06 +0200 Subject: memory: Minor change to squelch static analysis warnings --- zencore/memory.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zencore/memory.cpp b/zencore/memory.cpp index 62c81076d..14ea7ca1d 100644 --- a/zencore/memory.cpp +++ b/zencore/memory.cpp @@ -185,13 +185,13 @@ TEST_CASE("ChunkingLinearAllocator") TEST_CASE("MemoryView") { { - uint8_t Array1[16]; + uint8_t Array1[16] = {}; MemoryView View1 = MakeMemoryView(Array1); CHECK(View1.GetSize() == 16); } { - uint32_t Array2[16]; + uint32_t Array2[16] = {}; MemoryView View2 = MakeMemoryView(Array2); CHECK(View2.GetSize() == 64); } -- cgit v1.2.3 From 69bbdeefd2ddc42952bc89b3b39244ce0d758b42 Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Fri, 29 Oct 2021 18:11:41 +0200 Subject: filesystem: Improved test for GetRunningExecutablePath (still not ideal) --- zencore/filesystem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zencore/filesystem.cpp b/zencore/filesystem.cpp index b8e8eff55..a642e2cf6 100644 --- a/zencore/filesystem.cpp +++ b/zencore/filesystem.cpp @@ -840,7 +840,7 @@ TEST_CASE("filesystem") // GetExePath -- this is not a great test as it's so dependent on where the this code gets linked in path BinPath = GetRunningExecutablePath(); - const bool ExpectedExe = BinPath.stem() == "zencore-test" || BinPath.stem() == "zenserver-test" || BinPath.stem() == "zenstore-test"; + const bool ExpectedExe = ToUtf8(BinPath.stem().native()).ends_with("-test"sv) || BinPath.stem() == "zenserver"; CHECK(ExpectedExe); CHECK(is_regular_file(BinPath)); -- cgit v1.2.3 From 47745869ef94436dc368ec8e66fca053816ce44d Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Fri, 29 Oct 2021 18:11:56 +0200 Subject: Removed unused source files --- zenserver/cache/cacheagent.cpp | 5 ----- zenserver/cache/cacheagent.h | 9 --------- 2 files changed, 14 deletions(-) delete mode 100644 zenserver/cache/cacheagent.cpp delete mode 100644 zenserver/cache/cacheagent.h 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 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: -}; -- cgit v1.2.3 From 6a5485ff81689d65e609dd3cbdfd9e8780bbe8b4 Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Fri, 29 Oct 2021 18:12:52 +0200 Subject: zenserver-test: Some modifications to avoid ODR violations --- zenserver-test/zenserver-test.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/zenserver-test/zenserver-test.cpp b/zenserver-test/zenserver-test.cpp index 23be9f729..f3849b2cd 100644 --- a/zenserver-test/zenserver-test.cpp +++ b/zenserver-test/zenserver-test.cpp @@ -66,6 +66,7 @@ ZEN_THIRD_PARTY_INCLUDES_END #endif using namespace fmt::literals; +using namespace std::literals; /* @@ -126,10 +127,10 @@ public: m_Headers.reserve(16); zen::ExtendableStringBuilder<256> RequestBody; - RequestBody << "GET " << Path << " HTTP/1.1\r\n"; - RequestBody << "Host: " << Server << "\r\n"; - RequestBody << "Accept: */*\r\n"; - RequestBody << "Connection: " << (m_KeepAlive ? "keep-alive" : "close") << "\r\n\r\n"; // TODO: support keep-alive + RequestBody << "GET "sv << Path << " HTTP/1.1\r\n"sv; + RequestBody << "Host: "sv << Server << "\r\n"sv; + RequestBody << "Accept: */*\r\n"sv; + RequestBody << "Connection: "sv << (m_KeepAlive ? "keep-alive"sv : "close"sv) << "\r\n\r\n"sv; // TODO: support keep-alive m_RequestBody = RequestBody; @@ -460,12 +461,12 @@ using namespace spdlog; using namespace spdlog::details; using namespace std::literals; -class full_formatter final : public spdlog::formatter +class full_test_formatter final : public spdlog::formatter { public: - full_formatter(std::string_view LogId, std::chrono::time_point Epoch) : m_Epoch(Epoch), m_LogId(LogId) {} + full_test_formatter(std::string_view LogId, std::chrono::time_point Epoch) : m_Epoch(Epoch), m_LogId(LogId) {} - virtual std::unique_ptr clone() const override { return std::make_unique(m_LogId, m_Epoch); } + virtual std::unique_ptr clone() const override { return std::make_unique(m_LogId, m_Epoch); } static constexpr bool UseDate = false; @@ -680,7 +681,7 @@ main(int argc, char** argv) zen::logging::InitializeLogging(); spdlog::set_level(spdlog::level::debug); - spdlog::set_formatter(std::make_unique<::logging::full_formatter>("test", std::chrono::system_clock::now())); + spdlog::set_formatter(std::make_unique<::logging::full_test_formatter>("test", std::chrono::system_clock::now())); std::filesystem::path ProgramBaseDir = std::filesystem::path(argv[0]).parent_path(); std::filesystem::path TestBaseDir = ProgramBaseDir.parent_path().parent_path() / ".test"; -- cgit v1.2.3 From eff472457f4090a4476ced920cea2ea4cbeca7bf Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Fri, 29 Oct 2021 18:17:36 +0200 Subject: z$: hooked up bucket traversal for gc added some tests added "test" mode for zenserver, to run any tests embedded in the zenserver (example: `zenserver test -tx=z$.*`) --- zenserver/cache/structuredcachestore.cpp | 128 ++++++++++++++++++++++++++++--- zenserver/cache/structuredcachestore.h | 7 +- zenserver/zenserver.cpp | 28 ++++++- zenserver/zenserver.vcxproj | 2 - zenserver/zenserver.vcxproj.filters | 6 -- 5 files changed, 148 insertions(+), 23 deletions(-) diff --git a/zenserver/cache/structuredcachestore.cpp b/zenserver/cache/structuredcachestore.cpp index e7b840ed8..02ec43115 100644 --- a/zenserver/cache/structuredcachestore.cpp +++ b/zenserver/cache/structuredcachestore.cpp @@ -6,19 +6,27 @@ #include #include +#include +#include +#include +#include #include #include #include #include #include +#include +#include #include #include #include #include +#include #include #include #include +#include ZEN_THIRD_PARTY_INCLUDES_START #include @@ -31,7 +39,7 @@ namespace zen { using namespace fmt::literals; -ZenCacheStore::ZenCacheStore(CasStore& Cas, const std::filesystem::path& RootDir) : m_DiskLayer{Cas, RootDir} +ZenCacheStore::ZenCacheStore(const std::filesystem::path& RootDir) : m_DiskLayer{RootDir} { ZEN_INFO("initializing structured cache at '{}'", RootDir); CreateDirectories(RootDir); @@ -125,7 +133,8 @@ ZenCacheStore::Scrub(ScrubContext& Ctx) void ZenCacheStore::GarbageCollect(GcContext& GcCtx) { - ZEN_UNUSED(GcCtx); + m_DiskLayer.GarbageCollect(GcCtx); + m_MemLayer.GarbageCollect(GcCtx); } ////////////////////////////////////////////////////////////////////////// @@ -213,7 +222,12 @@ ZenCacheMemoryLayer::Scrub(ScrubContext& Ctx) void ZenCacheMemoryLayer::GarbageCollect(GcContext& GcCtx) { - ZEN_UNUSED(GcCtx); + RwLock::SharedLockScope _(m_Lock); + + for (auto& Kv : m_Buckets) + { + Kv.second.GarbageCollect(GcCtx); + } } void @@ -358,7 +372,7 @@ static_assert(sizeof(DiskIndexEntry) == 36); struct ZenCacheDiskLayer::CacheBucket { - CacheBucket(CasStore& Cas); + CacheBucket(); ~CacheBucket(); void OpenOrCreate(std::filesystem::path BucketDir, bool AllowCreate = true); @@ -374,7 +388,6 @@ struct ZenCacheDiskLayer::CacheBucket inline bool IsOk() const { return m_IsOk; } private: - CasStore& m_CasStore; std::filesystem::path m_BucketDir; Oid m_BucketId; bool m_IsOk = false; @@ -405,7 +418,7 @@ private: inline RwLock& LockForHash(const IoHash& Hash) { return m_ShardedLocks[Hash.Hash[19]]; } }; -ZenCacheDiskLayer::CacheBucket::CacheBucket(CasStore& Cas) : m_CasStore(Cas) +ZenCacheDiskLayer::CacheBucket::CacheBucket() { } @@ -839,7 +852,7 @@ ZenCacheDiskLayer::CacheBucket::PutStandaloneCacheValue(const IoHash& HashKey, c ////////////////////////////////////////////////////////////////////////// -ZenCacheDiskLayer::ZenCacheDiskLayer(CasStore& Cas, const std::filesystem::path& RootDir) : m_RootDir(RootDir), m_CasStore(Cas) +ZenCacheDiskLayer::ZenCacheDiskLayer(const std::filesystem::path& RootDir) : m_RootDir(RootDir) { } @@ -873,7 +886,7 @@ ZenCacheDiskLayer::Get(std::string_view InBucket, const IoHash& HashKey, ZenCach } else { - auto It = m_Buckets.try_emplace(std::string(InBucket), m_CasStore); + auto It = m_Buckets.try_emplace(std::string(InBucket)); Bucket = &It.first->second; std::filesystem::path BucketPath = m_RootDir; @@ -916,7 +929,7 @@ ZenCacheDiskLayer::Put(std::string_view InBucket, const IoHash& HashKey, const Z } else { - auto It = m_Buckets.try_emplace(std::string(InBucket), m_CasStore); + auto It = m_Buckets.try_emplace(std::string(InBucket)); Bucket = &It.first->second; std::filesystem::path bucketPath = m_RootDir; @@ -972,7 +985,7 @@ ZenCacheDiskLayer::DiscoverBuckets() } else { - auto InsertResult = m_Buckets.try_emplace(BucketName8, m_CasStore); + auto InsertResult = m_Buckets.try_emplace(BucketName8); std::filesystem::path BucketPath = m_RootDir; BucketPath /= BucketName8; @@ -1050,7 +1063,100 @@ ZenCacheDiskLayer::Scrub(ScrubContext& Ctx) void ZenCacheDiskLayer::GarbageCollect(GcContext& GcCtx) { - ZEN_UNUSED(GcCtx); + RwLock::SharedLockScope _(m_Lock); + + for (auto& Kv : m_Buckets) + { + Kv.second.GarbageCollect(GcCtx); + } +} + +////////////////////////////////////////////////////////////////////////// + +#if ZEN_WITH_TESTS + +TEST_CASE("z$.store") +{ + using namespace fmt::literals; + using namespace std::literals; + + ScopedTemporaryDirectory TempDir; + + ZenCacheStore Zcs(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); + } +} + +TEST_CASE("z$.gc") +{ + using namespace fmt::literals; + using namespace std::literals; + + ScopedTemporaryDirectory TempDir; + + CasStoreConfiguration Config{.RootDirectory = TempDir.Path()}; + std::unique_ptr Cas{CreateCasStore()}; + Cas->Initialize(Config); + + CidStore Cid(*Cas, TempDir.Path()); + + ZenCacheStore Zcs(TempDir.Path() / "cache"); + + const int kIterationCount = 100; + + for (int i = 0; i < kIterationCount; ++i) + { + const IoHash Key = IoHash::HashBuffer(&i, sizeof i); + + CompressedBuffer CompBuf = CompressedBuffer::Compress(SharedBuffer::MakeView("abcd"sv)); + Cid.AddChunk(CompBuf); + + CbObjectWriter Cbo; + Cbo << "hey" << i << "ref" << CbAttachment(CompBuf); + CbObject Obj = Cbo.Save(); + + ZenCacheValue Value; + Value.Value = Obj.GetBuffer().AsIoBuffer(); + Value.Value.SetContentType(ZenContentType::kCbObject); + + Zcs.Put("test_bucket"sv, Key, Value); + } +} + +#endif + +void +z$_forcelink() +{ } } // namespace zen diff --git a/zenserver/cache/structuredcachestore.h b/zenserver/cache/structuredcachestore.h index 4753af627..760f4995c 100644 --- a/zenserver/cache/structuredcachestore.h +++ b/zenserver/cache/structuredcachestore.h @@ -101,7 +101,7 @@ private: class ZenCacheDiskLayer { public: - ZenCacheDiskLayer(CasStore& Cas, const std::filesystem::path& RootDir); + explicit ZenCacheDiskLayer(const std::filesystem::path& RootDir); ~ZenCacheDiskLayer(); bool Get(std::string_view Bucket, const IoHash& HashKey, ZenCacheValue& OutValue); @@ -119,7 +119,6 @@ private: */ struct CacheBucket; - CasStore& m_CasStore; std::filesystem::path m_RootDir; RwLock m_Lock; std::unordered_map m_Buckets; // TODO: make this case insensitive @@ -128,7 +127,7 @@ private: class ZenCacheStore { public: - ZenCacheStore(CasStore& Cas, const std::filesystem::path& RootDir); + explicit ZenCacheStore(const std::filesystem::path& RootDir); ~ZenCacheStore(); bool Get(std::string_view Bucket, const IoHash& HashKey, ZenCacheValue& OutValue); @@ -146,4 +145,6 @@ private: uint64_t m_LastScrubTime = 0; }; +void z$_forcelink(); + } // namespace zen diff --git a/zenserver/zenserver.cpp b/zenserver/zenserver.cpp index 00abed513..1a04aa39b 100644 --- a/zenserver/zenserver.cpp +++ b/zenserver/zenserver.cpp @@ -596,7 +596,7 @@ ZenServer::InitializeStructuredCache(ZenServiceConfig& ServiceConfig) auto ValueOrDefault = [](std::string_view Value, std::string_view Default) { return Value.empty() ? Default : Value; }; ZEN_INFO("instantiating structured cache service"); - m_CacheStore = std::make_unique(*m_CasStore, m_DataRoot / "cache"); + m_CacheStore = std::make_unique(m_DataRoot / "cache"); std::unique_ptr UpstreamCache; if (ServiceConfig.UpstreamCacheConfig.CachePolicy != UpstreamCachePolicy::Disabled) @@ -842,6 +842,22 @@ ZenWindowsService::Run() return 0; } +#if ZEN_WITH_TESTS +int +test_main(int argc, char** argv) +{ + zen::zencore_forcelinktests(); + zen::zenhttp_forcelinktests(); + zen::zenstore_forcelinktests(); + + zen::logging::InitializeLogging(); + + spdlog::set_level(spdlog::level::debug); + + return doctest::Context(argc, argv).run(); +} +#endif + int main(int argc, char* argv[]) { @@ -851,6 +867,16 @@ main(int argc, char* argv[]) mi_version(); #endif +#if ZEN_WITH_TESTS + if (argc >= 2) + { + if (argv[1] == "test"sv) + { + return test_main(argc, argv); + } + } +#endif + try { ZenServerOptions GlobalOptions; diff --git a/zenserver/zenserver.vcxproj b/zenserver/zenserver.vcxproj index b670582e7..d954d3f8d 100644 --- a/zenserver/zenserver.vcxproj +++ b/zenserver/zenserver.vcxproj @@ -120,7 +120,6 @@ - @@ -142,7 +141,6 @@ - diff --git a/zenserver/zenserver.vcxproj.filters b/zenserver/zenserver.vcxproj.filters index b87fa0016..04c6267ba 100644 --- a/zenserver/zenserver.vcxproj.filters +++ b/zenserver/zenserver.vcxproj.filters @@ -5,9 +5,6 @@ - - cache - diag @@ -49,9 +46,6 @@ - - cache - experimental -- cgit v1.2.3 From 7b2afa7e5791d2b401e32911362ac9f1e1106598 Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Fri, 29 Oct 2021 18:41:26 +0200 Subject: Minor cleanup --- zenserver/cache/structuredcachestore.cpp | 39 ++------------------------------ 1 file changed, 2 insertions(+), 37 deletions(-) diff --git a/zenserver/cache/structuredcachestore.cpp b/zenserver/cache/structuredcachestore.cpp index 02ec43115..e1d77a088 100644 --- a/zenserver/cache/structuredcachestore.cpp +++ b/zenserver/cache/structuredcachestore.cpp @@ -22,11 +22,12 @@ #include #include #include +#include #include #include -#include #include +#include ZEN_THIRD_PARTY_INCLUDES_START #include @@ -1116,42 +1117,6 @@ TEST_CASE("z$.store") } } -TEST_CASE("z$.gc") -{ - using namespace fmt::literals; - using namespace std::literals; - - ScopedTemporaryDirectory TempDir; - - CasStoreConfiguration Config{.RootDirectory = TempDir.Path()}; - std::unique_ptr Cas{CreateCasStore()}; - Cas->Initialize(Config); - - CidStore Cid(*Cas, TempDir.Path()); - - ZenCacheStore Zcs(TempDir.Path() / "cache"); - - const int kIterationCount = 100; - - for (int i = 0; i < kIterationCount; ++i) - { - const IoHash Key = IoHash::HashBuffer(&i, sizeof i); - - CompressedBuffer CompBuf = CompressedBuffer::Compress(SharedBuffer::MakeView("abcd"sv)); - Cid.AddChunk(CompBuf); - - CbObjectWriter Cbo; - Cbo << "hey" << i << "ref" << CbAttachment(CompBuf); - CbObject Obj = Cbo.Save(); - - ZenCacheValue Value; - Value.Value = Obj.GetBuffer().AsIoBuffer(); - Value.Value.SetContentType(ZenContentType::kCbObject); - - Zcs.Put("test_bucket"sv, Key, Value); - } -} - #endif void -- cgit v1.2.3