diff options
| author | Dan Engelbrecht <[email protected]> | 2024-10-16 09:49:55 +0200 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2024-10-16 09:49:55 +0200 |
| commit | b254f75968e1a5692fa872fcfda5eaa1a0ed561d (patch) | |
| tree | 968e5fc30e37295a4c5767d5c290016116e196ab /src/zenstore/filecas.cpp | |
| parent | upload linux mac exe to sentry (#196) (diff) | |
| download | zen-b254f75968e1a5692fa872fcfda5eaa1a0ed561d.tar.xz zen-b254f75968e1a5692fa872fcfda5eaa1a0ed561d.zip | |
safer path from handle (#195)
* remove PathFromHandle that throws to give better context on failures
Diffstat (limited to 'src/zenstore/filecas.cpp')
| -rw-r--r-- | src/zenstore/filecas.cpp | 72 |
1 files changed, 41 insertions, 31 deletions
diff --git a/src/zenstore/filecas.cpp b/src/zenstore/filecas.cpp index 57b42beb2..6d5bcff96 100644 --- a/src/zenstore/filecas.cpp +++ b/src/zenstore/filecas.cpp @@ -459,41 +459,30 @@ FileCasStrategy::InsertChunk(IoBuffer Chunk, const IoHash& ChunkHash, CasStore:: ChunkHash); #elif ZEN_PLATFORM_LINUX || ZEN_PLATFORM_MAC - - std::filesystem::path SourcePath = PathFromHandle(FileRef.FileHandle); - std::filesystem::path DestPath = Name.ShardedPath.c_str(); - int Ret = link(SourcePath.c_str(), DestPath.c_str()); - if (Ret < 0 && zen::GetLastError() == ENOENT) + std::error_code Ec; + std::filesystem::path SourcePath = PathFromHandle(FileRef.FileHandle, Ec); + if (Ec) { - // Destination directory doesn't exist. Create it any try again. - CreateDirectories(DestPath.parent_path().c_str()); - Ret = link(SourcePath.c_str(), DestPath.c_str()); + ZEN_WARN("link of CAS payload file {} failed ('{}'), falling back to regular write for insert of {}", + FileRef.FileHandle, + Ec.message(), + ChunkHash); } - if (Ret == 0) + else { - m_CasLog.Append({.Key = ChunkHash, .Size = Chunk.Size()}); - Chunk.SetDeleteOnClose(false); - - HashLock.ReleaseNow(); - bool IsNew = false; + std::filesystem::path DestPath = Name.ShardedPath.c_str(); + int Ret = link(SourcePath.c_str(), DestPath.c_str()); + if (Ret < 0 && zen::GetLastError() == ENOENT) { - RwLock::ExclusiveLockScope __(m_Lock); - IsNew = m_Index.insert({ChunkHash, IndexEntry{.Size = Chunk.Size()}}).second; + // Destination directory doesn't exist. Create it any try again. + CreateDirectories(DestPath.parent_path().c_str()); + Ret = link(SourcePath.c_str(), DestPath.c_str()); } - if (IsNew) + if (Ret == 0) { - m_TotalSize.fetch_add(Chunk.Size(), std::memory_order::relaxed); - } - return CasStore::InsertResult{.New = IsNew}; - } - else - { - int LinkError = zen::GetLastError(); + m_CasLog.Append({.Key = ChunkHash, .Size = Chunk.Size()}); + Chunk.SetDeleteOnClose(false); - // It is possible that someone beat us to it in linking the file. In that - // case a "file exists" error is okay. All others are not. - if (LinkError == EEXIST) - { HashLock.ReleaseNow(); bool IsNew = false; { @@ -506,10 +495,31 @@ FileCasStrategy::InsertChunk(IoBuffer Chunk, const IoHash& ChunkHash, CasStore:: } return CasStore::InsertResult{.New = IsNew}; } + else + { + int LinkError = zen::GetLastError(); - ZEN_WARN("link of CAS payload file failed ('{}'), falling back to regular write for insert of {}", - GetSystemErrorAsString(LinkError), - ChunkHash); + // It is possible that someone beat us to it in linking the file. In that + // case a "file exists" error is okay. All others are not. + if (LinkError == EEXIST) + { + HashLock.ReleaseNow(); + bool IsNew = false; + { + RwLock::ExclusiveLockScope __(m_Lock); + IsNew = m_Index.insert({ChunkHash, IndexEntry{.Size = Chunk.Size()}}).second; + } + if (IsNew) + { + m_TotalSize.fetch_add(Chunk.Size(), std::memory_order::relaxed); + } + return CasStore::InsertResult{.New = IsNew}; + } + + ZEN_WARN("link of CAS payload file failed ('{}'), falling back to regular write for insert of {}", + GetSystemErrorAsString(LinkError), + ChunkHash); + } } #endif // ZEN_PLATFORM_* } |