aboutsummaryrefslogtreecommitdiff
path: root/src/zenstore
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2024-09-30 09:27:36 +0200
committerGitHub Enterprise <[email protected]>2024-09-30 09:27:36 +0200
commit54ee1372c4254e185e83c8eb9329ace9704664c6 (patch)
treea766c6bb340db9e26fe23247da7c5fce1fe39395 /src/zenstore
parentFixing compilation errors with fmt v11 (#172) (diff)
downloadzen-54ee1372c4254e185e83c8eb9329ace9704664c6.tar.xz
zen-54ee1372c4254e185e83c8eb9329ace9704664c6.zip
optimize startup time (#175)
* use tsl::robin_set for BlockIndexSet don't calculate full block location when only block index is needed * don't copy visitor function * reserve space for attachments
Diffstat (limited to 'src/zenstore')
-rw-r--r--src/zenstore/blockstore.cpp20
-rw-r--r--src/zenstore/cache/cachedisklayer.cpp23
-rw-r--r--src/zenstore/compactcas.cpp6
-rw-r--r--src/zenstore/include/zenstore/blockstore.h12
4 files changed, 26 insertions, 35 deletions
diff --git a/src/zenstore/blockstore.cpp b/src/zenstore/blockstore.cpp
index 7c6677052..592d1c7fb 100644
--- a/src/zenstore/blockstore.cpp
+++ b/src/zenstore/blockstore.cpp
@@ -331,17 +331,7 @@ BlockStore::Initialize(const std::filesystem::path& BlocksBasePath, uint64_t Max
}
void
-BlockStore::BlockIndexSet::Add(uint32_t BlockIndex)
-{
- if (!std::binary_search(begin(BlockIndexes), end(BlockIndexes), BlockIndex))
- {
- auto It = std::lower_bound(begin(BlockIndexes), end(BlockIndexes), BlockIndex);
- BlockIndexes.insert(It, BlockIndex);
- }
-}
-
-void
-BlockStore::SyncExistingBlocksOnDisk(const BlockIndexSet& KnownLocations)
+BlockStore::SyncExistingBlocksOnDisk(const BlockIndexSet& KnownBlocks)
{
ZEN_TRACE_CPU("BlockStore::SyncExistingBlocksOnDisk");
@@ -355,7 +345,7 @@ BlockStore::SyncExistingBlocksOnDisk(const BlockIndexSet& KnownLocations)
DeleteBlocks.insert(It.first);
}
- for (const uint32_t BlockIndex : KnownLocations.GetBlockIndices())
+ for (const uint32_t BlockIndex : KnownBlocks)
{
DeleteBlocks.erase(BlockIndex);
if (auto It = m_ChunkBlocks.find(BlockIndex); It != m_ChunkBlocks.end() && !It->second.IsNull())
@@ -1968,9 +1958,9 @@ TEST_CASE("blockstore.clean.stray.blocks")
// Recreate a fake block for a missing chunk location
BlockStore::BlockIndexSet KnownBlocks;
- KnownBlocks.Add(FirstChunkLocation.BlockIndex);
- KnownBlocks.Add(SecondChunkLocation.BlockIndex);
- KnownBlocks.Add(ThirdChunkLocation.BlockIndex);
+ KnownBlocks.insert(FirstChunkLocation.BlockIndex);
+ KnownBlocks.insert(SecondChunkLocation.BlockIndex);
+ KnownBlocks.insert(ThirdChunkLocation.BlockIndex);
Store.SyncExistingBlocksOnDisk(KnownBlocks);
// We create a fake block for the location - we should still not be able to get the chunk
diff --git a/src/zenstore/cache/cachedisklayer.cpp b/src/zenstore/cache/cachedisklayer.cpp
index a4aa497c4..3fc4eca03 100644
--- a/src/zenstore/cache/cachedisklayer.cpp
+++ b/src/zenstore/cache/cachedisklayer.cpp
@@ -1136,8 +1136,8 @@ ZenCacheDiskLayer::CacheBucket::InitializeIndexFromDisk(RwLock::ExclusiveLockSco
}
else
{
- const BlockStoreLocation& BlockLocation = Location.GetBlockLocation(m_Configuration.PayloadAlignment);
- KnownBlocks.Add(BlockLocation.BlockIndex);
+ uint32_t BlockIndex = Location.Location.BlockLocation.GetBlockIndex();
+ KnownBlocks.insert(BlockIndex);
}
}
m_BlockStore.SyncExistingBlocksOnDisk(KnownBlocks);
@@ -3649,6 +3649,7 @@ ZenCacheDiskLayer::CacheBucket::GetReferences(GcCtx& Ctx, bool StateIsAlreadyLoc
{
continue;
}
+
const IoHash& Key = Entry.first;
if (Loc.IsFlagSet(DiskLocation::kStandaloneFile))
{
@@ -3672,7 +3673,10 @@ ZenCacheDiskLayer::CacheBucket::GetReferences(GcCtx& Ctx, bool StateIsAlreadyLoc
}
}
- for (std::vector<std::size_t> ChunkIndexes : InlineBlockChunkIndexes)
+ OutReferences.reserve(OutReferences.size() + InlineKeys.size() +
+ StandaloneKeys.size()); // Make space for at least one attachment per record
+
+ for (const std::vector<std::size_t>& ChunkIndexes : InlineBlockChunkIndexes)
{
ZEN_ASSERT(!ChunkIndexes.empty());
@@ -3694,12 +3698,15 @@ ZenCacheDiskLayer::CacheBucket::GetReferences(GcCtx& Ctx, bool StateIsAlreadyLoc
auto CaptureAttachments = [&](size_t ChunkIndex, MemoryView Data) {
if (GetAttachments(Data))
{
- size_t AttachmentCount = OutReferences.size() - NextPrecachedReferencesStart;
- if (WriteMetaData && AttachmentCount > 0)
+ if (WriteMetaData)
{
- Keys.push_back(InlineKeys[ChunkIndex]);
- AttachmentCounts.push_back(gsl::narrow<uint32_t>(AttachmentCount));
- NextPrecachedReferencesStart += AttachmentCount;
+ size_t AttachmentCount = OutReferences.size() - NextPrecachedReferencesStart;
+ if (AttachmentCount > 0)
+ {
+ Keys.push_back(InlineKeys[ChunkIndex]);
+ AttachmentCounts.push_back(gsl::narrow<uint32_t>(AttachmentCount));
+ NextPrecachedReferencesStart += AttachmentCount;
+ }
}
}
};
diff --git a/src/zenstore/compactcas.cpp b/src/zenstore/compactcas.cpp
index 6af07a606..5fca3046c 100644
--- a/src/zenstore/compactcas.cpp
+++ b/src/zenstore/compactcas.cpp
@@ -1293,9 +1293,9 @@ CasContainerStrategy::OpenContainer(bool IsNewStore)
for (const auto& Entry : m_LocationMap)
{
- const BlockStoreDiskLocation& DiskLocation = m_Locations[Entry.second];
- BlockStoreLocation BlockLocation = DiskLocation.Get(m_PayloadAlignment);
- KnownBlocks.Add(BlockLocation.BlockIndex);
+ const BlockStoreDiskLocation& DiskLocation = m_Locations[Entry.second];
+ uint32_t BlockIndex = DiskLocation.GetBlockIndex();
+ KnownBlocks.insert(BlockIndex);
}
m_BlockStore.SyncExistingBlocksOnDisk(KnownBlocks);
diff --git a/src/zenstore/include/zenstore/blockstore.h b/src/zenstore/include/zenstore/blockstore.h
index 29c53cf22..5af9aeb10 100644
--- a/src/zenstore/include/zenstore/blockstore.h
+++ b/src/zenstore/include/zenstore/blockstore.h
@@ -8,6 +8,7 @@
ZEN_THIRD_PARTY_INCLUDES_START
#include <tsl/robin_map.h>
+#include <tsl/robin_set.h>
ZEN_THIRD_PARTY_INCLUDES_END
#include <unordered_set>
@@ -144,18 +145,11 @@ public:
void Initialize(const std::filesystem::path& BlocksBasePath, uint64_t MaxBlockSize, uint64_t MaxBlockCount);
- struct BlockIndexSet
- {
- void Add(uint32_t BlockIndex);
- std::span<const uint32_t> GetBlockIndices() const { return BlockIndexes; }
-
- private:
- std::vector<uint32_t> BlockIndexes;
- };
+ typedef tsl::robin_set<uint32_t> BlockIndexSet;
// Ask the store to create empty blocks for all locations that does not have a block
// Remove any block that is not referenced
- void SyncExistingBlocksOnDisk(const BlockIndexSet& KnownLocations);
+ void SyncExistingBlocksOnDisk(const BlockIndexSet& KnownBlocks);
BlockEntryCountMap GetBlocksToCompact(const BlockUsageMap& BlockUsage, uint32_t BlockUsageThresholdPercent);
void Close();