diff options
| author | Stefan Boberg <[email protected]> | 2021-05-21 22:27:13 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-05-21 22:27:13 +0200 |
| commit | 6b9e432a9152118bcb6c203abbcbe46f9da5c1e2 (patch) | |
| tree | 9093c5c10353eea7018bc3f3a1e31957c015f913 /zenserver/cache/cachestore.cpp | |
| parent | Fixed up error reporting in BasicFile, now uses ThrowSystemException() to cor... (diff) | |
| download | zen-6b9e432a9152118bcb6c203abbcbe46f9da5c1e2.tar.xz zen-6b9e432a9152118bcb6c203abbcbe46f9da5c1e2.zip | |
Fixed up PutLargeObject() error handling
Diffstat (limited to 'zenserver/cache/cachestore.cpp')
| -rw-r--r-- | zenserver/cache/cachestore.cpp | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/zenserver/cache/cachestore.cpp b/zenserver/cache/cachestore.cpp index e0dd57902..1db58c1e6 100644 --- a/zenserver/cache/cachestore.cpp +++ b/zenserver/cache/cachestore.cpp @@ -2,6 +2,7 @@ #include "cachestore.h" +#include <zencore/except.h> #include <zencore/windows.h> #include <fmt/core.h> @@ -1019,9 +1020,7 @@ ZenCacheDiskLayer::CacheBucket::Get(const zen::IoHash& HashKey, ZenCacheValue& O { zen::RwLock::SharedLockScope _(m_IndexLock); - auto it = m_Index.find(HashKey); - - if (it != m_Index.end()) + if (auto it = m_Index.find(HashKey); it != m_Index.end()) { OutValue.Value = IoBufferBuilder::MakeFromFileHandle(m_SobsFile.Handle(), it->second.Offset, it->second.Size); @@ -1050,10 +1049,14 @@ void ZenCacheDiskLayer::CacheBucket::Put(const zen::IoHash& HashKey, const ZenCacheValue& Value) { if (!m_Ok) + { return; + } if (Value.Value.Size() >= m_LargeObjectThreshold) - PutLargeObject(HashKey, Value); + { + return PutLargeObject(HashKey, Value); + } // Small object put @@ -1096,24 +1099,33 @@ ZenCacheDiskLayer::CacheBucket::Flush() void ZenCacheDiskLayer::CacheBucket::PutLargeObject(const zen::IoHash& HashKey, const ZenCacheValue& Value) { - zen::WideStringBuilder<128> dataFilePath; + zen::WideStringBuilder<128> DataFilePath; + BuildPath(DataFilePath, HashKey); - BuildPath(dataFilePath, HashKey); - - CAtlTemporaryFile dataFile; + // TODO: replace this with a more efficient implementation with proper atomic rename - HRESULT hRes = dataFile.Create(m_BucketDir.c_str()); + CAtlTemporaryFile DataFile; - hRes = dataFile.Write(Value.Value.Data(), gsl::narrow<DWORD>(Value.Value.Size())); + HRESULT hRes = DataFile.Create(m_BucketDir.c_str()); if (FAILED(hRes)) { - // TODO: report error! and delete temp file + zen::ThrowSystemException(hRes, "Failed to open temporary file for put at '{}'"_format(m_BucketDir)); + } - return; + 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()))); } - hRes = dataFile.Close(dataFilePath.c_str()); + hRes = DataFile.Close(DataFilePath.c_str()); + + if (FAILED(hRes)) + { + zen::ThrowSystemException(hRes, "Failed to finalize file '{}'"_format(zen::WideToUtf8(DataFilePath))); + } } ////////////////////////////////////////////////////////////////////////// @@ -1238,7 +1250,7 @@ ZenCacheTracker::TrackAccess(std::string_view Bucket, const zen::IoHash& HashKey ZEN_UNUSED(HashKey); } -void +void ZenCacheTracker::Flush() { } |