diff options
| author | Stefan Boberg <[email protected]> | 2021-09-20 12:08:44 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-09-20 12:08:44 +0200 |
| commit | 782351959f697fca6b0804c134467b7d9c29da1a (patch) | |
| tree | fdd6c841a567e69e3d0b45089de70c7e7d0bb756 | |
| parent | trivial: include cleanup (diff) | |
| download | zen-782351959f697fca6b0804c134467b7d9c29da1a.tar.xz zen-782351959f697fca6b0804c134467b7d9c29da1a.zip | |
Moved more code into zen namespace, for consistency
Also removed snapshot_manifest (remnants of vfs prototype)
26 files changed, 225 insertions, 565 deletions
diff --git a/zencore/compositebuffer.cpp b/zencore/compositebuffer.cpp index 0e27e6f0e..3190ca5ea 100644 --- a/zencore/compositebuffer.cpp +++ b/zencore/compositebuffer.cpp @@ -90,8 +90,8 @@ CompositeBuffer CompositeBuffer::Mid(uint64_t Offset, uint64_t Size) const { const uint64_t BufferSize = GetSize(); - Offset = zen::Min(Offset, BufferSize); - Size = zen::Min(Size, BufferSize - Offset); + Offset = Min(Offset, BufferSize); + Size = Min(Size, BufferSize - Offset); CompositeBuffer Buffer; IterateRange(Offset, Size, [&Buffer](MemoryView View, const SharedBuffer& ViewOuter) { Buffer.m_Segments.push_back(SharedBuffer::MakeView(View, ViewOuter)); diff --git a/zencore/filesystem.cpp b/zencore/filesystem.cpp index 59300b7ad..45e177aaa 100644 --- a/zencore/filesystem.cpp +++ b/zencore/filesystem.cpp @@ -406,14 +406,14 @@ WriteFile(std::filesystem::path Path, const IoBuffer* const* Data, size_t Buffer HRESULT hRes = Outfile.Create(Path.c_str(), GENERIC_WRITE, FILE_SHARE_READ, CREATE_ALWAYS); if (hRes == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)) { - zen::CreateDirectories(Path.parent_path()); + CreateDirectories(Path.parent_path()); hRes = Outfile.Create(Path.c_str(), GENERIC_WRITE, FILE_SHARE_READ, CREATE_ALWAYS); } if (FAILED(hRes)) { - zen::ThrowSystemException(hRes, "File open failed for '{}'"_format(Path).c_str()); + ThrowSystemException(hRes, "File open failed for '{}'"_format(Path).c_str()); } // TODO: this should be block-enlightened @@ -425,13 +425,13 @@ WriteFile(std::filesystem::path Path, const IoBuffer* const* Data, size_t Buffer while (WriteSize) { - const uint64_t ChunkSize = zen::Min<uint64_t>(WriteSize, uint64_t(2) * 1024 * 1024 * 1024); + const uint64_t ChunkSize = Min<uint64_t>(WriteSize, uint64_t(2) * 1024 * 1024 * 1024); hRes = Outfile.Write(DataPtr, gsl::narrow_cast<uint32_t>(WriteSize)); if (FAILED(hRes)) { - zen::ThrowSystemException(hRes, "File write failed for '{}'"_format(Path).c_str()); + ThrowSystemException(hRes, "File write failed for '{}'"_format(Path).c_str()); } WriteSize -= ChunkSize; @@ -529,7 +529,7 @@ FileSystemTraversal::TraverseFileSystem(const std::filesystem::path& RootDir, Tr if (FAILED(hRes)) { - zen::ThrowSystemException(hRes, "Failed to open handle to volume root"); + ThrowSystemException(hRes, "Failed to open handle to volume root"); } while (Continue) diff --git a/zencore/include/zencore/snapshot_manifest.h b/zencore/include/zencore/snapshot_manifest.h deleted file mode 100644 index 95e64773a..000000000 --- a/zencore/include/zencore/snapshot_manifest.h +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright Epic Games, Inc. All Rights Reserved. - -#pragma once - -#include <zencore/iohash.h> -#include <zencore/zencore.h> - -#include <filesystem> -#include <functional> -#include <string> -#include <vector> - -namespace zen { - -struct LeafNode -{ - uint64_t FileSize = 0; - uint64_t FileModifiedTime = 0; - zen::IoHash ChunkHash = zen::IoHash::Zero; - std::wstring Name; -}; - -struct TreeNode -{ - std::vector<TreeNode> Children; - std::vector<LeafNode> Leaves; - std::wstring Name; - zen::BLAKE3 ChunkHash = zen::BLAKE3::Zero; - - ZENCORE_API void VisitModifyFiles(std::function<void(LeafNode& node)> func); - ZENCORE_API void VisitFiles(std::function<void(const LeafNode& node)> func); - ZENCORE_API void Finalize(); -}; - -struct SnapshotManifest -{ - std::string Id; - TreeNode Root; - zen::BLAKE3 ChunkHash = zen::BLAKE3::Zero; - - ZENCORE_API void finalize(); -}; - -class InStream; -class OutStream; - -ZENCORE_API void ReadManifest(SnapshotManifest& Manifest, InStream& FromStream); -ZENCORE_API void WriteManifest(const SnapshotManifest& Manifest, OutStream& ToStream); -ZENCORE_API void PrintManifest(const SnapshotManifest& Manifest, OutStream& ToStream); - -// Translate a user-provided manifest specification into a file path. -// Supports hashtag syntax to implicitly refer to user documents zenfs folder -ZENCORE_API std::filesystem::path ManifestSpecToPath(const char* ManifestSpec); - -void snapshotmanifest_forcelink(); - -} // namespace zen diff --git a/zencore/snapshot_manifest.cpp b/zencore/snapshot_manifest.cpp deleted file mode 100644 index 6e9945cf0..000000000 --- a/zencore/snapshot_manifest.cpp +++ /dev/null @@ -1,285 +0,0 @@ -// Copyright Epic Games, Inc. All Rights Reserved. - -#include <zencore/snapshot_manifest.h> -#include <zencore/stream.h> -#include <zencore/streamutil.h> -#include <zencore/string.h> -#include <zencore/testing.h> - -#include <filesystem> -#include <ostream> - -// Used for getting My Documents for default snapshot dir -#include <ShlObj.h> -#if ZEN_PLATFORM_WINDOWS -# pragma comment(lib, "shell32.lib") -#endif - -namespace zen { - -constexpr const char* magicString = "-=- ZEN_SNAP -=-"; - -struct SerializedManifestHeader -{ - char Magic[16]; - - void init() { memcpy(Magic, magicString, sizeof Magic); } - bool verify() const { return memcmp(Magic, magicString, sizeof Magic) == 0; } -}; - -TextWriter& -operator<<(TextWriter& Writer, const LeafNode& Leaf) -{ - Writer << "modTime: " << Leaf.FileModifiedTime << ", size: " << Leaf.FileSize << ", hash: " << Leaf.ChunkHash << ", name: " << Leaf.Name - << "\n"; - - return Writer; -} - -BinaryWriter& -operator<<(BinaryWriter& Writer, const LeafNode& Leaf) -{ - Writer << Leaf.FileModifiedTime << Leaf.FileSize << Leaf.ChunkHash << Leaf.Name; - - return Writer; -} - -BinaryReader& -operator>>(BinaryReader& Reader, LeafNode& Leaf) -{ - Reader >> Leaf.FileModifiedTime >> Leaf.FileSize >> Leaf.ChunkHash >> Leaf.Name; - - return Reader; -} - -void -TreeNode::Finalize() -{ - zen::BLAKE3Stream Blake3Stream; - - for (auto& Node : Children) - { - Node.Finalize(); - Blake3Stream.Append(Node.ChunkHash.Hash, sizeof Node.ChunkHash); - Blake3Stream.Append(Node.Name.data(), Node.Name.size() + 1); - } - - for (auto& leaf : Leaves) - { - Blake3Stream.Append(leaf.ChunkHash.Hash, sizeof leaf.ChunkHash); - Blake3Stream.Append(leaf.Name.data(), leaf.Name.size() + 1); - } - - this->ChunkHash = Blake3Stream.GetHash(); -} - -void -TreeNode::VisitFiles(std::function<void(const LeafNode& node)> func) -{ - for (auto& Node : Children) - Node.VisitFiles(func); - - for (auto& Leaf : Leaves) - func(Leaf); -} - -void -TreeNode::VisitModifyFiles(std::function<void(LeafNode& node)> func) -{ - for (auto& Node : Children) - Node.VisitModifyFiles(func); - - for (auto& Leaf : Leaves) - func(Leaf); -} - -IndentTextWriter& -operator<<(IndentTextWriter& Writer, const TreeNode& Node) -{ - Writer << "hash: " << Node.ChunkHash << ", name: " << Node.Name << "\n"; - - if (!Node.Leaves.empty()) - { - Writer << "files: " - << "\n"; - - IndentTextWriter::Scope _(Writer); - - for (const LeafNode& Leaf : Node.Leaves) - Writer << Leaf; - } - - if (!Node.Children.empty()) - { - Writer << "children: " - << "\n"; - - IndentTextWriter::Scope _(Writer); - - for (const TreeNode& Child : Node.Children) - { - Writer << Child; - } - } - - return Writer; -} - -BinaryWriter& -operator<<(BinaryWriter& Writer, const TreeNode& Node) -{ - Writer << Node.ChunkHash << Node.Name; - Writer << uint32_t(Node.Children.size()); - - for (const TreeNode& child : Node.Children) - Writer << child; - - Writer << uint32_t(Node.Leaves.size()); - - for (const LeafNode& Leaf : Node.Leaves) - Writer << Leaf; - - return Writer; -} - -BinaryReader& -operator>>(BinaryReader& Reader, TreeNode& Node) -{ - Reader >> Node.ChunkHash >> Node.Name; - - uint32_t ChildCount = 0; - Reader >> ChildCount; - Node.Children.resize(ChildCount); - - for (TreeNode& Child : Node.Children) - Reader >> Child; - - uint32_t LeafCount = 0; - Reader >> LeafCount; - Node.Leaves.resize(LeafCount); - - for (LeafNode& Leaf : Node.Leaves) - Reader >> Leaf; - - return Reader; -} - -void -SnapshotManifest::finalize() -{ - Root.Finalize(); - - zen::BLAKE3Stream Blake3Stream; - - Blake3Stream.Append(Root.ChunkHash.Hash, sizeof Root.ChunkHash); - Blake3Stream.Append(Root.Name.data(), Root.Name.size() + 1); - - this->ChunkHash = Blake3Stream.GetHash(); -} - -void -WriteManifest(const SnapshotManifest& Manifest, OutStream& ToStream) -{ - BinaryWriter Out(ToStream); - SerializedManifestHeader Header; - Header.init(); - Out.Write(&Header, sizeof Header); - - Out << Manifest.ChunkHash << Manifest.Id << Manifest.Root; -} - -void -ReadManifest(SnapshotManifest& Manifest, InStream& FromStream) -{ - BinaryReader Reader(FromStream); - SerializedManifestHeader Header; - Reader.Read(&Header, sizeof Header); - - Reader >> Manifest.ChunkHash >> Manifest.Id >> Manifest.Root; -} - -void -PrintManifest(const SnapshotManifest& Manifest, OutStream& ToStream) -{ - IndentTextWriter Writer(ToStream); - - Writer << "hash: " << Manifest.ChunkHash << "\n"; - Writer << "id: " << Manifest.Id << "\n"; - Writer << "root: " - << "\n"; - IndentTextWriter::Scope _(Writer); - Writer << Manifest.Root; -} - -std::filesystem::path -ManifestSpecToPath(const char* ManifestSpec) -{ - ExtendableWideStringBuilder<128> ManifestTargetFile; - - if (ManifestSpec[0] == '#') - { - // Pick sensible default - - WCHAR MyDocumentsDir[MAX_PATH]; - HRESULT hRes = SHGetFolderPathW(NULL, - CSIDL_PERSONAL /* My Documents */, - NULL, - SHGFP_TYPE_CURRENT, - /* out */ MyDocumentsDir); - - if (SUCCEEDED(hRes)) - { - wcscat_s(MyDocumentsDir, L"\\zenfs\\Snapshots\\"); - - ManifestTargetFile.Append(MyDocumentsDir); - ManifestTargetFile.AppendAscii(ManifestSpec + 1); - } - } - else - { - ManifestTargetFile.AppendAscii(ManifestSpec); - } - - std::filesystem::path ManifestPath{ManifestTargetFile.c_str()}; - - if (ManifestPath.extension() != L".zenfs") - { - ManifestPath.append(L".zenfs"); - } - - return ManifestPath; -} - -////////////////////////////////////////////////////////////////////////// -// -// Testing related code follows... -// - -#if ZEN_WITH_TESTS - -void -snapshotmanifest_forcelink() -{ -} - -TEST_CASE("Snapshot manifest") -{ - SnapshotManifest Manifest; - - Manifest.Id = "test_manifest"; - Manifest.ChunkHash = zen::BLAKE3::HashMemory("abcd", 4); - - MemoryOutStream Outstream; - WriteManifest(Manifest, Outstream); - - MemoryInStream Instream(Outstream.Data(), Outstream.Size()); - SnapshotManifest Manifest2; - ReadManifest(/* out */ Manifest2, Instream); - - CHECK(Manifest.Id == Manifest2.Id); - CHECK(Manifest.ChunkHash == Manifest2.ChunkHash); -} - -#endif - -} // namespace zen diff --git a/zencore/zencore.cpp b/zencore/zencore.cpp index 185b191f4..b025f5b5c 100644 --- a/zencore/zencore.cpp +++ b/zencore/zencore.cpp @@ -20,7 +20,6 @@ #include <zencore/memory.h> #include <zencore/refcount.h> #include <zencore/sha1.h> -#include <zencore/snapshot_manifest.h> #include <zencore/stats.h> #include <zencore/stream.h> #include <zencore/string.h> @@ -114,7 +113,6 @@ zencore_forcelinktests() zen::memory_forcelink(); zen::refcount_forcelink(); zen::sha1_forcelink(); - zen::snapshotmanifest_forcelink(); zen::stats_forcelink(); zen::stream_forcelink(); zen::string_forcelink(); diff --git a/zencore/zencore.vcxproj b/zencore/zencore.vcxproj index 46ec02892..f0eae411e 100644 --- a/zencore/zencore.vcxproj +++ b/zencore/zencore.vcxproj @@ -136,7 +136,6 @@ <ClInclude Include="include\zencore\sha1.h" /> <ClInclude Include="include\zencore\iobuffer.h" /> <ClInclude Include="include\zencore\sharedbuffer.h" /> - <ClInclude Include="include\zencore\snapshot_manifest.h" /> <ClInclude Include="include\zencore\stats.h" /> <ClInclude Include="include\zencore\stream.h" /> <ClInclude Include="include\zencore\streamutil.h" /> @@ -178,7 +177,6 @@ </ClCompile> <ClCompile Include="iobuffer.cpp" /> <ClCompile Include="sharedbuffer.cpp" /> - <ClCompile Include="snapshot_manifest.cpp" /> <ClCompile Include="stats.cpp" /> <ClCompile Include="stream.cpp" /> <ClCompile Include="streamutil.cpp" /> diff --git a/zencore/zencore.vcxproj.filters b/zencore/zencore.vcxproj.filters index b09eb1b73..b9c69a33f 100644 --- a/zencore/zencore.vcxproj.filters +++ b/zencore/zencore.vcxproj.filters @@ -4,7 +4,6 @@ <ClInclude Include="include\zencore\intmath.h" /> <ClInclude Include="include\zencore\scopeguard.h" /> <ClInclude Include="include\zencore\sha1.h" /> - <ClInclude Include="include\zencore\snapshot_manifest.h" /> <ClInclude Include="include\zencore\targetver.h" /> <ClInclude Include="include\zencore\zencore.h" /> <ClInclude Include="include\zencore\compactbinary.h" /> @@ -46,7 +45,6 @@ <ClInclude Include="include\zencore\testing.h" /> </ItemGroup> <ItemGroup> - <ClCompile Include="snapshot_manifest.cpp" /> <ClCompile Include="sha1.cpp" /> <ClCompile Include="zencore.cpp" /> <ClCompile Include="compactbinary.cpp" /> diff --git a/zenserver/admin/admin.h b/zenserver/admin/admin.h index f90ad4537..3554b1005 100644 --- a/zenserver/admin/admin.h +++ b/zenserver/admin/admin.h @@ -4,6 +4,8 @@ #include <zenhttp/httpserver.h> +namespace zen { + class HttpAdminService : public zen::HttpService { public: @@ -16,3 +18,5 @@ public: private: }; + +} // namespace zen diff --git a/zenserver/cache/structuredcache.cpp b/zenserver/cache/structuredcache.cpp index c66b1f98d..b3867bbc3 100644 --- a/zenserver/cache/structuredcache.cpp +++ b/zenserver/cache/structuredcache.cpp @@ -67,7 +67,7 @@ enum class CachePolicy : uint8_t gsl_DEFINE_ENUM_BITMASK_OPERATORS(CachePolicy); CachePolicy -ParseCachePolicy(const zen::HttpServerRequest::QueryParams& QueryParams) +ParseCachePolicy(const HttpServerRequest::QueryParams& QueryParams) { CachePolicy QueryPolicy = CachePolicy::Query; @@ -76,7 +76,7 @@ ParseCachePolicy(const zen::HttpServerRequest::QueryParams& QueryParams) if (!Opts.empty()) { QueryPolicy = CachePolicy::None; - zen::ForEachStrTok(Opts, ',', [&QueryPolicy](const std::string_view& Opt) { + ForEachStrTok(Opts, ',', [&QueryPolicy](const std::string_view& Opt) { if (Opt == detail::cacheopt::Local) { QueryPolicy |= CachePolicy::QueryLocal; @@ -97,7 +97,7 @@ ParseCachePolicy(const zen::HttpServerRequest::QueryParams& QueryParams) if (!Opts.empty()) { StorePolicy = CachePolicy::None; - zen::ForEachStrTok(Opts, ',', [&StorePolicy](const std::string_view& Opt) { + ForEachStrTok(Opts, ',', [&StorePolicy](const std::string_view& Opt) { if (Opt == detail::cacheopt::Local) { StorePolicy |= CachePolicy::StoreLocal; @@ -117,7 +117,7 @@ ParseCachePolicy(const zen::HttpServerRequest::QueryParams& QueryParams) std::string_view Opts = QueryParams.GetValue("skip"sv); if (!Opts.empty()) { - zen::ForEachStrTok(Opts, ',', [&SkipPolicy](const std::string_view& Opt) { + ForEachStrTok(Opts, ',', [&SkipPolicy](const std::string_view& Opt) { if (Opt == detail::cacheopt::Meta) { SkipPolicy |= CachePolicy::SkipMeta; @@ -144,11 +144,11 @@ ParseCachePolicy(const zen::HttpServerRequest::QueryParams& QueryParams) ////////////////////////////////////////////////////////////////////////// -HttpStructuredCacheService::HttpStructuredCacheService(::ZenCacheStore& InCacheStore, - zen::CasStore& InStore, - zen::CidStore& InCidStore, +HttpStructuredCacheService::HttpStructuredCacheService(ZenCacheStore& InCacheStore, + CasStore& InStore, + CidStore& InCidStore, std::unique_ptr<UpstreamCache> UpstreamCache) -: m_Log(zen::logging::Get("cache")) +: m_Log(logging::Get("cache")) , m_CacheStore(InCacheStore) , m_CasStore(InStore) , m_CidStore(InCidStore) @@ -173,7 +173,7 @@ HttpStructuredCacheService::Flush() } void -HttpStructuredCacheService::HandleRequest(zen::HttpServerRequest& Request) +HttpStructuredCacheService::HandleRequest(HttpServerRequest& Request) { CacheRef Ref; @@ -188,7 +188,7 @@ HttpStructuredCacheService::HandleRequest(zen::HttpServerRequest& Request) return HandleCacheBucketRequest(Request, Key); } - return Request.WriteResponse(zen::HttpResponseCode::BadRequest); // invalid URL + return Request.WriteResponse(HttpResponseCode::BadRequest); // invalid URL } const auto QueryParams = Request.GetQueryParams(); @@ -207,12 +207,12 @@ HttpStructuredCacheService::HandleRequest(zen::HttpServerRequest& Request) } void -HttpStructuredCacheService::HandleCacheBucketRequest(zen::HttpServerRequest& Request, std::string_view Bucket) +HttpStructuredCacheService::HandleCacheBucketRequest(HttpServerRequest& Request, std::string_view Bucket) { ZEN_UNUSED(Request, Bucket); switch (auto Verb = Request.RequestVerb()) { - using enum zen::HttpVerb; + using enum HttpVerb; case kHead: case kGet: @@ -226,22 +226,22 @@ HttpStructuredCacheService::HandleCacheBucketRequest(zen::HttpServerRequest& Req if (m_CacheStore.DropBucket(Bucket)) { - return Request.WriteResponse(zen::HttpResponseCode::OK); + return Request.WriteResponse(HttpResponseCode::OK); } else { - return Request.WriteResponse(zen::HttpResponseCode::NotFound); + return Request.WriteResponse(HttpResponseCode::NotFound); } break; } } void -HttpStructuredCacheService::HandleCacheRecordRequest(zen::HttpServerRequest& Request, CacheRef& Ref, CachePolicy Policy) +HttpStructuredCacheService::HandleCacheRecordRequest(HttpServerRequest& Request, CacheRef& Ref, CachePolicy Policy) { switch (auto Verb = Request.RequestVerb()) { - using enum zen::HttpVerb; + using enum HttpVerb; case kHead: case kGet: @@ -253,7 +253,7 @@ HttpStructuredCacheService::HandleCacheRecordRequest(zen::HttpServerRequest& Req bool InUpstreamCache = false; const bool QueryUpstream = - !Success && m_UpstreamCache && (zen::CachePolicy::QueryRemote == (Policy & zen::CachePolicy::QueryRemote)); + !Success && m_UpstreamCache && (CachePolicy::QueryRemote == (Policy & CachePolicy::QueryRemote)); if (QueryUpstream) { @@ -272,14 +272,14 @@ HttpStructuredCacheService::HandleCacheRecordRequest(zen::HttpServerRequest& Req { if (CacheRecordType == ZenContentType::kCbObject) { - const zen::CbValidateError ValidationResult = - zen::ValidateCompactBinary(UpstreamResult.Value, zen::CbValidateMode::All); + const CbValidateError ValidationResult = + ValidateCompactBinary(UpstreamResult.Value, CbValidateMode::All); if (ValidationResult == CbValidateError::None) { - zen::CbObjectView CacheRecord(UpstreamResult.Value.Data()); + CbObjectView CacheRecord(UpstreamResult.Value.Data()); - zen::CbObjectWriter IndexData; + CbObjectWriter IndexData; IndexData.BeginArray("references"); CacheRecord.IterateAttachments([&](CbFieldView Attachment) { IndexData.AddHash(Attachment.AsHash()); }); IndexData.EndArray(); @@ -355,7 +355,7 @@ HttpStructuredCacheService::HandleCacheRecordRequest(zen::HttpServerRequest& Req { ZEN_DEBUG("MISS - '{}/{}'", Ref.BucketSegment, Ref.HashKey); - return Request.WriteResponse(zen::HttpResponseCode::NotFound); + return Request.WriteResponse(HttpResponseCode::NotFound); } if (Verb == kHead) @@ -367,13 +367,13 @@ HttpStructuredCacheService::HandleCacheRecordRequest(zen::HttpServerRequest& Req { CbObjectView CacheRecord(Value.Value.Data()); - const zen::CbValidateError ValidationResult = zen::ValidateCompactBinary(Value.Value, zen::CbValidateMode::All); + const CbValidateError ValidationResult = ValidateCompactBinary(Value.Value, CbValidateMode::All); if (ValidationResult != CbValidateError::None) { ZEN_WARN("GET - cache record '{}/{}' FAILED, invalid compact binary object", Ref.BucketSegment, Ref.HashKey); - return Request.WriteResponse(zen::HttpResponseCode::NotFound, HttpContentType::kText, "Invalid cache record"sv); + return Request.WriteResponse(HttpResponseCode::NotFound, HttpContentType::kText, "Invalid cache record"sv); } uint32_t AttachmentCount = 0; @@ -401,7 +401,7 @@ HttpStructuredCacheService::HandleCacheRecordRequest(zen::HttpServerRequest& Req FoundCount, AttachmentCount); - return Request.WriteResponse(zen::HttpResponseCode::NotFound, HttpContentType::kText, "Missing attachments"sv); + return Request.WriteResponse(HttpResponseCode::NotFound, HttpContentType::kText, "Missing attachments"sv); } Package.SetObject(LoadCompactBinaryObject(Value.Value)); @@ -419,7 +419,7 @@ HttpStructuredCacheService::HandleCacheRecordRequest(zen::HttpServerRequest& Req IoBuffer Response(IoBuffer::Clone, MemStream.Data(), MemStream.Size()); - return Request.WriteResponse(zen::HttpResponseCode::OK, HttpContentType::kCbPackage, Response); + return Request.WriteResponse(HttpResponseCode::OK, HttpContentType::kCbPackage, Response); } else { @@ -429,23 +429,23 @@ HttpStructuredCacheService::HandleCacheRecordRequest(zen::HttpServerRequest& Req NiceBytes(Value.Value.Size()), InUpstreamCache ? "UPSTREAM" : "LOCAL"); - return Request.WriteResponse(zen::HttpResponseCode::OK, Value.Value.GetContentType(), Value.Value); + return Request.WriteResponse(HttpResponseCode::OK, Value.Value.GetContentType(), Value.Value); } } break; case kPut: { - zen::IoBuffer Body = Request.ReadPayload(); + IoBuffer Body = Request.ReadPayload(); if (!Body || Body.Size() == 0) { - return Request.WriteResponse(zen::HttpResponseCode::BadRequest); + return Request.WriteResponse(HttpResponseCode::BadRequest); } const HttpContentType ContentType = Request.RequestContentType(); - const bool StoreUpstream = m_UpstreamCache && (zen::CachePolicy::StoreRemote == (Policy & zen::CachePolicy::StoreRemote)); + const bool StoreUpstream = m_UpstreamCache && (CachePolicy::StoreRemote == (Policy & CachePolicy::StoreRemote)); if (ContentType == HttpContentType::kBinary || ContentType == HttpContentType::kUnknownContentType) { @@ -459,13 +459,13 @@ HttpStructuredCacheService::HandleCacheRecordRequest(zen::HttpServerRequest& Req {.Type = ZenContentType::kBinary, .CacheKey = {Ref.BucketSegment, Ref.HashKey}}); } - return Request.WriteResponse(zen::HttpResponseCode::Created); + return Request.WriteResponse(HttpResponseCode::Created); } else if (ContentType == HttpContentType::kCbObject) { // Validate payload before accessing it - const zen::CbValidateError ValidationResult = - zen::ValidateCompactBinary(MemoryView(Body.Data(), Body.Size()), zen::CbValidateMode::All); + const CbValidateError ValidationResult = + ValidateCompactBinary(MemoryView(Body.Data(), Body.Size()), CbValidateMode::All); if (ValidationResult != CbValidateError::None) { @@ -481,7 +481,7 @@ HttpStructuredCacheService::HandleCacheRecordRequest(zen::HttpServerRequest& Req } // Extract referenced payload hashes - zen::CbObjectView Cbo(Body.Data()); + CbObjectView Cbo(Body.Data()); std::vector<IoHash> References; std::vector<IoHash> MissingRefs; @@ -492,7 +492,7 @@ HttpStructuredCacheService::HandleCacheRecordRequest(zen::HttpServerRequest& Req if (!References.empty()) { - zen::CbObjectWriter Idx; + CbObjectWriter Idx; Idx.BeginArray("references"); for (const IoHash& Hash : References) @@ -514,7 +514,7 @@ HttpStructuredCacheService::HandleCacheRecordRequest(zen::HttpServerRequest& Req ZEN_DEBUG("PUT - cache record '{}/{}' {}, {}/{} attachments missing", Ref.BucketSegment, Ref.HashKey, - zen::NiceBytes(CacheValue.Value.Size()), + NiceBytes(CacheValue.Value.Size()), MissingRefs.size(), References.size()); @@ -525,12 +525,12 @@ HttpStructuredCacheService::HandleCacheRecordRequest(zen::HttpServerRequest& Req .CacheKey = {Ref.BucketSegment, Ref.HashKey}, .PayloadIds = std::move(References)}); - return Request.WriteResponse(zen::HttpResponseCode::Created); + return Request.WriteResponse(HttpResponseCode::Created); } else { // TODO: Binary attachments? - zen::CbObjectWriter Response; + CbObjectWriter Response; Response.BeginArray("needs"); for (const IoHash& MissingRef : MissingRefs) { @@ -540,7 +540,7 @@ HttpStructuredCacheService::HandleCacheRecordRequest(zen::HttpServerRequest& Req Response.EndArray(); // Return Created | BadRequest? - return Request.WriteResponse(zen::HttpResponseCode::Created, Response.Save()); + return Request.WriteResponse(HttpResponseCode::Created, Response.Save()); } } else if (ContentType == HttpContentType::kCbPackage) @@ -631,17 +631,17 @@ HttpStructuredCacheService::HandleCacheRecordRequest(zen::HttpServerRequest& Req ZEN_DEBUG("PUT - cache record '{}/{}' {}, {}/{} ({}/{}) new attachments", Ref.BucketSegment, Ref.HashKey, - zen::NiceBytes(TotalPackageBytes), + NiceBytes(TotalPackageBytes), AttachmentResult.NewCount, AttachmentResult.Count, - zen::NiceBytes(AttachmentResult.NewBytes), - zen::NiceBytes(AttachmentResult.Bytes)); + NiceBytes(AttachmentResult.NewBytes), + NiceBytes(AttachmentResult.Bytes)); - return Request.WriteResponse(zen::HttpResponseCode::Created); + return Request.WriteResponse(HttpResponseCode::Created); } else { - return Request.WriteResponse(zen::HttpResponseCode::BadRequest); + return Request.WriteResponse(HttpResponseCode::BadRequest); } } break; @@ -655,7 +655,7 @@ HttpStructuredCacheService::HandleCacheRecordRequest(zen::HttpServerRequest& Req } void -HttpStructuredCacheService::HandleCachePayloadRequest(zen::HttpServerRequest& Request, CacheRef& Ref, CachePolicy Policy) +HttpStructuredCacheService::HandleCachePayloadRequest(HttpServerRequest& Request, CacheRef& Ref, CachePolicy Policy) { // Note: the URL references the uncompressed payload hash - so this maintains the mapping // from uncompressed CAS identity (aka CID/Content ID) to the stored payload hash @@ -667,12 +667,12 @@ HttpStructuredCacheService::HandleCachePayloadRequest(zen::HttpServerRequest& Re switch (auto Verb = Request.RequestVerb()) { - using enum zen::HttpVerb; + using enum HttpVerb; case kHead: case kGet: { - zen::IoBuffer Payload = m_CidStore.FindChunkByCid(Ref.PayloadId); + IoBuffer Payload = m_CidStore.FindChunkByCid(Ref.PayloadId); bool InUpstreamCache = false; if (!Payload && m_UpstreamCache) @@ -680,11 +680,11 @@ HttpStructuredCacheService::HandleCachePayloadRequest(zen::HttpServerRequest& Re if (auto UpstreamResult = m_UpstreamCache->GetCachePayload({{Ref.BucketSegment, Ref.HashKey}, Ref.PayloadId}); UpstreamResult.Success) { - if (zen::CompressedBuffer Compressed = zen::CompressedBuffer::FromCompressed(SharedBuffer(UpstreamResult.Value))) + if (CompressedBuffer Compressed = CompressedBuffer::FromCompressed(SharedBuffer(UpstreamResult.Value))) { Payload = UpstreamResult.Value; - zen::IoHash ChunkHash = zen::IoHash::HashBuffer(Payload); - zen::CasStore::InsertResult Result = m_CasStore.InsertChunk(Payload, ChunkHash); + IoHash ChunkHash = IoHash::HashBuffer(Payload); + CasStore::InsertResult Result = m_CasStore.InsertChunk(Payload, ChunkHash); InUpstreamCache = true; m_CidStore.AddCompressedCid(Ref.PayloadId, ChunkHash); @@ -699,7 +699,7 @@ HttpStructuredCacheService::HandleCachePayloadRequest(zen::HttpServerRequest& Re if (!Payload) { ZEN_DEBUG("MISS - '{}/{}/{}'", Ref.BucketSegment, Ref.HashKey, Ref.PayloadId); - return Request.WriteResponse(zen::HttpResponseCode::NotFound); + return Request.WriteResponse(HttpResponseCode::NotFound); } ZEN_DEBUG("HIT - '{}/{}/{}' {} (type: {}) ({})", @@ -715,29 +715,29 @@ HttpStructuredCacheService::HandleCachePayloadRequest(zen::HttpServerRequest& Re Request.SetSuppressResponseBody(); } - return Request.WriteResponse(zen::HttpResponseCode::OK, zen::HttpContentType::kBinary, Payload); + return Request.WriteResponse(HttpResponseCode::OK, HttpContentType::kBinary, Payload); } break; case kPut: { - if (zen::IoBuffer Body = Request.ReadPayload()) + if (IoBuffer Body = Request.ReadPayload()) { if (Body.Size() == 0) { - return Request.WriteResponse(zen::HttpResponseCode::BadRequest, + return Request.WriteResponse(HttpResponseCode::BadRequest, HttpContentType::kText, "Empty payload not permitted"); } - zen::IoHash ChunkHash = zen::IoHash::HashBuffer(Body); + IoHash ChunkHash = IoHash::HashBuffer(Body); - zen::CompressedBuffer Compressed = zen::CompressedBuffer::FromCompressed(SharedBuffer(Body)); + CompressedBuffer Compressed = CompressedBuffer::FromCompressed(SharedBuffer(Body)); if (!Compressed) { // All attachment payloads need to be in compressed buffer format - return Request.WriteResponse(zen::HttpResponseCode::BadRequest, + return Request.WriteResponse(HttpResponseCode::BadRequest, HttpContentType::kText, "Attachments must be compressed"); } @@ -749,7 +749,7 @@ HttpStructuredCacheService::HandleCachePayloadRequest(zen::HttpServerRequest& Re return Request.WriteResponse(HttpResponseCode::BadRequest); } - zen::CasStore::InsertResult Result = m_CasStore.InsertChunk(Body, ChunkHash); + CasStore::InsertResult Result = m_CasStore.InsertChunk(Body, ChunkHash); m_CidStore.AddCompressedCid(Ref.PayloadId, ChunkHash); @@ -763,11 +763,11 @@ HttpStructuredCacheService::HandleCachePayloadRequest(zen::HttpServerRequest& Re if (Result.New) { - return Request.WriteResponse(zen::HttpResponseCode::Created); + return Request.WriteResponse(HttpResponseCode::Created); } else { - return Request.WriteResponse(zen::HttpResponseCode::OK); + return Request.WriteResponse(HttpResponseCode::OK); } } } @@ -783,7 +783,7 @@ HttpStructuredCacheService::HandleCachePayloadRequest(zen::HttpServerRequest& Re } bool -HttpStructuredCacheService::ValidateKeyUri(zen::HttpServerRequest& Request, CacheRef& OutRef) +HttpStructuredCacheService::ValidateKeyUri(HttpServerRequest& Request, CacheRef& OutRef) { std::string_view Key = Request.RelativeUri(); std::string_view::size_type BucketSplitOffset = Key.find_first_of('/'); @@ -819,14 +819,14 @@ HttpStructuredCacheService::ValidateKeyUri(zen::HttpServerRequest& Request, Cach PayloadSegment = Key.substr(PayloadSplitOffset + 1); } - if (HashSegment.size() != zen::IoHash::StringLength) + if (HashSegment.size() != IoHash::StringLength) { return false; } - if (!PayloadSegment.empty() && PayloadSegment.size() == zen::IoHash::StringLength) + if (!PayloadSegment.empty() && PayloadSegment.size() == IoHash::StringLength) { - const bool IsOk = zen::ParseHexBytes(PayloadSegment.data(), PayloadSegment.size(), OutRef.PayloadId.Hash); + const bool IsOk = ParseHexBytes(PayloadSegment.data(), PayloadSegment.size(), OutRef.PayloadId.Hash); if (!IsOk) { @@ -835,10 +835,10 @@ HttpStructuredCacheService::ValidateKeyUri(zen::HttpServerRequest& Request, Cach } else { - OutRef.PayloadId = zen::IoHash::Zero; + OutRef.PayloadId = IoHash::Zero; } - const bool IsOk = zen::ParseHexBytes(HashSegment.data(), HashSegment.size(), OutRef.HashKey.Hash); + const bool IsOk = ParseHexBytes(HashSegment.data(), HashSegment.size(), OutRef.HashKey.Hash); if (!IsOk) { diff --git a/zenserver/cache/structuredcache.h b/zenserver/cache/structuredcache.h index 796b21d1f..8871094b3 100644 --- a/zenserver/cache/structuredcache.h +++ b/zenserver/cache/structuredcache.h @@ -10,13 +10,12 @@ namespace spdlog { class logger; } -class ZenCacheStore; - namespace zen { class CasStore; class CidStore; class UpstreamCache; +class ZenCacheStore; enum class CachePolicy : uint8_t; /** @@ -77,7 +76,7 @@ private: spdlog::logger& Log() { return m_Log; } spdlog::logger& m_Log; - ZenCacheStore& m_CacheStore; + zen::ZenCacheStore& m_CacheStore; zen::CasStore& m_CasStore; zen::CidStore& m_CidStore; std::unique_ptr<UpstreamCache> m_UpstreamCache; diff --git a/zenserver/cache/structuredcachestore.cpp b/zenserver/cache/structuredcachestore.cpp index 018955e65..14f4531ab 100644 --- a/zenserver/cache/structuredcachestore.cpp +++ b/zenserver/cache/structuredcachestore.cpp @@ -24,15 +24,16 @@ #include <atlfile.h> -using namespace zen; -using namespace fmt::literals; - ////////////////////////////////////////////////////////////////////////// -ZenCacheStore::ZenCacheStore(zen::CasStore& Cas, const std::filesystem::path& RootDir) : m_DiskLayer{Cas, RootDir} +namespace zen { + +using namespace fmt::literals; + +ZenCacheStore::ZenCacheStore(CasStore& Cas, const std::filesystem::path& RootDir) : m_DiskLayer{Cas, RootDir} { ZEN_INFO("initializing structured cache at '{}'", RootDir); - zen::CreateDirectories(RootDir); + CreateDirectories(RootDir); } ZenCacheStore::~ZenCacheStore() @@ -40,7 +41,7 @@ ZenCacheStore::~ZenCacheStore() } bool -ZenCacheStore::Get(std::string_view InBucket, const zen::IoHash& HashKey, ZenCacheValue& OutValue) +ZenCacheStore::Get(std::string_view InBucket, const IoHash& HashKey, ZenCacheValue& OutValue) { bool Ok = m_MemLayer.Get(InBucket, HashKey, OutValue); @@ -68,7 +69,7 @@ ZenCacheStore::Get(std::string_view InBucket, const zen::IoHash& HashKey, ZenCac } void -ZenCacheStore::Put(std::string_view InBucket, const zen::IoHash& HashKey, const ZenCacheValue& Value) +ZenCacheStore::Put(std::string_view InBucket, const IoHash& HashKey, const ZenCacheValue& Value) { // Store value and index @@ -115,7 +116,7 @@ ZenCacheMemoryLayer::~ZenCacheMemoryLayer() } bool -ZenCacheMemoryLayer::Get(std::string_view InBucket, const zen::IoHash& HashKey, ZenCacheValue& OutValue) +ZenCacheMemoryLayer::Get(std::string_view InBucket, const IoHash& HashKey, ZenCacheValue& OutValue) { CacheBucket* Bucket = nullptr; @@ -139,7 +140,7 @@ ZenCacheMemoryLayer::Get(std::string_view InBucket, const zen::IoHash& HashKey, } void -ZenCacheMemoryLayer::Put(std::string_view InBucket, const zen::IoHash& HashKey, const ZenCacheValue& Value) +ZenCacheMemoryLayer::Put(std::string_view InBucket, const IoHash& HashKey, const ZenCacheValue& Value) { CacheBucket* Bucket = nullptr; @@ -179,7 +180,7 @@ ZenCacheMemoryLayer::DropBucket(std::string_view Bucket) } bool -ZenCacheMemoryLayer::CacheBucket::Get(const zen::IoHash& HashKey, ZenCacheValue& OutValue) +ZenCacheMemoryLayer::CacheBucket::Get(const IoHash& HashKey, ZenCacheValue& OutValue) { RwLock::SharedLockScope _(m_bucketLock); @@ -196,7 +197,7 @@ ZenCacheMemoryLayer::CacheBucket::Get(const zen::IoHash& HashKey, ZenCacheValue& } void -ZenCacheMemoryLayer::CacheBucket::Put(const zen::IoHash& HashKey, const ZenCacheValue& Value) +ZenCacheMemoryLayer::CacheBucket::Put(const IoHash& HashKey, const ZenCacheValue& Value) { RwLock::ExclusiveLockScope _(m_bucketLock); @@ -227,7 +228,7 @@ struct DiskLocation struct DiskIndexEntry { - zen::IoHash Key; + IoHash Key; DiskLocation Location; }; @@ -243,8 +244,8 @@ struct ZenCacheDiskLayer::CacheBucket void OpenOrCreate(std::filesystem::path BucketDir); static bool Delete(std::filesystem::path BucketDir); - bool Get(const zen::IoHash& HashKey, ZenCacheValue& OutValue); - void Put(const zen::IoHash& HashKey, const ZenCacheValue& Value); + bool Get(const IoHash& HashKey, ZenCacheValue& OutValue); + void Put(const IoHash& HashKey, const ZenCacheValue& Value); void Drop(); void Flush(); @@ -260,12 +261,12 @@ private: BasicFile m_SobsFile; TCasLogFile<DiskIndexEntry> m_SlogFile; - void BuildPath(zen::WideStringBuilderBase& Path, const zen::IoHash& HashKey); - void PutLargeObject(const zen::IoHash& HashKey, const ZenCacheValue& Value); + void BuildPath(WideStringBuilderBase& Path, const IoHash& HashKey); + void PutLargeObject(const IoHash& HashKey, const ZenCacheValue& Value); - RwLock m_IndexLock; - tsl::robin_map<zen::IoHash, DiskLocation, zen::IoHash::Hasher> m_Index; - uint64_t m_WriteCursor = 0; + RwLock m_IndexLock; + tsl::robin_map<IoHash, DiskLocation, IoHash::Hasher> m_Index; + uint64_t m_WriteCursor = 0; }; ZenCacheDiskLayer::CacheBucket::CacheBucket(CasStore& Cas) : m_CasStore(Cas) @@ -281,7 +282,7 @@ ZenCacheDiskLayer::CacheBucket::Delete(std::filesystem::path BucketDir) { if (std::filesystem::exists(BucketDir)) { - zen::DeleteDirectories(BucketDir); + DeleteDirectories(BucketDir); return true; } @@ -292,7 +293,7 @@ ZenCacheDiskLayer::CacheBucket::Delete(std::filesystem::path BucketDir) void ZenCacheDiskLayer::CacheBucket::OpenOrCreate(std::filesystem::path BucketDir) { - zen::CreateDirectories(BucketDir); + CreateDirectories(BucketDir); m_BucketDir = BucketDir; @@ -357,7 +358,7 @@ ZenCacheDiskLayer::CacheBucket::OpenOrCreate(std::filesystem::path BucketDir) uint64_t MaxFileOffset = 0; - if (zen::RwLock::ExclusiveLockScope _(m_IndexLock); m_Index.empty()) + if (RwLock::ExclusiveLockScope _(m_IndexLock); m_Index.empty()) { m_SlogFile.Replay([&](const DiskIndexEntry& Record) { m_Index[Record.Key] = Record.Location; @@ -372,7 +373,7 @@ ZenCacheDiskLayer::CacheBucket::OpenOrCreate(std::filesystem::path BucketDir) } void -ZenCacheDiskLayer::CacheBucket::BuildPath(zen::WideStringBuilderBase& Path, const zen::IoHash& HashKey) +ZenCacheDiskLayer::CacheBucket::BuildPath(WideStringBuilderBase& Path, const IoHash& HashKey) { char hex[sizeof(HashKey.Hash) * 2]; ToHexBytes(HashKey.Hash, sizeof HashKey.Hash, hex); @@ -383,14 +384,14 @@ ZenCacheDiskLayer::CacheBucket::BuildPath(zen::WideStringBuilderBase& Path, cons } bool -ZenCacheDiskLayer::CacheBucket::Get(const zen::IoHash& HashKey, ZenCacheValue& OutValue) +ZenCacheDiskLayer::CacheBucket::Get(const IoHash& HashKey, ZenCacheValue& OutValue) { if (!m_Ok) { return false; } - zen::RwLock::SharedLockScope _(m_IndexLock); + RwLock::SharedLockScope _(m_IndexLock); if (auto it = m_Index.find(HashKey); it != m_Index.end()) { @@ -417,7 +418,7 @@ ZenCacheDiskLayer::CacheBucket::Get(const zen::IoHash& HashKey, ZenCacheValue& O WideStringBuilder<128> DataFilePath; BuildPath(DataFilePath, HashKey); - if (zen::IoBuffer Data = IoBufferBuilder::MakeFromFile(DataFilePath.c_str())) + if (IoBuffer Data = IoBufferBuilder::MakeFromFile(DataFilePath.c_str())) { OutValue.Value = Data; OutValue.Value.SetContentType(ContentType); @@ -431,7 +432,7 @@ ZenCacheDiskLayer::CacheBucket::Get(const zen::IoHash& HashKey, ZenCacheValue& O } void -ZenCacheDiskLayer::CacheBucket::Put(const zen::IoHash& HashKey, const ZenCacheValue& Value) +ZenCacheDiskLayer::CacheBucket::Put(const IoHash& HashKey, const ZenCacheValue& Value) { if (!m_Ok) { @@ -453,12 +454,12 @@ ZenCacheDiskLayer::CacheBucket::Put(const zen::IoHash& HashKey, const ZenCacheVa EntryFlags |= DiskLocation::kStructured; } - zen::RwLock::ExclusiveLockScope _(m_IndexLock); + RwLock::ExclusiveLockScope _(m_IndexLock); DiskLocation Loc{.OffsetAndFlags = DiskLocation::CombineOffsetAndFlags(m_WriteCursor, EntryFlags), .Size = gsl::narrow<uint32_t>(Value.Value.Size())}; - m_WriteCursor = zen::RoundUp(m_WriteCursor + Loc.Size, 16); + m_WriteCursor = RoundUp(m_WriteCursor + Loc.Size, 16); if (auto it = m_Index.find(HashKey); it == m_Index.end()) { @@ -483,7 +484,7 @@ ZenCacheDiskLayer::CacheBucket::Drop() m_SobsFile.Close(); m_SlogFile.Close(); - zen::DeleteDirectories(m_BucketDir); + DeleteDirectories(m_BucketDir); } void @@ -494,9 +495,9 @@ ZenCacheDiskLayer::CacheBucket::Flush() } void -ZenCacheDiskLayer::CacheBucket::PutLargeObject(const zen::IoHash& HashKey, const ZenCacheValue& Value) +ZenCacheDiskLayer::CacheBucket::PutLargeObject(const IoHash& HashKey, const ZenCacheValue& Value) { - zen::WideStringBuilder<128> DataFilePath; + WideStringBuilder<128> DataFilePath; BuildPath(DataFilePath, HashKey); // TODO: replace this with a more efficient implementation with proper atomic rename @@ -507,21 +508,21 @@ ZenCacheDiskLayer::CacheBucket::PutLargeObject(const zen::IoHash& HashKey, const if (FAILED(hRes)) { - zen::ThrowSystemException(hRes, "Failed to open temporary file for put at '{}'"_format(m_BucketDir)); + ThrowSystemException(hRes, "Failed to open temporary file for put at '{}'"_format(m_BucketDir)); } hRes = DataFile.Write(Value.Value.Data(), gsl::narrow<DWORD>(Value.Value.Size())); if (FAILED(hRes)) { - zen::ThrowSystemException(hRes, "Failed to write payload ({} bytes) to file"_format(NiceBytes(Value.Value.Size()))); + ThrowSystemException(hRes, "Failed to write payload ({} bytes) to file"_format(NiceBytes(Value.Value.Size()))); } hRes = DataFile.Close(DataFilePath.c_str()); if (FAILED(hRes)) { - zen::ThrowSystemException(hRes, "Failed to finalize file '{}'"_format(zen::WideToUtf8(DataFilePath))); + ThrowSystemException(hRes, "Failed to finalize file '{}'"_format(WideToUtf8(DataFilePath))); } // Update index @@ -533,7 +534,7 @@ ZenCacheDiskLayer::CacheBucket::PutLargeObject(const zen::IoHash& HashKey, const EntryFlags |= DiskLocation::kStructured; } - zen::RwLock::ExclusiveLockScope _(m_IndexLock); + RwLock::ExclusiveLockScope _(m_IndexLock); DiskLocation Loc{.OffsetAndFlags = DiskLocation::CombineOffsetAndFlags(0, EntryFlags), .Size = 0}; @@ -560,12 +561,12 @@ ZenCacheDiskLayer::ZenCacheDiskLayer(CasStore& Cas, const std::filesystem::path& ZenCacheDiskLayer::~ZenCacheDiskLayer() = default; bool -ZenCacheDiskLayer::Get(std::string_view InBucket, const zen::IoHash& HashKey, ZenCacheValue& OutValue) +ZenCacheDiskLayer::Get(std::string_view InBucket, const IoHash& HashKey, ZenCacheValue& OutValue) { CacheBucket* Bucket = nullptr; { - zen::RwLock::SharedLockScope _(m_Lock); + RwLock::SharedLockScope _(m_Lock); auto it = m_Buckets.find(std::string(InBucket)); @@ -579,7 +580,7 @@ ZenCacheDiskLayer::Get(std::string_view InBucket, const zen::IoHash& HashKey, Ze { // Bucket needs to be opened/created - zen::RwLock::ExclusiveLockScope _(m_Lock); + RwLock::ExclusiveLockScope _(m_Lock); if (auto it = m_Buckets.find(std::string(InBucket)); it != m_Buckets.end()) { @@ -603,12 +604,12 @@ ZenCacheDiskLayer::Get(std::string_view InBucket, const zen::IoHash& HashKey, Ze } void -ZenCacheDiskLayer::Put(std::string_view InBucket, const zen::IoHash& HashKey, const ZenCacheValue& Value) +ZenCacheDiskLayer::Put(std::string_view InBucket, const IoHash& HashKey, const ZenCacheValue& Value) { CacheBucket* Bucket = nullptr; { - zen::RwLock::SharedLockScope _(m_Lock); + RwLock::SharedLockScope _(m_Lock); auto it = m_Buckets.find(std::string(InBucket)); @@ -622,7 +623,7 @@ ZenCacheDiskLayer::Put(std::string_view InBucket, const zen::IoHash& HashKey, co { // New bucket needs to be created - zen::RwLock::ExclusiveLockScope _(m_Lock); + RwLock::ExclusiveLockScope _(m_Lock); if (auto it = m_Buckets.find(std::string(InBucket)); it != m_Buckets.end()) { @@ -651,7 +652,7 @@ ZenCacheDiskLayer::Put(std::string_view InBucket, const zen::IoHash& HashKey, co bool ZenCacheDiskLayer::DropBucket(std::string_view InBucket) { - zen::RwLock::ExclusiveLockScope _(m_Lock); + RwLock::ExclusiveLockScope _(m_Lock); auto it = m_Buckets.find(std::string(InBucket)); @@ -679,7 +680,7 @@ ZenCacheDiskLayer::Flush() Buckets.reserve(m_Buckets.size()); { - zen::RwLock::SharedLockScope _(m_Lock); + RwLock::SharedLockScope _(m_Lock); for (auto& Kv : m_Buckets) { @@ -705,7 +706,7 @@ ZenCacheTracker::~ZenCacheTracker() } void -ZenCacheTracker::TrackAccess(std::string_view Bucket, const zen::IoHash& HashKey) +ZenCacheTracker::TrackAccess(std::string_view Bucket, const IoHash& HashKey) { ZEN_UNUSED(Bucket); ZEN_UNUSED(HashKey); @@ -715,3 +716,5 @@ void ZenCacheTracker::Flush() { } + +} // namespace zen diff --git a/zenserver/cache/structuredcachestore.h b/zenserver/cache/structuredcachestore.h index 48c3cfde9..c4fa20958 100644 --- a/zenserver/cache/structuredcachestore.h +++ b/zenserver/cache/structuredcachestore.h @@ -23,8 +23,6 @@ namespace zen { class WideStringBuilderBase; class CasStore; -} // namespace zen - /****************************************************************************** /$$$$$$$$ /$$$$$$ /$$ @@ -44,8 +42,8 @@ class CasStore; struct ZenCacheValue { - zen::IoBuffer Value; - zen::CbObject IndexData; + IoBuffer Value; + CbObject IndexData; }; class ZenCacheMemoryLayer @@ -54,32 +52,32 @@ public: ZenCacheMemoryLayer(); ~ZenCacheMemoryLayer(); - bool Get(std::string_view Bucket, const zen::IoHash& HashKey, ZenCacheValue& OutValue); - void Put(std::string_view Bucket, const zen::IoHash& HashKey, const ZenCacheValue& Value); + bool Get(std::string_view Bucket, const IoHash& HashKey, ZenCacheValue& OutValue); + void Put(std::string_view Bucket, const IoHash& HashKey, const ZenCacheValue& Value); bool DropBucket(std::string_view Bucket); private: struct CacheBucket { - zen::RwLock m_bucketLock; - tsl::robin_map<zen::IoHash, zen::IoBuffer> m_cacheMap; + RwLock m_bucketLock; + tsl::robin_map<IoHash, IoBuffer> m_cacheMap; - bool Get(const zen::IoHash& HashKey, ZenCacheValue& OutValue); - void Put(const zen::IoHash& HashKey, const ZenCacheValue& Value); + bool Get(const IoHash& HashKey, ZenCacheValue& OutValue); + void Put(const IoHash& HashKey, const ZenCacheValue& Value); }; - zen::RwLock m_Lock; + RwLock m_Lock; std::unordered_map<std::string, CacheBucket> m_Buckets; }; class ZenCacheDiskLayer { public: - ZenCacheDiskLayer(zen::CasStore& Cas, const std::filesystem::path& RootDir); + ZenCacheDiskLayer(CasStore& Cas, const std::filesystem::path& RootDir); ~ZenCacheDiskLayer(); - bool Get(std::string_view Bucket, const zen::IoHash& HashKey, ZenCacheValue& OutValue); - void Put(std::string_view Bucket, const zen::IoHash& HashKey, const ZenCacheValue& Value); + bool Get(std::string_view Bucket, const IoHash& HashKey, ZenCacheValue& OutValue); + void Put(std::string_view Bucket, const IoHash& HashKey, const ZenCacheValue& Value); bool DropBucket(std::string_view Bucket); void Flush(); @@ -89,20 +87,20 @@ private: */ struct CacheBucket; - zen::CasStore& m_CasStore; + CasStore& m_CasStore; std::filesystem::path m_RootDir; - zen::RwLock m_Lock; + RwLock m_Lock; std::unordered_map<std::string, CacheBucket> m_Buckets; // TODO: make this case insensitive }; class ZenCacheStore { public: - ZenCacheStore(zen::CasStore& Cas, const std::filesystem::path& RootDir); + ZenCacheStore(CasStore& Cas, const std::filesystem::path& RootDir); ~ZenCacheStore(); - bool Get(std::string_view Bucket, const zen::IoHash& HashKey, ZenCacheValue& OutValue); - void Put(std::string_view Bucket, const zen::IoHash& HashKey, const ZenCacheValue& Value); + bool Get(std::string_view Bucket, const IoHash& HashKey, ZenCacheValue& OutValue); + void Put(std::string_view Bucket, const IoHash& HashKey, const ZenCacheValue& Value); bool DropBucket(std::string_view Bucket); void Flush(); @@ -121,8 +119,10 @@ public: ZenCacheTracker(ZenCacheStore& CacheStore); ~ZenCacheTracker(); - void TrackAccess(std::string_view Bucket, const zen::IoHash& HashKey); + void TrackAccess(std::string_view Bucket, const IoHash& HashKey); void Flush(); private: }; + +} // namespace zen diff --git a/zenserver/diag/diagsvcs.h b/zenserver/diag/diagsvcs.h index 51ee98f67..61703e393 100644 --- a/zenserver/diag/diagsvcs.h +++ b/zenserver/diag/diagsvcs.h @@ -7,7 +7,9 @@ ////////////////////////////////////////////////////////////////////////// -class HttpTestService : public zen::HttpService +namespace zen { + +class HttpTestService : public HttpService { uint32_t LogPoint = 0; @@ -17,7 +19,7 @@ public: virtual const char* BaseUri() const override { return "/test/"; } - virtual void HandleRequest(zen::HttpServerRequest& Request) override + virtual void HandleRequest(HttpServerRequest& Request) override { using namespace std::literals; @@ -25,21 +27,21 @@ public: if (Uri == "hello"sv) { - Request.WriteResponse(zen::HttpResponseCode::OK, zen::HttpContentType::kText, u8"hello world!"sv); + Request.WriteResponse(HttpResponseCode::OK, HttpContentType::kText, u8"hello world!"sv); // OutputLogMessageInternal(&LogPoint, 0, 0); } else if (Uri == "1K"sv) { - Request.WriteResponse(zen::HttpResponseCode::OK, zen::HttpContentType::kBinary, m_1k); + Request.WriteResponse(HttpResponseCode::OK, HttpContentType::kBinary, m_1k); } else if (Uri == "1M"sv) { - Request.WriteResponse(zen::HttpResponseCode::OK, zen::HttpContentType::kBinary, m_1m); + Request.WriteResponse(HttpResponseCode::OK, HttpContentType::kBinary, m_1m); } else if (Uri == "1M_1k"sv) { - std::vector<zen::IoBuffer> Buffers; + std::vector<IoBuffer> Buffers; Buffers.reserve(1024); for (int i = 0; i < 1024; ++i) @@ -47,11 +49,11 @@ public: Buffers.push_back(m_1k); } - Request.WriteResponse(zen::HttpResponseCode::OK, zen::HttpContentType::kBinary, Buffers); + Request.WriteResponse(HttpResponseCode::OK, HttpContentType::kBinary, Buffers); } else if (Uri == "1G"sv) { - std::vector<zen::IoBuffer> Buffers; + std::vector<IoBuffer> Buffers; Buffers.reserve(1024); for (int i = 0; i < 1024; ++i) @@ -59,11 +61,11 @@ public: Buffers.push_back(m_1m); } - Request.WriteResponse(zen::HttpResponseCode::OK, zen::HttpContentType::kBinary, Buffers); + Request.WriteResponse(HttpResponseCode::OK, HttpContentType::kBinary, Buffers); } else if (Uri == "1G_1k"sv) { - std::vector<zen::IoBuffer> Buffers; + std::vector<IoBuffer> Buffers; Buffers.reserve(1024 * 1024); for (int i = 0; i < 1024 * 1024; ++i) @@ -71,16 +73,16 @@ public: Buffers.push_back(m_1k); } - Request.WriteResponse(zen::HttpResponseCode::OK, zen::HttpContentType::kBinary, Buffers); + Request.WriteResponse(HttpResponseCode::OK, HttpContentType::kBinary, Buffers); } } private: - zen::IoBuffer m_1m{1024 * 1024}; - zen::IoBuffer m_1k{m_1m, 0u, 1024}; + IoBuffer m_1m{1024 * 1024}; + IoBuffer m_1k{m_1m, 0u, 1024}; }; -class HttpHealthService : public zen::HttpService +class HttpHealthService : public HttpService { public: HttpHealthService() = default; @@ -88,16 +90,18 @@ public: virtual const char* BaseUri() const override { return "/health/"; } - virtual void HandleRequest(zen::HttpServerRequest& Request) override + virtual void HandleRequest(HttpServerRequest& Request) override { using namespace std::literals; switch (Request.RequestVerb()) { - case zen::HttpVerb::kGet: - return Request.WriteResponse(zen::HttpResponseCode::OK, zen::HttpContentType::kText, u8"OK!"sv); + case HttpVerb::kGet: + return Request.WriteResponse(HttpResponseCode::OK, HttpContentType::kText, u8"OK!"sv); } } private: }; + +} // namespace zen diff --git a/zenserver/upstream/upstreamcache.cpp b/zenserver/upstream/upstreamcache.cpp index ecd540445..5b7680be2 100644 --- a/zenserver/upstream/upstreamcache.cpp +++ b/zenserver/upstream/upstreamcache.cpp @@ -94,7 +94,7 @@ namespace detail { std::atomic_bool m_CompleteAdding{false}; }; - class JupiterUpstreamEndpoint final : public zen::UpstreamEndpoint + class JupiterUpstreamEndpoint final : public UpstreamEndpoint { public: JupiterUpstreamEndpoint(const CloudCacheClientOptions& Options) : m_UseLegacyDdc(Options.UseLegacyDdc) @@ -108,7 +108,7 @@ namespace detail { virtual bool Initialize() override { - zen::CloudCacheSession Session(m_Client); + CloudCacheSession Session(m_Client); const CloudCacheResult Result = Session.Authenticate(); return Result.Success; } @@ -119,7 +119,7 @@ namespace detail { { try { - zen::CloudCacheSession Session(m_Client); + CloudCacheSession Session(m_Client); CloudCacheResult Result; if (m_UseLegacyDdc && Type == ZenContentType::kBinary) @@ -135,7 +135,7 @@ namespace detail { { CbPackage Package; - const CbValidateError ValidationResult = zen::ValidateCompactBinary(Result.Response, CbValidateMode::All); + const CbValidateError ValidationResult = ValidateCompactBinary(Result.Response, CbValidateMode::All); if (Result.Success = ValidationResult == CbValidateError::None; Result.Success) { CbObject CacheRecord = LoadCompactBinaryObject(Result.Response); @@ -184,7 +184,7 @@ namespace detail { { try { - zen::CloudCacheSession Session(m_Client); + CloudCacheSession Session(m_Client); const CloudCacheResult Result = Session.GetCompressedBlob(PayloadKey.PayloadId); return {.Value = Result.Response, @@ -279,7 +279,7 @@ namespace detail { RefPtr<CloudCacheClient> m_Client; }; - class ZenUpstreamEndpoint final : public zen::UpstreamEndpoint + class ZenUpstreamEndpoint final : public UpstreamEndpoint { public: ZenUpstreamEndpoint(std::string_view ServiceUrl) @@ -357,14 +357,14 @@ namespace detail { try { - zen::ZenStructuredCacheSession Session(*m_Client); + ZenStructuredCacheSession Session(*m_Client); ZenCacheResult Result; int64_t TotalBytes = 0ull; double TotalElapsedSeconds = 0.0; if (CacheRecord.Type == ZenContentType::kCbPackage) { - zen::CbPackage Package; + CbPackage Package; Package.SetObject(CbObject(SharedBuffer(RecordValue))); for (const IoBuffer& Payload : Payloads) @@ -441,7 +441,7 @@ namespace detail { private: std::string m_DisplayName; - RefPtr<zen::ZenStructuredCacheClient> m_Client; + RefPtr<ZenStructuredCacheClient> m_Client; }; } // namespace detail @@ -468,7 +468,7 @@ class UpstreamStats final }; public: - UpstreamStats() : m_Log(zen::logging::Get("upstream")) {} + UpstreamStats() : m_Log(logging::Get("upstream")) {} void Add(const UpstreamEndpoint& Endpoint, const GetUpstreamCacheResult& Result) { @@ -536,8 +536,8 @@ private: class DefaultUpstreamCache final : public UpstreamCache { public: - DefaultUpstreamCache(const UpstreamCacheOptions& Options, ::ZenCacheStore& CacheStore, CidStore& CidStore) - : m_Log(zen::logging::Get("upstream")) + DefaultUpstreamCache(const UpstreamCacheOptions& Options, ZenCacheStore& CacheStore, CidStore& CidStore) + : m_Log(logging::Get("upstream")) , m_Options(Options) , m_CacheStore(CacheStore) , m_CidStore(CidStore) @@ -718,11 +718,11 @@ private: spdlog::logger& m_Log; UpstreamCacheOptions m_Options; - ::ZenCacheStore& m_CacheStore; + ZenCacheStore& m_CacheStore; CidStore& m_CidStore; UpstreamQueue m_UpstreamQueue; UpstreamStats m_Stats; - std::vector<std::unique_ptr<zen::UpstreamEndpoint>> m_Endpoints; + std::vector<std::unique_ptr<UpstreamEndpoint>> m_Endpoints; std::vector<std::thread> m_UpstreamThreads; std::atomic_bool m_IsRunning{false}; }; @@ -730,7 +730,7 @@ private: ////////////////////////////////////////////////////////////////////////// std::unique_ptr<UpstreamCache> -MakeUpstreamCache(const UpstreamCacheOptions& Options, ::ZenCacheStore& CacheStore, CidStore& CidStore) +MakeUpstreamCache(const UpstreamCacheOptions& Options, ZenCacheStore& CacheStore, CidStore& CidStore) { return std::make_unique<DefaultUpstreamCache>(Options, CacheStore, CidStore); } diff --git a/zenserver/upstream/upstreamcache.h b/zenserver/upstream/upstreamcache.h index 3b054d815..142fe260f 100644 --- a/zenserver/upstream/upstreamcache.h +++ b/zenserver/upstream/upstreamcache.h @@ -8,11 +8,10 @@ #include <memory> -class ZenCacheStore; - namespace zen { class CidStore; +class ZenCacheStore; struct CloudCacheClientOptions; struct UpstreamCacheKey @@ -103,7 +102,7 @@ public: virtual EnqueueResult EnqueueUpstream(UpstreamCacheRecord CacheRecord) = 0; }; -std::unique_ptr<UpstreamCache> MakeUpstreamCache(const UpstreamCacheOptions& Options, ::ZenCacheStore& CacheStore, CidStore& CidStore); +std::unique_ptr<UpstreamCache> MakeUpstreamCache(const UpstreamCacheOptions& Options, ZenCacheStore& CacheStore, CidStore& CidStore); std::unique_ptr<UpstreamEndpoint> MakeJupiterUpstreamEndpoint(const CloudCacheClientOptions& Options); diff --git a/zenserver/upstream/zen.cpp b/zenserver/upstream/zen.cpp index be4daa30a..7f689d7f3 100644 --- a/zenserver/upstream/zen.cpp +++ b/zenserver/upstream/zen.cpp @@ -73,7 +73,7 @@ namespace detail { // Note that currently this just implements an UDP echo service for testing purposes -Mesh::Mesh(asio::io_context& IoContext) : m_Log(logging::Get("mesh")), m_IoContext(IoContext), m_SessionId(zen::GetSessionId()) +Mesh::Mesh(asio::io_context& IoContext) : m_Log(logging::Get("mesh")), m_IoContext(IoContext), m_SessionId(GetSessionId()) { } @@ -370,7 +370,7 @@ ZenStructuredCacheClient::FreeSessionState(detail::ZenCacheSessionState* State) using namespace std::literals; ZenStructuredCacheSession::ZenStructuredCacheSession(ZenStructuredCacheClient& OuterClient) -: m_Log(zen::logging::Get("zenclient"sv)) +: m_Log(logging::Get("zenclient"sv)) , m_Client(OuterClient) { m_SessionState = m_Client.AllocSessionState(); diff --git a/zenserver/vfs.cpp b/zenserver/vfs.cpp index b98801116..fcc9a71f8 100644 --- a/zenserver/vfs.cpp +++ b/zenserver/vfs.cpp @@ -5,7 +5,6 @@ #if ZEN_WITH_VFS # include <zencore/except.h> # include <zencore/filesystem.h> -# include <zencore/snapshot_manifest.h> # include <zencore/stream.h> # include <zencore/windows.h> # include <zencore/logging.h> diff --git a/zenserver/zenserver.cpp b/zenserver/zenserver.cpp index 529972cc0..62e8609f4 100644 --- a/zenserver/zenserver.cpp +++ b/zenserver/zenserver.cpp @@ -420,10 +420,10 @@ private: zen::Ref<zen::HttpServer> m_Http; std::unique_ptr<zen::CasStore> m_CasStore{zen::CreateCasStore()}; std::unique_ptr<zen::CidStore> m_CidStore; - std::unique_ptr<ZenCacheStore> m_CacheStore; + std::unique_ptr<zen::ZenCacheStore> m_CacheStore; zen::CasGc m_Gc{*m_CasStore}; zen::CasScrubber m_Scrubber{*m_CasStore}; - HttpTestService m_TestService; + zen::HttpTestService m_TestService; zen::HttpTestingService m_TestingService; zen::HttpCasService m_CasService{*m_CasStore}; zen::RefPtr<zen::ProjectStore> m_ProjectStore; @@ -431,8 +431,8 @@ private: std::unique_ptr<zen::HttpLaunchService> m_HttpLaunchService; std::unique_ptr<zen::HttpProjectService> m_HttpProjectService; std::unique_ptr<zen::HttpStructuredCacheService> m_StructuredCacheService; - HttpAdminService m_AdminService; - HttpHealthService m_HealthService; + zen::HttpAdminService m_AdminService; + zen::HttpHealthService m_HealthService; zen::Mesh m_ZenMesh{m_IoContext}; std::unique_ptr<zen::HttpFunctionService> m_HttpFunctionService; diff --git a/zenstore/CAS.cpp b/zenstore/CAS.cpp index 320ca9e5a..916e7f709 100644 --- a/zenstore/CAS.cpp +++ b/zenstore/CAS.cpp @@ -200,10 +200,10 @@ TEST_CASE("CasStore") { ScopedTemporaryDirectory TempDir; - zen::CasStoreConfiguration config; + CasStoreConfiguration config; config.RootDirectory = TempDir.Path(); - std::unique_ptr<zen::CasStore> Store{CreateCasStore()}; + std::unique_ptr<CasStore> Store{CreateCasStore()}; Store->Initialize(config); ScrubContext Ctx; diff --git a/zenstore/caslog.cpp b/zenstore/caslog.cpp index 70bcf4669..dc6021544 100644 --- a/zenstore/caslog.cpp +++ b/zenstore/caslog.cpp @@ -62,7 +62,7 @@ CasLogFile::Open(std::filesystem::path FileName, size_t RecordSize, bool IsCreat if (IsCreate) { // Initialize log by writing header - FileHeader Header = {.RecordSize = gsl::narrow<uint32_t>(RecordSize), .LogId = zen::Oid::NewOid(), .ValidatedTail = 0}; + FileHeader Header = {.RecordSize = gsl::narrow<uint32_t>(RecordSize), .LogId = Oid::NewOid(), .ValidatedTail = 0}; memcpy(Header.Magic, FileHeader::MagicSequence, sizeof Header.Magic); Header.Finalize(); @@ -128,7 +128,7 @@ CasLogFile::Replay(std::function<void(const void*)>&& Handler) if (FAILED(hRes)) { - zen::ThrowSystemException(hRes, "Failed to read log file"); + ThrowSystemException(hRes, "Failed to read log file"); } for (int i = 0; i < LogEntryCount; ++i) @@ -144,7 +144,7 @@ CasLogFile::Append(const void* DataPointer, uint64_t DataSize) if (FAILED(hRes)) { - zen::ThrowSystemException(hRes, "Failed to write to log file '{}'"_format(zen::PathFromHandle(m_File))); + ThrowSystemException(hRes, "Failed to write to log file '{}'"_format(PathFromHandle(m_File))); } } diff --git a/zenstore/cidstore.cpp b/zenstore/cidstore.cpp index 100054a0e..e1b7ac656 100644 --- a/zenstore/cidstore.cpp +++ b/zenstore/cidstore.cpp @@ -78,7 +78,7 @@ struct CidStore::CidState void InitializeIndex(const std::filesystem::path& RootDir) { - zen::CreateDirectories(RootDir); + CreateDirectories(RootDir); std::filesystem::path SlogPath{RootDir / "cid.slog"}; bool IsNew = !std::filesystem::exists(SlogPath); diff --git a/zenstore/compactcas.cpp b/zenstore/compactcas.cpp index 070ca1503..fe38f0fde 100644 --- a/zenstore/compactcas.cpp +++ b/zenstore/compactcas.cpp @@ -50,7 +50,7 @@ CasContainerStrategy::Initialize(const std::string_view ContainerBaseName, uint6 // This is not technically necessary (nobody should be accessing us from // another thread at this stage) but may help static analysis - zen::RwLock::ExclusiveLockScope _(m_LocationMapLock); + RwLock::ExclusiveLockScope _(m_LocationMapLock); m_CasLog.Replay([&](const CasDiskIndexEntry& Record) { m_LocationMap[Record.Key] = Record.Location; @@ -113,7 +113,7 @@ CasContainerStrategy::FindChunk(const IoHash& ChunkHash) if (auto KeyIt = m_LocationMap.find(ChunkHash); KeyIt != m_LocationMap.end()) { const CasDiskLocation& Location = KeyIt->second; - return zen::IoBufferBuilder::MakeFromFileHandle(m_SmallObjectFile.Handle(), Location.Offset, Location.Size); + return IoBufferBuilder::MakeFromFileHandle(m_SmallObjectFile.Handle(), Location.Offset, Location.Size); } // Not found @@ -192,7 +192,7 @@ CasContainerStrategy::Scrub(ScrubContext& Ctx) do { - const uint64_t ChunkSize = zen::Min(WindowSize, FileSize - WindowStart); + const uint64_t ChunkSize = Min(WindowSize, FileSize - WindowStart); m_SmallObjectFile.Read(BufferBase, ChunkSize, WindowStart); for (auto& Entry : m_LocationMap) diff --git a/zenstore/filecas.cpp b/zenstore/filecas.cpp index 31991a43e..983ce166e 100644 --- a/zenstore/filecas.cpp +++ b/zenstore/filecas.cpp @@ -159,7 +159,7 @@ FileCasStrategy::InsertChunk(IoBuffer Chunk, const IoHash& ChunkHash) if (FAILED(hRes)) { - zen::CreateDirectories(FilePath.c_str()); + CreateDirectories(FilePath.c_str()); hRes = InternalCreateDirectoryHandle(); } diff --git a/zenstore/include/zenstore/caslog.h b/zenstore/include/zenstore/caslog.h index 3d558bee0..1fbda0265 100644 --- a/zenstore/include/zenstore/caslog.h +++ b/zenstore/include/zenstore/caslog.h @@ -33,7 +33,7 @@ private: { uint8_t Magic[16]; uint32_t RecordSize = 0; - zen::Oid LogId; + Oid LogId; uint32_t ValidatedTail = 0; uint32_t Pad[6]; uint32_t Checksum = 0; diff --git a/zenutil/include/zenutil/zenserverprocess.h b/zenutil/include/zenutil/zenserverprocess.h index 979db349a..09728aa1a 100644 --- a/zenutil/include/zenutil/zenserverprocess.h +++ b/zenutil/include/zenutil/zenserverprocess.h @@ -66,9 +66,9 @@ struct ZenServerInstance private: ZenServerEnvironment& m_Env; - zen::ProcessHandle m_Process; - zen::Event m_ReadyEvent; - zen::Event m_ShutdownEvent; + ProcessHandle m_Process; + Event m_ReadyEvent; + Event m_ShutdownEvent; bool m_Terminate = false; std::filesystem::path m_TestDir; bool m_MeshEnabled = false; @@ -109,10 +109,10 @@ public: FRIEND_ENUM_CLASS_FLAGS(FlagsEnum); - zen::Oid GetSessionId() const { return zen::Oid::FromMemory(SessionId); } - void Reset(); - void SignalShutdownRequest(); - bool AddSponsorProcess(uint32_t Pid); + Oid GetSessionId() const { return Oid::FromMemory(SessionId); } + void Reset(); + void SignalShutdownRequest(); + bool AddSponsorProcess(uint32_t Pid); }; static_assert(sizeof(ZenServerEntry) == 256); diff --git a/zenutil/zenserverprocess.cpp b/zenutil/zenserverprocess.cpp index 9e370ae10..55b592ab1 100644 --- a/zenutil/zenserverprocess.cpp +++ b/zenutil/zenserverprocess.cpp @@ -46,7 +46,7 @@ namespace zenutil { { if (!SetSecurityDescriptorDacl(&m_Sd, TRUE, (PACL)NULL, FALSE)) { - zen::ThrowLastError("SetSecurityDescriptorDacl failed", std::source_location::current()); + ThrowLastError("SetSecurityDescriptorDacl failed", std::source_location::current()); } m_Attributes.lpSecurityDescriptor = &m_Sd; @@ -108,7 +108,7 @@ ZenServerState::Initialize() if (hMap == NULL) { - zen::ThrowLastError("Could not open or create file mapping object for Zen server state"); + ThrowLastError("Could not open or create file mapping object for Zen server state"); } m_hMapFile = hMap; @@ -122,7 +122,7 @@ ZenServerState::Initialize() if (pBuf == NULL) { - zen::ThrowLastError("Could not map view of Zen server state"); + ThrowLastError("Could not map view of Zen server state"); } m_Data = reinterpret_cast<ZenServerEntry*>(pBuf); @@ -149,7 +149,7 @@ ZenServerState::InitializeReadOnly() if (pBuf == NULL) { - zen::ThrowLastError("Could not map view of Zen server state"); + ThrowLastError("Could not map view of Zen server state"); } m_Data = reinterpret_cast<ZenServerEntry*>(pBuf); @@ -181,7 +181,7 @@ ZenServerState::Register(int ListenPort) // Allocate an entry - int Pid = zen::GetCurrentProcessId(); + int Pid = GetCurrentProcessId(); for (int i = 0; i < m_MaxEntryCount; ++i) { @@ -199,7 +199,7 @@ ZenServerState::Register(int ListenPort) Entry.Pid = Pid; Entry.Flags = 0; - const zen::Oid SesId = zen::GetSessionId(); + const Oid SesId = GetSessionId(); memcpy(Entry.SessionId, &SesId, sizeof SesId); return &Entry; @@ -226,7 +226,7 @@ ZenServerState::Sweep() if (Entry.ListenPort) { - if (zen::IsProcessRunning(Entry.Pid) == false) + if (IsProcessRunning(Entry.Pid) == false) { ZEN_DEBUG("Sweep - pid {} not running, reclaiming entry (port {})", Entry.Pid, Entry.ListenPort); @@ -323,7 +323,7 @@ ZenServerEnvironment::InitializeForTest(std::filesystem::path ProgramBaseDir, st ZEN_INFO("Program base dir is '{}'", ProgramBaseDir); ZEN_INFO("Cleaning test base dir '{}'", TestBaseDir); - zen::DeleteDirectories(TestBaseDir.c_str()); + DeleteDirectories(TestBaseDir.c_str()); m_IsTestInstance = true; m_IsInitialized = true; @@ -334,14 +334,14 @@ ZenServerEnvironment::CreateNewTestDir() { using namespace std::literals; - zen::ExtendableWideStringBuilder<256> TestDir; + ExtendableWideStringBuilder<256> TestDir; TestDir << "test"sv << int64_t(++TestCounter); std::filesystem::path TestPath = m_TestBaseDir / TestDir.c_str(); ZEN_INFO("Creating new test dir @ '{}'", TestPath); - zen::CreateDirectories(TestPath.c_str()); + CreateDirectories(TestPath.c_str()); return TestPath; } @@ -406,16 +406,16 @@ ZenServerInstance::SpawnServer(int BasePort, std::string_view AdditionalServerAr const int MyPid = _getpid(); const int ChildId = ++ChildIdCounter; - zen::ExtendableStringBuilder<32> ChildEventName; + ExtendableStringBuilder<32> ChildEventName; ChildEventName << "Zen_Child_" << ChildId; - zen::NamedEvent ChildEvent{ChildEventName}; + NamedEvent ChildEvent{ChildEventName}; CreateShutdownEvent(BasePort); - zen::ExtendableStringBuilder<32> LogId; + ExtendableStringBuilder<32> LogId; LogId << "Zen" << ChildId; - zen::ExtendableWideStringBuilder<512> CommandLine; + ExtendableWideStringBuilder<512> CommandLine; CommandLine << "\""; CommandLine.Append(Executable.c_str()); CommandLine << "\""; @@ -554,10 +554,10 @@ ZenServerInstance::SpawnServer(int BasePort, std::string_view AdditionalServerAr void ZenServerInstance::CreateShutdownEvent(int BasePort) { - zen::ExtendableStringBuilder<32> ChildShutdownEventName; + ExtendableStringBuilder<32> ChildShutdownEventName; ChildShutdownEventName << "Zen_" << BasePort; ChildShutdownEventName << "_Shutdown"; - zen::NamedEvent ChildShutdownEvent{ChildShutdownEventName}; + NamedEvent ChildShutdownEvent{ChildShutdownEventName}; m_ShutdownEvent = std::move(ChildShutdownEvent); } |