diff options
| author | Dan Engelbrecht <[email protected]> | 2022-03-21 10:06:10 +0100 |
|---|---|---|
| committer | Dan Engelbrecht <[email protected]> | 2022-03-31 11:28:33 +0200 |
| commit | f98dfd8f2f853aeb33eff572a9658f2993cc17bb (patch) | |
| tree | ff50b82c2f3783ebb0057b27c39cb72fafdc1c90 /zenstore/compactcas.cpp | |
| parent | Change block size of compactcas stores (diff) | |
| download | zen-f98dfd8f2f853aeb33eff572a9658f2993cc17bb.tar.xz zen-f98dfd8f2f853aeb33eff572a9658f2993cc17bb.zip | |
Move MarkAsDeleteOnClose to BasicFile
Diffstat (limited to 'zenstore/compactcas.cpp')
| -rw-r--r-- | zenstore/compactcas.cpp | 77 |
1 files changed, 32 insertions, 45 deletions
diff --git a/zenstore/compactcas.cpp b/zenstore/compactcas.cpp index 99f00f5af..82e0d49bf 100644 --- a/zenstore/compactcas.cpp +++ b/zenstore/compactcas.cpp @@ -82,44 +82,21 @@ namespace { return Path.ToPath(); } - void MarkFileAsDeleteOnClose(void* FileHandle) - { -#if ZEN_PLATFORM_WINDOWS - FILE_DISPOSITION_INFO Fdi{}; - Fdi.DeleteFile = TRUE; - BOOL Success = SetFileInformationByHandle(FileHandle, FileDispositionInfo, &Fdi, sizeof Fdi); - if (!Success) - { - ZEN_WARN("Failed to flag temporary payload file '{}' for deletion: '{}'", PathFromHandle(FileHandle), GetLastErrorAsString()); - } -#elif ZEN_PLATFORM_LINUX || ZEN_PLATFORM_MAC - std::filesystem::path SourcePath = PathFromHandle(FileRef.FileHandle); - if (unlink(SourcePath.c_str()) < 0) - { - int UnlinkError = zen::GetLastError(); - if (UnlinkError != ENOENT) - { - ZEN_WARN("unlink of CAS payload file failed ('{}')", GetSystemErrorAsString(UnlinkError)); - } - } -#endif - } - } // namespace struct CasContainerStrategy::ChunkBlock { explicit ChunkBlock(const std::filesystem::path& BlockPath); ~ChunkBlock(); - const std::filesystem::path GetPath() const; - void Open(); - void Create(uint64_t InitialSize); - void MarkAsDeleteOnClose(); - uint64_t FileSize(); - IoBuffer GetRange(uint64_t Offset, uint64_t Size); - void Read(void* Data, uint64_t Size, uint64_t FileOffset); - void Write(const void* Data, uint64_t Size, uint64_t FileOffset); - void Flush(); + const std::filesystem::path& GetPath() const; + void Open(); + void Create(uint64_t InitialSize); + void MarkAsDeleteOnClose(std::error_code& Ec); + uint64_t FileSize(); + IoBuffer GetRange(uint64_t Offset, uint64_t Size); + void Read(void* Data, uint64_t Size, uint64_t FileOffset); + void Write(const void* Data, uint64_t Size, uint64_t FileOffset); + void Flush(); void StreamByteRange(uint64_t FileOffset, uint64_t Size, std::function<void(const void* Data, uint64_t Size)>&& ChunkFun); private: @@ -142,7 +119,7 @@ CasContainerStrategy::ChunkBlock::~ChunkBlock() } } -const std::filesystem::path +const std::filesystem::path& CasContainerStrategy::ChunkBlock::GetPath() const { return m_Path; @@ -194,19 +171,19 @@ CasContainerStrategy::ChunkBlock::FileSize() } void -CasContainerStrategy::ChunkBlock::MarkAsDeleteOnClose() +CasContainerStrategy::ChunkBlock::MarkAsDeleteOnClose(std::error_code& Ec) { RwLock::ExclusiveLockScope _(m_OpenLock); - if (!m_IsOpened.load()) + if (m_IsOpened.load()) { - if (std::filesystem::is_regular_file(m_Path)) - { - std::filesystem::remove(m_Path); - } + m_SmallObjectFile.MarkAsDeleteOnClose(Ec); return; } - void* FileHandle = m_SmallObjectFile.Handle(); - MarkFileAsDeleteOnClose(FileHandle); + if (std::filesystem::is_regular_file(m_Path)) + { + Ec.clear(); + std::filesystem::remove(m_Path, Ec); + } } IoBuffer @@ -356,8 +333,8 @@ CasContainerStrategy::FindChunk(const IoHash& ChunkHash) if (auto BlockIt = m_ChunkBlocks.find(Location.BlockIndex); BlockIt != m_ChunkBlocks.end()) { - if (BlockIt->second) // This happens if the data associated with the block is not found - ie the ucas file is deleted but the - // index not updated + if (BlockIt->second) // This happens if the data associated with the block is not found - ie the ucas file is deleted but + // the index not updated { return BlockIt->second->GetRange(Location.Offset, Location.Size); } @@ -655,7 +632,12 @@ CasContainerStrategy::CollectGarbage(GcContext& GcCtx) RwLock::ExclusiveLockScope _i(m_LocationMapLock); auto BlockFile = m_ChunkBlocks[BlockIndex]; ZEN_INFO("marking cas store file for delete {}, block {}", m_ContainerBaseName, std::to_string(BlockIndex)); - BlockFile->MarkAsDeleteOnClose(); + std::error_code Ec; + BlockFile->MarkAsDeleteOnClose(Ec); + if (Ec) + { + ZEN_WARN("Failed to flag file '{}' for deletion: '{}'", BlockFile->GetPath(), Ec.message()); + } BlockFile.reset(); continue; } @@ -766,7 +748,12 @@ CasContainerStrategy::CollectGarbage(GcContext& GcCtx) } } ZEN_INFO("marking cas store file for delete {}, block index {}", m_ContainerBaseName, BlockIndex); - BlockFile->MarkAsDeleteOnClose(); + std::error_code Ec; + BlockFile->MarkAsDeleteOnClose(Ec); + if (Ec) + { + ZEN_WARN("Failed to flag file '{}' for deletion: '{}'", BlockFile->GetPath(), Ec.message()); + } BlockFile.reset(); } } |