aboutsummaryrefslogtreecommitdiff
path: root/zenstore/blockstore.cpp
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2022-03-27 20:13:54 +0200
committerDan Engelbrecht <[email protected]>2022-03-31 11:29:28 +0200
commit1ed438c250114e1f5ffb7355429862383ffa505d (patch)
tree9e2ce7cfdd6091a3651d5330455965587c3510f9 /zenstore/blockstore.cpp
parentfix cas log parsing (diff)
downloadzen-1ed438c250114e1f5ffb7355429862383ffa505d.tar.xz
zen-1ed438c250114e1f5ffb7355429862383ffa505d.zip
keep all block files open from start
Diffstat (limited to 'zenstore/blockstore.cpp')
-rw-r--r--zenstore/blockstore.cpp27
1 files changed, 10 insertions, 17 deletions
diff --git a/zenstore/blockstore.cpp b/zenstore/blockstore.cpp
index e43c3a00f..3d2d77b4e 100644
--- a/zenstore/blockstore.cpp
+++ b/zenstore/blockstore.cpp
@@ -24,7 +24,7 @@ BlockStoreFile::BlockStoreFile(const std::filesystem::path& BlockPath) : m_Path(
BlockStoreFile::~BlockStoreFile()
{
- RwLock::ExclusiveLockScope _(m_OpenLock);
+ RwLock::ExclusiveLockScope _(m_FileLock);
m_IoBuffer = IoBuffer();
m_File.Detach();
}
@@ -36,8 +36,9 @@ BlockStoreFile::GetPath() const
}
void
-BlockStoreFile::InternalOpen()
+BlockStoreFile::Open()
{
+ RwLock::ExclusiveLockScope _(m_FileLock);
if (m_File.Handle())
{
return;
@@ -48,16 +49,9 @@ BlockStoreFile::InternalOpen()
}
void
-BlockStoreFile::Open()
-{
- RwLock::ExclusiveLockScope _(m_OpenLock);
- InternalOpen();
-}
-
-void
BlockStoreFile::Create(uint64_t InitialSize)
{
- RwLock::ExclusiveLockScope _(m_OpenLock);
+ RwLock::ExclusiveLockScope _(m_FileLock);
auto ParentPath = m_Path.parent_path();
if (!std::filesystem::is_directory(ParentPath))
@@ -77,14 +71,14 @@ BlockStoreFile::Create(uint64_t InitialSize)
uint64_t
BlockStoreFile::FileSize()
{
- RwLock::SharedLockScope _(m_OpenLock);
+ RwLock::SharedLockScope _(m_FileLock);
return m_File.FileSize();
}
void
BlockStoreFile::MarkAsDeleteOnClose(std::error_code& Ec)
{
- RwLock::ExclusiveLockScope _(m_OpenLock);
+ RwLock::ExclusiveLockScope _(m_FileLock);
if (m_File.Handle())
{
m_File.MarkAsDeleteOnClose(Ec);
@@ -100,28 +94,27 @@ BlockStoreFile::MarkAsDeleteOnClose(std::error_code& Ec)
IoBuffer
BlockStoreFile::GetChunk(uint64_t Offset, uint64_t Size)
{
- InternalOpen();
return IoBuffer(m_IoBuffer, Offset, Size);
}
void
BlockStoreFile::Read(void* Data, uint64_t Size, uint64_t FileOffset)
{
- RwLock::SharedLockScope _(m_OpenLock);
+ RwLock::SharedLockScope _(m_FileLock);
m_File.Read(Data, Size, FileOffset);
}
void
BlockStoreFile::Write(const void* Data, uint64_t Size, uint64_t FileOffset)
{
- RwLock::SharedLockScope _(m_OpenLock);
+ RwLock::SharedLockScope _(m_FileLock);
m_File.Write(Data, Size, FileOffset);
}
void
BlockStoreFile::Flush()
{
- RwLock::ExclusiveLockScope _(m_OpenLock);
+ RwLock::ExclusiveLockScope _(m_FileLock);
if (!m_File.Handle())
{
return;
@@ -132,7 +125,7 @@ BlockStoreFile::Flush()
void
BlockStoreFile::StreamByteRange(uint64_t FileOffset, uint64_t Size, std::function<void(const void* Data, uint64_t Size)>&& ChunkFun)
{
- RwLock::SharedLockScope _(m_OpenLock);
+ RwLock::SharedLockScope _(m_FileLock);
m_File.StreamByteRange(FileOffset, Size, std::move(ChunkFun));
}