From 2ade130ec3c163cadc4a296e7d7800eb86e72056 Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Tue, 21 Apr 2026 10:07:03 +0200 Subject: structured cache: fix some minor issues (#995) - Fix double WriteResponse in PUT record failure path; the detail-body branch now short-circuits instead of falling through to a second WriteResponse call - Return 405 Method Not Allowed for unsupported verbs in the root, namespace, bucket, record, and chunk handlers (previously fell through to no response) - Clamp exec$/replay-recording thread_count so a bogus query value cannot spawn an unbounded worker pool ## Performance / cleanup - NamespaceMap now uses TransparentStringHash + std::equal_to<>, so Get/Put/Find/Drop can probe the map with a std::string_view directly instead of constructing a temporary std::string on every request - Replace insert_or_assign with try_emplace under the exclusive lock in GetNamespace; the find() re-check already guarantees the key is absent, so try_emplace matches intent better ## Reverted - The earlier change to erase the pinned entry from m_DroppedNamespaces after DropNamespace's post-drop work was reverted: other threads may still hold pointers into a dropped namespace, so tearing it down eagerly is unsafe. Dropped namespaces remain pinned for the lifetime of the process as before. --- .../storage/cache/httpstructuredcache.cpp | 27 +++++++++++++--------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'src/zenserver/storage/cache/httpstructuredcache.cpp') diff --git a/src/zenserver/storage/cache/httpstructuredcache.cpp b/src/zenserver/storage/cache/httpstructuredcache.cpp index 8ad48225b..4d3673e70 100644 --- a/src/zenserver/storage/cache/httpstructuredcache.cpp +++ b/src/zenserver/storage/cache/httpstructuredcache.cpp @@ -437,19 +437,22 @@ HttpStructuredCacheService::HandleRequest(HttpServerRequest& Request) std::string RecordPath = UrlDecode(Params.GetValue("path")); - uint32_t ThreadCount = GetHardwareConcurrency(); + const uint32_t HardwareConcurrency = GetHardwareConcurrency(); + const uint32_t MaxThreadCount = std::max(HardwareConcurrency, 16u); + uint32_t ThreadCount = HardwareConcurrency; if (auto Param = Params.GetValue("thread_count"); Param.empty() == false) { if (auto Value = ParseInt(Param)) { - ThreadCount = gsl::narrow(Value.value()); + ThreadCount = gsl::narrow_cast(std::min(Value.value(), MaxThreadCount)); } } + ThreadCount = std::clamp(ThreadCount, 1u, MaxThreadCount); ZEN_INFO("initiating cache RPC replay using {} threads, from '{}'", ThreadCount, RecordPath); std::unique_ptr Replayer(cache::MakeDiskRequestReplayer(RecordPath, false)); - ReplayRequestRecorder(RequestContext, *Replayer, ThreadCount < 1 ? 1 : ThreadCount); + ReplayRequestRecorder(RequestContext, *Replayer, ThreadCount); ZEN_INFO("cache RPC replay COMPLETED"); @@ -557,7 +560,7 @@ HttpStructuredCacheService::HandleCacheRequest(HttpServerRequest& Request) break; default: m_CacheStats.BadRequestCount++; - break; + return Request.WriteResponse(HttpResponseCode::MethodNotAllowed); } } @@ -707,7 +710,8 @@ HttpStructuredCacheService::HandleCacheNamespaceRequest(HttpServerRequest& Reque break; default: - break; + m_CacheStats.BadRequestCount++; + return Request.WriteResponse(HttpResponseCode::MethodNotAllowed); } } @@ -797,7 +801,8 @@ HttpStructuredCacheService::HandleCacheBucketRequest(HttpServerRequest& Request, break; default: - break; + m_CacheStats.BadRequestCount++; + return Request.WriteResponse(HttpResponseCode::MethodNotAllowed); } } @@ -816,7 +821,8 @@ HttpStructuredCacheService::HandleCacheRecordRequest(HttpServerRequest& Request, break; default: - break; + m_CacheStats.BadRequestCount++; + return Request.WriteResponse(HttpResponseCode::MethodNotAllowed); } } @@ -1216,8 +1222,6 @@ HttpStructuredCacheService::HandlePutCacheRecord(HttpServerRequest& Request, con } auto WriteFailureResponse = [&Request](const ZenCacheStore::PutResult& PutResult) { - ZEN_UNUSED(PutResult); - HttpResponseCode ResponseCode = HttpResponseCode::InternalServerError; switch (PutResult.Status) { @@ -1231,7 +1235,7 @@ HttpStructuredCacheService::HandlePutCacheRecord(HttpServerRequest& Request, con if (PutResult.Details) { - Request.WriteResponse(ResponseCode, PutResult.Details); + return Request.WriteResponse(ResponseCode, PutResult.Details); } return Request.WriteResponse(ResponseCode); }; @@ -1507,7 +1511,8 @@ HttpStructuredCacheService::HandleCacheChunkRequest(HttpServerRequest& Request, HandlePutCacheChunk(Request, Ref, PolicyFromUrl); break; default: - break; + m_CacheStats.BadRequestCount++; + return Request.WriteResponse(HttpResponseCode::MethodNotAllowed); } } -- cgit v1.2.3