aboutsummaryrefslogtreecommitdiff
path: root/src/zenstore/blockstore.cpp
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2023-09-04 09:14:46 -0400
committerGitHub <[email protected]>2023-09-04 15:14:46 +0200
commitf43bee9eed90ee5175f9b3e0dd2a7b7d4b3145e4 (patch)
tree02c1ed9658eadfdfd13795b932e4743b566a5941 /src/zenstore/blockstore.cpp
parentadd `--write-config` to zenserver options (#382) (diff)
downloadzen-f43bee9eed90ee5175f9b3e0dd2a7b7d4b3145e4.tar.xz
zen-f43bee9eed90ee5175f9b3e0dd2a7b7d4b3145e4.zip
retry file create (#383)
* add retry logic when creating files * only write disk usage log if disk writes are allowed * changelog
Diffstat (limited to 'src/zenstore/blockstore.cpp')
-rw-r--r--src/zenstore/blockstore.cpp25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/zenstore/blockstore.cpp b/src/zenstore/blockstore.cpp
index d1490dce2..abf77f8a6 100644
--- a/src/zenstore/blockstore.cpp
+++ b/src/zenstore/blockstore.cpp
@@ -48,7 +48,17 @@ BlockStoreFile::GetPath() const
void
BlockStoreFile::Open()
{
- m_File.Open(m_Path, BasicFile::Mode::kDelete);
+ uint32_t RetriesLeft = 3;
+ m_File.Open(m_Path, BasicFile::Mode::kDelete, [&](std::error_code& Ec) {
+ if (RetriesLeft == 0)
+ {
+ return false;
+ }
+ ZEN_WARN("Failed to open cas block '{}', reason: '{}', retries left: {}.", m_Path, Ec.message(), RetriesLeft);
+ Sleep(100 - (3 - RetriesLeft) * 100); // Total 600 ms
+ RetriesLeft--;
+ return true;
+ });
void* FileHandle = m_File.Handle();
m_IoBuffer = IoBuffer(IoBuffer::File, FileHandle, 0, m_File.FileSize());
}
@@ -62,7 +72,18 @@ BlockStoreFile::Create(uint64_t InitialSize)
CreateDirectories(ParentPath);
}
- m_File.Open(m_Path, BasicFile::Mode::kTruncateDelete);
+ uint32_t RetriesLeft = 3;
+ m_File.Open(m_Path, BasicFile::Mode::kTruncateDelete, [&](std::error_code& Ec) {
+ if (RetriesLeft == 0)
+ {
+ return false;
+ }
+ ZEN_WARN("Failed to create cas block '{}', reason: '{}', retries left: {}.", m_Path, Ec.message(), RetriesLeft);
+ Sleep(100 - (3 - RetriesLeft) * 100); // Total 600 ms
+ RetriesLeft--;
+ return true;
+ });
+
void* FileHandle = m_File.Handle();
// We map our m_IoBuffer beyond the file size as we will grow it over time and want