aboutsummaryrefslogtreecommitdiff
path: root/zenstore/include
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2022-03-24 22:41:46 +0100
committerDan Engelbrecht <[email protected]>2022-03-31 11:29:27 +0200
commit52bf08afc4b9da9ccdd73089c8ebfc7bda859bd3 (patch)
tree87fdb172c98fd05b5c64398cce6b1c6be6db257e /zenstore/include
parentclean up paths (diff)
downloadzen-52bf08afc4b9da9ccdd73089c8ebfc7bda859bd3.tar.xz
zen-52bf08afc4b9da9ccdd73089c8ebfc7bda859bd3.zip
Migration now works in larger disk IO chunks
BasicFile and CasLogFile now has new explicit modes instead of create true/false
Diffstat (limited to 'zenstore/include')
-rw-r--r--zenstore/include/zenstore/basicfile.h18
-rw-r--r--zenstore/include/zenstore/blockstore.h4
-rw-r--r--zenstore/include/zenstore/caslog.h13
3 files changed, 29 insertions, 6 deletions
diff --git a/zenstore/include/zenstore/basicfile.h b/zenstore/include/zenstore/basicfile.h
index 30bb4ee8f..0be9e34f1 100644
--- a/zenstore/include/zenstore/basicfile.h
+++ b/zenstore/include/zenstore/basicfile.h
@@ -31,8 +31,21 @@ public:
BasicFile(const BasicFile&) = delete;
BasicFile& operator=(const BasicFile&) = delete;
- void Open(const std::filesystem::path& FileName, bool IsCreate);
- void Open(const std::filesystem::path& FileName, bool IsCreate, std::error_code& Ec);
+ static constexpr uint32_t kAccessTruncate = 1 << 0;
+ static constexpr uint32_t kAccessWrite = 1 << 1;
+ static constexpr uint32_t kAccessDelete = 1 << 2;
+
+ enum class EMode : uint32_t
+ {
+ kRead = 0,
+ kWrite = kAccessWrite,
+ kTruncate = kAccessWrite | kAccessTruncate,
+ kDelete = kAccessWrite | kAccessDelete,
+ kTruncateDelete = kAccessWrite | kAccessTruncate | kAccessDelete
+ };
+
+ void Open(const std::filesystem::path& FileName, EMode Mode);
+ void Open(const std::filesystem::path& FileName, EMode Mode, std::error_code& Ec);
void Close();
void Read(void* Data, uint64_t Size, uint64_t FileOffset);
void StreamFile(std::function<void(const void* Data, uint64_t Size)>&& ChunkFun);
@@ -58,6 +71,7 @@ public:
protected:
void* m_FileHandle = nullptr; // This is either null or valid
+private:
};
/**
diff --git a/zenstore/include/zenstore/blockstore.h b/zenstore/include/zenstore/blockstore.h
index 306282665..5222ee50e 100644
--- a/zenstore/include/zenstore/blockstore.h
+++ b/zenstore/include/zenstore/blockstore.h
@@ -50,11 +50,11 @@ struct BlockStoreDiskLocation
return static_cast<std::uint32_t>(PackedOffset >> MaxOffsetBits);
}
- inline uint64_t GetOffset() const
+ inline uint64_t GetOffset(uint64_t OffsetAlignment) const
{
uint64_t PackedOffset = 0;
memcpy(&PackedOffset, &m_Offset, sizeof m_Offset);
- return PackedOffset & MaxOffset;
+ return (PackedOffset & MaxOffset) * OffsetAlignment;
}
inline uint64_t GetSize() const { return m_Size; }
diff --git a/zenstore/include/zenstore/caslog.h b/zenstore/include/zenstore/caslog.h
index 4c1bf8196..5b6cc24a0 100644
--- a/zenstore/include/zenstore/caslog.h
+++ b/zenstore/include/zenstore/caslog.h
@@ -15,7 +15,14 @@ public:
CasLogFile();
~CasLogFile();
- void Open(std::filesystem::path FileName, size_t RecordSize, bool isCreate);
+ enum class EMode
+ {
+ kRead,
+ kWrite,
+ kTruncate
+ };
+
+ void Open(std::filesystem::path FileName, size_t RecordSize, EMode Mode);
void Append(const void* DataPointer, uint64_t DataSize);
void Replay(std::function<void(const void*)>&& Handler);
void Flush();
@@ -41,6 +48,8 @@ private:
static_assert(sizeof(FileHeader) == 64);
private:
+ void Open(std::filesystem::path FileName, size_t RecordSize, BasicFile::EMode Mode);
+
BasicFile m_File;
FileHeader m_Header;
size_t m_RecordSize = 1;
@@ -51,7 +60,7 @@ template<typename T>
class TCasLogFile : public CasLogFile
{
public:
- void Open(std::filesystem::path FileName, bool IsCreate) { CasLogFile::Open(FileName, sizeof(T), IsCreate); }
+ void Open(std::filesystem::path FileName, EMode Mode) { CasLogFile::Open(FileName, sizeof(T), Mode); }
// This should be called before the Replay() is called to do some basic sanity checking
bool Initialize() { return true; }