aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2022-03-31 10:14:44 +0200
committerDan Engelbrecht <[email protected]>2022-03-31 11:29:28 +0200
commit3aebe78d461778bd743d63e1a296fcc7df564911 (patch)
treeebdd9f2b12d9c3f140b11078e09d33ceb7252635
parentimproved logging for gc/migration (diff)
downloadzen-3aebe78d461778bd743d63e1a296fcc7df564911.tar.xz
zen-3aebe78d461778bd743d63e1a296fcc7df564911.zip
Truncate migrated and new blocks after gc to save disk space
-rw-r--r--zenstore/blockstore.cpp6
-rw-r--r--zenstore/compactcas.cpp12
-rw-r--r--zenstore/include/zenstore/blockstore.h1
3 files changed, 19 insertions, 0 deletions
diff --git a/zenstore/blockstore.cpp b/zenstore/blockstore.cpp
index 350d9bb39..7eb73101a 100644
--- a/zenstore/blockstore.cpp
+++ b/zenstore/blockstore.cpp
@@ -91,6 +91,12 @@ BlockStoreFile::Write(const void* Data, uint64_t Size, uint64_t FileOffset)
}
void
+BlockStoreFile::Truncate(uint64_t Size)
+{
+ m_File.SetFileSize(Size);
+}
+
+void
BlockStoreFile::Flush()
{
m_File.Flush();
diff --git a/zenstore/compactcas.cpp b/zenstore/compactcas.cpp
index 9461d7d3a..dfaf72727 100644
--- a/zenstore/compactcas.cpp
+++ b/zenstore/compactcas.cpp
@@ -564,6 +564,7 @@ namespace {
ChunkBlock.Write(Buffer.data(), Size, Offset);
Offset += Size;
}
+ ChunkBlock.Truncate(Offset);
ChunkBlock.Flush();
std::vector<CasDiskIndexEntry> LogEntries;
@@ -1152,6 +1153,11 @@ CasContainerStrategy::CollectGarbage(GcContext& GcCtx)
m_CasLog.Append(LogEntries);
m_CasLog.Flush();
+ if (NewBlockFile)
+ {
+ NewBlockFile->Truncate(WriteOffset);
+ NewBlockFile->Flush();
+ }
{
RwLock::ExclusiveLockScope __(m_LocationMapLock);
Stopwatch Timer;
@@ -1229,6 +1235,12 @@ CasContainerStrategy::CollectGarbage(GcContext& GcCtx)
WriteOffset = RoundUp(WriteOffset + Chunk.size(), m_PayloadAlignment);
}
Chunk.clear();
+ if (NewBlockFile)
+ {
+ NewBlockFile->Truncate(WriteOffset);
+ NewBlockFile->Flush();
+ NewBlockFile = Ref<BlockStoreFile>();
+ }
const std::vector<IoHash>& DeleteMap = DeleteChunks[ChunkMapIndex];
std::vector<CasDiskIndexEntry> LogEntries = MakeCasDiskEntries(MovedBlockChunks, DeleteMap);
diff --git a/zenstore/include/zenstore/blockstore.h b/zenstore/include/zenstore/blockstore.h
index 54cdfeaa8..424db461a 100644
--- a/zenstore/include/zenstore/blockstore.h
+++ b/zenstore/include/zenstore/blockstore.h
@@ -89,6 +89,7 @@ struct BlockStoreFile : public RefCounted
IoBuffer GetChunk(uint64_t Offset, uint64_t Size);
void Read(void* Data, uint64_t Size, uint64_t FileOffset);
void Write(const void* Data, uint64_t Size, uint64_t FileOffset);
+ void Truncate(uint64_t Size);
void Flush();
void StreamByteRange(uint64_t FileOffset, uint64_t Size, std::function<void(const void* Data, uint64_t Size)>&& ChunkFun);