aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/zenstore/include/zenstore/projectstore.h4
-rw-r--r--src/zenstore/projectstore.cpp45
2 files changed, 37 insertions, 12 deletions
diff --git a/src/zenstore/include/zenstore/projectstore.h b/src/zenstore/include/zenstore/projectstore.h
index ad108f65b..09c3096ad 100644
--- a/src/zenstore/include/zenstore/projectstore.h
+++ b/src/zenstore/include/zenstore/projectstore.h
@@ -308,8 +308,8 @@ public:
/** Scan oplog and register each entry, thus updating the in-memory tracking tables
*/
uint32_t GetUnusedSpacePercentLocked() const;
- void WriteIndexSnapshot();
- void ReadIndexSnapshot();
+ void WriteIndexSnapshot(RwLock::ExclusiveLockScope&);
+ void ReadIndexSnapshot(RwLock::ExclusiveLockScope&);
void RefreshLsnToPayloadOffsetMap(RwLock::ExclusiveLockScope&);
struct OplogEntryMapping
diff --git a/src/zenstore/projectstore.cpp b/src/zenstore/projectstore.cpp
index 7e9ff50bb..2f97de5de 100644
--- a/src/zenstore/projectstore.cpp
+++ b/src/zenstore/projectstore.cpp
@@ -1113,9 +1113,32 @@ ProjectStore::Oplog::Oplog(const LoggerRef& InLog,
ProjectStore::Oplog::~Oplog()
{
- if (m_Storage)
+ try
+ {
+ RwLock::ExclusiveLockScope Lock(m_OplogLock);
+ if (m_Storage)
+ {
+ if (m_Mode == EMode::kFull)
+ {
+ m_Storage->Flush();
+ if (!m_MetaValid)
+ {
+ std::error_code DummyEc;
+ RemoveFile(m_MetaPath, DummyEc);
+ }
+
+ uint64_t LogCount = m_Storage->LogCount();
+ if (m_LogFlushPosition != LogCount || m_IsLegacySnapshot)
+ {
+ WriteIndexSnapshot(Lock);
+ }
+ }
+ m_Storage = {};
+ }
+ }
+ catch (const std::exception& Ex)
{
- Flush();
+ ZEN_ERROR("Oplog::~Oplog threw exception: '{}'", Ex.what());
}
}
@@ -1128,7 +1151,7 @@ ProjectStore::Oplog::Flush()
if (m_Mode == EMode::kFull)
{
- RwLock::SharedLockScope Lock(m_OplogLock);
+ RwLock::ExclusiveLockScope Lock(m_OplogLock);
if (!m_Storage)
{
@@ -1145,7 +1168,7 @@ ProjectStore::Oplog::Flush()
uint64_t LogCount = m_Storage->LogCount();
if (m_LogFlushPosition != LogCount || m_IsLegacySnapshot)
{
- WriteIndexSnapshot();
+ WriteIndexSnapshot(Lock);
}
}
}
@@ -1417,7 +1440,9 @@ ProjectStore::Oplog::Read()
ZEN_ASSERT(!m_LsnToPayloadOffsetMap);
- ReadIndexSnapshot();
+ RwLock::ExclusiveLockScope Lock(m_OplogLock);
+
+ ReadIndexSnapshot(Lock);
if (m_Mode == EMode::kFull)
{
@@ -1455,7 +1480,7 @@ ProjectStore::Oplog::Read()
if (m_Storage->LogCount() != m_LogFlushPosition || m_IsLegacySnapshot)
{
- WriteIndexSnapshot();
+ WriteIndexSnapshot(Lock);
}
}
else
@@ -1742,7 +1767,7 @@ ProjectStore::Oplog::Validate(const std::filesystem::path& ProjectRootDir,
}
void
-ProjectStore::Oplog::WriteIndexSnapshot()
+ProjectStore::Oplog::WriteIndexSnapshot(RwLock::ExclusiveLockScope&)
{
ZEN_MEMSCOPE(GetProjectstoreTag());
ZEN_TRACE_CPU("Oplog::WriteIndexSnapshot");
@@ -1883,7 +1908,7 @@ ProjectStore::Oplog::WriteIndexSnapshot()
}
void
-ProjectStore::Oplog::ReadIndexSnapshot()
+ProjectStore::Oplog::ReadIndexSnapshot(RwLock::ExclusiveLockScope&)
{
ZEN_MEMSCOPE(GetProjectstoreTag());
ZEN_TRACE_CPU("Oplog::ReadIndexSnapshot");
@@ -2212,7 +2237,7 @@ ProjectStore::Oplog::Compact(bool DryRun, bool RetainLSNs, std::string_view LogP
}
void
-ProjectStore::Oplog::Compact(RwLock::ExclusiveLockScope&, bool DryRun, bool RetainLSNs, std::string_view LogPrefix)
+ProjectStore::Oplog::Compact(RwLock::ExclusiveLockScope& Lock, bool DryRun, bool RetainLSNs, std::string_view LogPrefix)
{
ZEN_ASSERT(m_Mode == EMode::kFull);
@@ -2250,7 +2275,7 @@ ProjectStore::Oplog::Compact(RwLock::ExclusiveLockScope&, bool DryRun, bool Reta
m_OpToPayloadOffsetMap.swap(OpToPayloadOffsetMap);
m_OpLogPayloads.swap(OpPayloads);
m_LsnToPayloadOffsetMap.reset();
- WriteIndexSnapshot();
+ WriteIndexSnapshot(Lock);
}
uint64_t PostSize = TotalSize();