diff options
| author | Dan Engelbrecht <[email protected]> | 2025-05-12 11:03:46 +0200 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2025-05-12 11:03:46 +0200 |
| commit | a417d19e6d2af229e7fd33c559f6fefee3a81042 (patch) | |
| tree | 48d23f4c4700be6cbaa820d9ac798ddea70218cd /src/zenserver/projectstore/projectstore.cpp | |
| parent | enable per bucket config (#388) (diff) | |
| download | zen-a417d19e6d2af229e7fd33c559f6fefee3a81042.tar.xz zen-a417d19e6d2af229e7fd33c559f6fefee3a81042.zip | |
keep snapshot on log delete fail (#391)
- Improvement: Cleaned up snapshot writing for CompactCAS/FileCas/Cache/Project stores
- Improvement: Safer recovery when failing to delete log for CompactCAS/FileCas/Cache/Project stores
- Improvement: Added log file reset when writing snapshot at startup for FileCas
Diffstat (limited to 'src/zenserver/projectstore/projectstore.cpp')
| -rw-r--r-- | src/zenserver/projectstore/projectstore.cpp | 61 |
1 files changed, 7 insertions, 54 deletions
diff --git a/src/zenserver/projectstore/projectstore.cpp b/src/zenserver/projectstore/projectstore.cpp index 071aab137..6a55efdb7 100644 --- a/src/zenserver/projectstore/projectstore.cpp +++ b/src/zenserver/projectstore/projectstore.cpp @@ -1643,31 +1643,9 @@ ProjectStore::Oplog::WriteIndexSnapshot() namespace fs = std::filesystem; - fs::path IndexPath = m_BasePath / "ops.zidx"; - fs::path TempIndexPath = m_BasePath / "ops.zidx.tmp"; - - // Move index away, we keep it if something goes wrong - if (IsFile(TempIndexPath)) - { - std::error_code Ec; - if (!RemoveFile(TempIndexPath, Ec) || Ec) - { - ZEN_WARN("oplog '{}/{}': snapshot failed to clean up temp snapshot at {}, reason: '{}'", - GetOuterProject()->Identifier, - m_OplogId, - TempIndexPath, - Ec.message()); - return; - } - } - + const fs::path IndexPath = m_BasePath / "ops.zidx"; try { - if (IsFile(IndexPath)) - { - RenameFile(IndexPath, TempIndexPath); - } - // Write the current state of the location map to a new index state std::vector<uint32_t> LSNEntries; std::vector<Oid> Keys; @@ -1781,7 +1759,11 @@ ProjectStore::Oplog::WriteIndexSnapshot() ObjectIndexFile.MoveTemporaryIntoPlace(IndexPath, Ec); if (Ec) { - throw std::system_error(Ec, fmt::format("Failed to move temp file '{}' to '{}'", ObjectIndexFile.GetPath(), IndexPath)); + throw std::system_error(Ec, + fmt::format("Snapshot failed to rename new snapshot '{}' to '{}', reason: '{}'", + ObjectIndexFile.GetPath(), + IndexPath, + Ec.message())); } EntryCount = LSNEntries.size(); m_LogFlushPosition = IndexLogPosition; @@ -1789,35 +1771,6 @@ ProjectStore::Oplog::WriteIndexSnapshot() catch (const std::exception& Err) { ZEN_WARN("oplog '{}/{}': snapshot FAILED, reason: '{}'", m_OuterProject->Identifier, m_OplogId, Err.what()); - - // Restore any previous snapshot - - if (IsFile(TempIndexPath)) - { - std::error_code Ec; - RemoveFile(IndexPath, Ec); // We don't care if this fails, we try to move the old temp file regardless - RenameFile(TempIndexPath, IndexPath, Ec); - if (Ec) - { - ZEN_WARN("oplog '{}/{}': snapshot failed to restore old snapshot from {}, reason: '{}'", - m_OuterProject->Identifier, - m_OplogId, - TempIndexPath, - Ec.message()); - } - } - } - if (IsFile(TempIndexPath)) - { - std::error_code Ec; - if (!RemoveFile(TempIndexPath, Ec) || Ec) - { - ZEN_WARN("oplog '{}/{}': snapshot failed to remove temporary file {}, reason: '{}'", - m_OuterProject->Identifier, - m_OplogId, - TempIndexPath, - Ec.message()); - } } } @@ -1827,7 +1780,7 @@ ProjectStore::Oplog::ReadIndexSnapshot() ZEN_MEMSCOPE(GetProjectstoreTag()); ZEN_TRACE_CPU("Oplog::ReadIndexSnapshot"); - std::filesystem::path IndexPath = m_BasePath / "ops.zidx"; + const std::filesystem::path IndexPath = m_BasePath / "ops.zidx"; if (IsFile(IndexPath)) { uint64_t EntryCount = 0; |