aboutsummaryrefslogtreecommitdiff
path: root/src/zenstore/cache/cachedisklayer.cpp
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2025-10-24 23:10:06 +0200
committerGitHub Enterprise <[email protected]>2025-10-24 23:10:06 +0200
commit6d96e791f9bb8cd25cbdb1c3fecfcaad9fff6a20 (patch)
tree150ec308a9ec64966a8f0effb4fa1361099b617a /src/zenstore/cache/cachedisklayer.cpp
parentoptimize blockstore filesize (#612) (diff)
downloadzen-6d96e791f9bb8cd25cbdb1c3fecfcaad9fff6a20.tar.xz
zen-6d96e791f9bb8cd25cbdb1c3fecfcaad9fff6a20.zip
optimize filecas write file (#613)
* try to move file into place before trying speculative remove of target file
Diffstat (limited to 'src/zenstore/cache/cachedisklayer.cpp')
-rw-r--r--src/zenstore/cache/cachedisklayer.cpp26
1 files changed, 10 insertions, 16 deletions
diff --git a/src/zenstore/cache/cachedisklayer.cpp b/src/zenstore/cache/cachedisklayer.cpp
index c2e811003..67f587a7c 100644
--- a/src/zenstore/cache/cachedisklayer.cpp
+++ b/src/zenstore/cache/cachedisklayer.cpp
@@ -2724,14 +2724,19 @@ ZenCacheDiskLayer::CacheBucket::PutStandaloneCacheValue(const IoHash& HashKey, c
RwLock::ExclusiveLockScope ValueLock(LockForHash(HashKey));
- // We do a speculative remove of the file instead of probing with a exists call and check the error code instead
- RemoveFile(FsPath, Ec);
+ // Assume parent directory exists
+ DataFile.MoveTemporaryIntoPlace(FsPath, Ec);
if (Ec)
{
- if (Ec.value() != ENOENT)
+ CreateDirectories(FsPath.parent_path());
+
+ // Try again after we or someone else created the directory
+ Ec.clear();
+ DataFile.MoveTemporaryIntoPlace(FsPath, Ec);
+
+ if (Ec)
{
- ZEN_WARN("Failed to remove file '{}' for put in '{}', reason: '{}', retrying.", FsPath, m_BucketDir, Ec.message());
- Sleep(100);
+ // We do a speculative remove of the file instead of probing with a exists call and check the error code instead
Ec.clear();
RemoveFile(FsPath, Ec);
if (Ec && Ec.value() != ENOENT)
@@ -2739,17 +2744,6 @@ ZenCacheDiskLayer::CacheBucket::PutStandaloneCacheValue(const IoHash& HashKey, c
throw std::system_error(Ec, fmt::format("Failed to remove file '{}' for put in '{}'", FsPath, m_BucketDir));
}
}
- }
-
- // Assume parent directory exists
- DataFile.MoveTemporaryIntoPlace(FsPath, Ec);
- if (Ec)
- {
- CreateDirectories(FsPath.parent_path());
-
- // Try again after we or someone else created the directory
- Ec.clear();
- DataFile.MoveTemporaryIntoPlace(FsPath, Ec);
// Retry if we still fail to handle contention to file system
uint32_t RetriesLeft = 3;