diff options
Diffstat (limited to 'zenstore')
| -rw-r--r-- | zenstore/blockstore.cpp | 16 | ||||
| -rw-r--r-- | zenstore/compactcas.cpp | 18 | ||||
| -rw-r--r-- | zenstore/filecas.cpp | 22 | ||||
| -rw-r--r-- | zenstore/gc.cpp | 10 |
4 files changed, 47 insertions, 19 deletions
diff --git a/zenstore/blockstore.cpp b/zenstore/blockstore.cpp index 5d81d1120..d743c431f 100644 --- a/zenstore/blockstore.cpp +++ b/zenstore/blockstore.cpp @@ -859,7 +859,7 @@ TEST_CASE("blockstore.blockfile") CHECK(!std::filesystem::exists(RootDirectory / "1")); } -namespace { +namespace blockstore::impl { BlockStoreLocation WriteStringAsChunk(BlockStore& Store, std::string_view String, size_t PayloadAlignment) { BlockStoreLocation Location; @@ -907,10 +907,12 @@ namespace { return IoBufferBuilder::MakeCloneFromMemory(Values.data(), Values.size()); } -} // namespace +} // namespace blockstore::impl TEST_CASE("blockstore.chunks") { + using namespace blockstore::impl; + ScopedTemporaryDirectory TempDir; auto RootDirectory = TempDir.Path(); @@ -939,6 +941,8 @@ TEST_CASE("blockstore.chunks") TEST_CASE("blockstore.clean.stray.blocks") { + using namespace blockstore::impl; + ScopedTemporaryDirectory TempDir; auto RootDirectory = TempDir.Path(); @@ -963,6 +967,8 @@ TEST_CASE("blockstore.clean.stray.blocks") TEST_CASE("blockstore.flush.forces.new.block") { + using namespace blockstore::impl; + ScopedTemporaryDirectory TempDir; auto RootDirectory = TempDir.Path(); @@ -984,6 +990,8 @@ TEST_CASE("blockstore.flush.forces.new.block") TEST_CASE("blockstore.iterate.chunks") { + using namespace blockstore::impl; + ScopedTemporaryDirectory TempDir; auto RootDirectory = TempDir.Path(); @@ -1078,6 +1086,8 @@ TEST_CASE("blockstore.iterate.chunks") TEST_CASE("blockstore.reclaim.space") { + using namespace blockstore::impl; + ScopedTemporaryDirectory TempDir; auto RootDirectory = TempDir.Path(); @@ -1193,6 +1203,8 @@ TEST_CASE("blockstore.reclaim.space") TEST_CASE("blockstore.thread.read.write") { + using namespace blockstore::impl; + ScopedTemporaryDirectory TempDir; auto RootDirectory = TempDir.Path(); diff --git a/zenstore/compactcas.cpp b/zenstore/compactcas.cpp index 70a88ecad..60644847f 100644 --- a/zenstore/compactcas.cpp +++ b/zenstore/compactcas.cpp @@ -732,7 +732,7 @@ CasContainerStrategy::OpenContainer(bool IsNewStore) #if ZEN_WITH_TESTS namespace { - static IoBuffer CreateChunk(uint64_t Size) + static IoBuffer CreateRandomChunk(uint64_t Size) { static std::random_device rd; static std::mt19937 g(rd()); @@ -865,7 +865,7 @@ TEST_CASE("compactcas.compact.totalsize") for (int32_t Idx = 0; Idx < kChunkCount; ++Idx) { - IoBuffer Chunk = CreateChunk(kChunkSize); + IoBuffer Chunk = CreateRandomChunk(kChunkSize); const IoHash Hash = HashBuffer(Chunk); CasStore::InsertResult InsertResult = Cas.InsertChunk(Chunk, Hash); ZEN_ASSERT(InsertResult.New); @@ -904,7 +904,7 @@ TEST_CASE("compactcas.gc.basic") CasContainerStrategy Cas(Gc); Cas.Initialize(TempDir.Path(), "cb", 65536, 1 << 4, true); - IoBuffer Chunk = CreateChunk(128); + IoBuffer Chunk = CreateRandomChunk(128); IoHash ChunkHash = IoHash::HashBuffer(Chunk); const CasStore::InsertResult InsertResult = Cas.InsertChunk(Chunk, ChunkHash); @@ -923,7 +923,7 @@ TEST_CASE("compactcas.gc.removefile") { ScopedTemporaryDirectory TempDir; - IoBuffer Chunk = CreateChunk(128); + IoBuffer Chunk = CreateRandomChunk(128); IoHash ChunkHash = IoHash::HashBuffer(Chunk); { GcManager Gc; @@ -964,7 +964,7 @@ TEST_CASE("compactcas.gc.compact") Chunks.reserve(9); for (uint64_t Size : ChunkSizes) { - Chunks.push_back(CreateChunk(Size)); + Chunks.push_back(CreateRandomChunk(Size)); } std::vector<IoHash> ChunkHashes; @@ -1190,7 +1190,7 @@ TEST_CASE("compactcas.gc.deleteblockonopen") Chunks.reserve(20); for (uint64_t Size : ChunkSizes) { - Chunks.push_back(CreateChunk(Size)); + Chunks.push_back(CreateRandomChunk(Size)); } std::vector<IoHash> ChunkHashes; @@ -1256,7 +1256,7 @@ TEST_CASE("compactcas.gc.handleopeniobuffer") Chunks.reserve(20); for (const uint64_t& Size : ChunkSizes) { - Chunks.push_back(CreateChunk(Size)); + Chunks.push_back(CreateRandomChunk(Size)); } std::vector<IoHash> ChunkHashes; @@ -1308,7 +1308,7 @@ TEST_CASE("compactcas.threadedinsert") { while (true) { - IoBuffer Chunk = CreateChunk(kChunkSize); + IoBuffer Chunk = CreateRandomChunk(kChunkSize); IoHash Hash = HashBuffer(Chunk); if (Chunks.contains(Hash)) { @@ -1377,7 +1377,7 @@ TEST_CASE("compactcas.threadedinsert") for (int32_t Idx = 0; Idx < kChunkCount; ++Idx) { - IoBuffer Chunk = CreateChunk(kChunkSize); + IoBuffer Chunk = CreateRandomChunk(kChunkSize); IoHash Hash = HashBuffer(Chunk); NewChunks[Hash] = Chunk; } diff --git a/zenstore/filecas.cpp b/zenstore/filecas.cpp index b4729d558..986cc9ae6 100644 --- a/zenstore/filecas.cpp +++ b/zenstore/filecas.cpp @@ -39,7 +39,7 @@ ZEN_THIRD_PARTY_INCLUDES_END namespace zen { -namespace { +namespace filecas::impl { const char* IndexExtension = ".uidx"; const char* LogExtension = ".ulog"; @@ -77,7 +77,7 @@ namespace { #pragma pack(pop) -} // namespace +} // namespace filecas::impl FileCasStrategy::ShardingHelper::ShardingHelper(const std::filesystem::path& RootPath, const IoHash& ChunkHash) { @@ -125,6 +125,8 @@ FileCasStrategy::~FileCasStrategy() void FileCasStrategy::Initialize(const std::filesystem::path& RootDirectory, bool IsNewStore) { + using namespace filecas::impl; + m_IsInitialized = true; m_RootDirectory = RootDirectory; @@ -1013,6 +1015,8 @@ FileCasStrategy::ValidateEntry(const FileCasIndexEntry& Entry, std::string& OutR void FileCasStrategy::MakeIndexSnapshot() { + using namespace filecas::impl; + uint64_t LogCount = m_CasLog.GetLogCount(); if (m_LogFlushPosition == LogCount) { @@ -1062,12 +1066,12 @@ FileCasStrategy::MakeIndexSnapshot() BasicFile ObjectIndexFile; ObjectIndexFile.Open(IndexPath, BasicFile::Mode::kTruncate); - FileCasIndexHeader Header = {.EntryCount = Entries.size(), .LogPosition = LogCount}; + filecas::impl::FileCasIndexHeader Header = {.EntryCount = Entries.size(), .LogPosition = LogCount}; - Header.Checksum = FileCasIndexHeader::ComputeChecksum(Header); + Header.Checksum = filecas::impl::FileCasIndexHeader::ComputeChecksum(Header); - ObjectIndexFile.Write(&Header, sizeof(FileCasIndexHeader), 0); - ObjectIndexFile.Write(Entries.data(), Entries.size() * sizeof(FileCasIndexEntry), sizeof(FileCasIndexHeader)); + ObjectIndexFile.Write(&Header, sizeof(filecas::impl::FileCasIndexHeader), 0); + ObjectIndexFile.Write(Entries.data(), Entries.size() * sizeof(FileCasIndexEntry), sizeof(filecas::impl::FileCasIndexHeader)); ObjectIndexFile.Flush(); ObjectIndexFile.Close(); EntryCount = Entries.size(); @@ -1093,6 +1097,8 @@ FileCasStrategy::MakeIndexSnapshot() uint64_t FileCasStrategy::ReadIndexFile() { + using namespace filecas::impl; + std::vector<FileCasIndexEntry> Entries; std::filesystem::path IndexPath = GetIndexPath(m_RootDirectory); if (std::filesystem::is_regular_file(IndexPath)) @@ -1179,6 +1185,8 @@ FileCasStrategy::ReadIndexFile() uint64_t FileCasStrategy::ReadLog(uint64_t SkipEntryCount) { + using namespace filecas::impl; + std::filesystem::path LogPath = GetLogPath(m_RootDirectory); if (std::filesystem::is_regular_file(LogPath)) { @@ -1230,6 +1238,8 @@ FileCasStrategy::ReadLog(uint64_t SkipEntryCount) std::vector<FileCasStrategy::FileCasIndexEntry> FileCasStrategy::ScanFolderForCasFiles(const std::filesystem::path& RootDir) { + using namespace filecas::impl; + std::vector<FileCasIndexEntry> Entries; struct Visitor : public FileSystemTraversal::TreeVisitor { diff --git a/zenstore/gc.cpp b/zenstore/gc.cpp index 8d3b8d018..370c3c965 100644 --- a/zenstore/gc.cpp +++ b/zenstore/gc.cpp @@ -888,7 +888,7 @@ GcScheduler::CollectGarbage(const GcClock::TimePoint& ExpireTime, bool Delete, b #if ZEN_WITH_TESTS -namespace { +namespace gc::impl { static IoBuffer CreateChunk(uint64_t Size) { static std::random_device rd; @@ -909,10 +909,12 @@ namespace { { return CompressedBuffer::Compress(SharedBuffer::MakeView(Buffer.GetData(), Buffer.GetSize())); } -} // namespace +} // namespace gc::impl TEST_CASE("gc.basic") { + using namespace gc::impl; + ScopedTemporaryDirectory TempDir; CidStoreConfiguration CasConfig; @@ -940,6 +942,8 @@ TEST_CASE("gc.basic") TEST_CASE("gc.full") { + using namespace gc::impl; + ScopedTemporaryDirectory TempDir; CidStoreConfiguration CasConfig; @@ -1140,6 +1144,8 @@ TEST_CASE("gc.full") TEST_CASE("gc.diskusagewindow") { + using namespace gc::impl; + DiskUsageWindow Stats; Stats.Append({.SampleTime = 0, .DiskUsage = 0}); // 0 0 Stats.Append({.SampleTime = 10, .DiskUsage = 10}); // 1 10 |