diff options
| author | Dan Engelbrecht <[email protected]> | 2023-06-05 13:48:12 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-06-05 13:48:12 +0200 |
| commit | f9652d41e8faa782aa10432470e853b73397b639 (patch) | |
| tree | 2d731edbc3ea9880092e75a892a30780a8c1d014 /src/zenserver/cache/cachedisklayer.cpp | |
| parent | Increased timeout to 25 min for Windows validation (diff) | |
| download | zen-f9652d41e8faa782aa10432470e853b73397b639.tar.xz zen-f9652d41e8faa782aa10432470e853b73397b639.zip | |
Increase retry logic (#325)
* Increase timeout and number of retries in CacheBucket::PutStandaloneCacheValue when moving temporary file into place
* changelog
Diffstat (limited to 'src/zenserver/cache/cachedisklayer.cpp')
| -rw-r--r-- | src/zenserver/cache/cachedisklayer.cpp | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/src/zenserver/cache/cachedisklayer.cpp b/src/zenserver/cache/cachedisklayer.cpp index 54ac2807b..9d3935131 100644 --- a/src/zenserver/cache/cachedisklayer.cpp +++ b/src/zenserver/cache/cachedisklayer.cpp @@ -1701,30 +1701,36 @@ ZenCacheDiskLayer::CacheBucket::PutStandaloneCacheValue(const IoHash& HashKey, c } } + // Assume parent directory exists DataFile.MoveTemporaryIntoPlace(FsPath, Ec); if (Ec) { CreateDirectories(FsPath.parent_path()); - Ec.clear(); - // Try again + // Try again after we or someone else created the directory + Ec.clear(); DataFile.MoveTemporaryIntoPlace(FsPath, Ec); - if (Ec) + + // Retry if we still fail to handle contention to file system + uint32_t RetriesLeft = 3; + while (Ec && RetriesLeft > 0) { - ZEN_WARN("Failed to finalize file '{}', moving from '{}' for put in '{}', reason: '{}', retrying.", + ZEN_WARN("Failed to finalize file '{}', moving from '{}' for put in '{}', reason: '{}', retries left: {}.", FsPath, DataFile.GetPath(), m_BucketDir, - Ec.message()); - Sleep(100); + Ec.message(), + RetriesLeft); + Sleep(100 - (3 - RetriesLeft) * 100); // Total 600 ms Ec.clear(); DataFile.MoveTemporaryIntoPlace(FsPath, Ec); - if (Ec) - { - throw std::system_error( - Ec, - fmt::format("Failed to finalize file '{}', moving from '{}' for put in '{}'", FsPath, DataFile.GetPath(), m_BucketDir)); - } + RetriesLeft--; + } + if (Ec) + { + throw std::system_error( + Ec, + fmt::format("Failed to finalize file '{}', moving from '{}' for put in '{}'", FsPath, DataFile.GetPath(), m_BucketDir)); } } @@ -2124,4 +2130,4 @@ ZenCacheDiskLayer::GetValueDetails(const std::string_view BucketFilter, const st return Details; } -} // namespace zen
\ No newline at end of file +} // namespace zen |