From 7a94b22eafdbd3f394fb9200e713cbb3b2b0cd56 Mon Sep 17 00:00:00 2001 From: zousar Date: Fri, 19 Sep 2025 23:46:52 -0600 Subject: Change batch put responses for client reporting Conflicts are now treated as successes, and we optionally return a Details array instead of an ErrorMessages array. Details are returned for all requests in a batch, or no requests in a batch depending on whether there are any details to be shared about any of the put requests. The details for a conflict include the raw hash and raw size of the item. If the item is a record, we also include the record as an object. --- src/zenstore/cache/cachedisklayer.cpp | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'src/zenstore/cache/cachedisklayer.cpp') diff --git a/src/zenstore/cache/cachedisklayer.cpp b/src/zenstore/cache/cachedisklayer.cpp index fd52cdab5..9a56844fe 100644 --- a/src/zenstore/cache/cachedisklayer.cpp +++ b/src/zenstore/cache/cachedisklayer.cpp @@ -1968,17 +1968,19 @@ ZenCacheDiskLayer::CacheBucket::ShouldRejectPut(const IoHash& HashKey, IndexLock.ReleaseNow(); if (!cache::impl::UpdateValueWithRawSizeAndHash(InOutValue)) { - OutPutResult = PutResult{zen::PutStatus::Fail, "Value provided is of bad format"}; + CbObjectWriter DetailWriter; + DetailWriter.AddString("Value provided is of bad format"); + OutPutResult = PutResult{zen::PutStatus::Fail, DetailWriter.Save()}; return true; } else if (MetaData.RawSize != InOutValue.RawSize || MetaData.RawHash != InOutValue.RawHash) { - OutPutResult = PutResult{ - zen::PutStatus::Conflict, - fmt::format("Value exists with different size '{}' or hash '{}'", MetaData.RawSize, MetaData.RawHash)}; - return true; + // Deliberate fall through without return so that we load the value and include it in the result + } + else + { + return false; } - return false; } } @@ -2008,16 +2010,27 @@ ZenCacheDiskLayer::CacheBucket::ShouldRejectPut(const IoHash& HashKey, { if (!cache::impl::UpdateValueWithRawSizeAndHash(InOutValue)) { - OutPutResult = PutResult{zen::PutStatus::Fail, "Value provided is of bad format"}; + CbObjectWriter DetailWriter; + DetailWriter.AddString("Value provided is of bad format"); + OutPutResult = PutResult{zen::PutStatus::Fail, DetailWriter.Save()}; return true; } if (ExistingValue.RawSize != InOutValue.RawSize || ExistingValue.RawHash != InOutValue.RawHash) { - OutPutResult = PutResult{zen::PutStatus::Conflict, - fmt::format("Value exists with different size '{}' or hash '{}'", - ExistingValue.RawSize, - ExistingValue.RawHash)}; + CbObjectWriter DetailWriter; + if (Location.IsFlagSet(DiskLocation::kStructured)) + { + DetailWriter.AddInteger("RawSize", ExistingValue.RawSize); + DetailWriter.AddHash("RawHash", ExistingValue.RawHash); + DetailWriter.AddObject("Object", CbObjectView(ExistingValue.Value.GetData())); + } + else + { + DetailWriter.AddInteger("RawSize", ExistingValue.RawSize); + DetailWriter.AddHash("RawHash", ExistingValue.RawHash); + } + OutPutResult = PutResult{zen::PutStatus::Conflict, DetailWriter.Save()}; return true; } } -- cgit v1.2.3