diff options
| author | Dan Engelbrecht <[email protected]> | 2023-11-06 15:55:39 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-11-06 15:55:39 +0100 |
| commit | 5295c9618cbae2bb937e188c072f66a77d793eb5 (patch) | |
| tree | 6aeca701b20af5745eb7924c901c9708c098199b /src/zenserver/cache/structuredcachestore.cpp | |
| parent | statsd for cas (#511) (diff) | |
| download | zen-5295c9618cbae2bb937e188c072f66a77d793eb5.tar.xz zen-5295c9618cbae2bb937e188c072f66a77d793eb5.zip | |
gc v2 tests (#512)
* set MaxBlockCount at init
* properly calculate total size
* basic blockstore compact blocks test
* correct detection of block swap
* Use one implementation for CreateRandomBlob
* reduce some data sets to increase speed of tests
* reduce test time
* rename BlockStoreCompactState::AddBlock -> BlockStoreCompactState::IncludeBlock
Diffstat (limited to 'src/zenserver/cache/structuredcachestore.cpp')
| -rw-r--r-- | src/zenserver/cache/structuredcachestore.cpp | 62 |
1 files changed, 9 insertions, 53 deletions
diff --git a/src/zenserver/cache/structuredcachestore.cpp b/src/zenserver/cache/structuredcachestore.cpp index 09c9f1468..db6156ea1 100644 --- a/src/zenserver/cache/structuredcachestore.cpp +++ b/src/zenserver/cache/structuredcachestore.cpp @@ -774,24 +774,6 @@ using namespace std::literals; namespace testutils { IoHash CreateKey(size_t KeyValue) { return IoHash::HashBuffer(&KeyValue, sizeof(size_t)); } - IoBuffer CreateBinaryCacheValue(uint64_t Size) - { - static std::random_device rd; - static std::mt19937 g(rd()); - - std::vector<uint8_t> Values; - Values.resize(Size); - for (size_t Idx = 0; Idx < Size; ++Idx) - { - Values[Idx] = static_cast<uint8_t>(Idx); - } - std::shuffle(Values.begin(), Values.end(), g); - - IoBuffer Buf(IoBuffer::Clone, Values.data(), Values.size()); - Buf.SetContentType(ZenContentType::kBinary); - return Buf; - }; - IoHash ToIoHash(const Oid& Id) { char OIdString[24 + 1]; @@ -800,33 +782,7 @@ namespace testutils { return Key; } - std::pair<Oid, IoBuffer> CreateBinaryBlob(size_t Size) - { - uint64_t seed{Size}; - auto next = [](uint64_t& seed) { - uint64_t z = (seed += UINT64_C(0x9E3779B97F4A7C15)); - z = (z ^ (z >> 30)) * UINT64_C(0xBF58476D1CE4E5B9); - z = (z ^ (z >> 27)) * UINT64_C(0x94D049BB133111EB); - return z ^ (z >> 31); - }; - - IoBuffer Data(Size); - uint64_t* DataPtr = reinterpret_cast<uint64_t*>(Data.MutableData()); - while (Size > sizeof(uint64_t)) - { - *DataPtr++ = next(seed); - Size -= sizeof(uint64_t); - } - uint64_t ByteNext = next(seed); - uint8_t* ByteDataPtr = reinterpret_cast<uint8_t*>(DataPtr); - while (Size > 0) - { - *ByteDataPtr++ = static_cast<uint8_t>(ByteNext & 0xff); - ByteNext >>= 8; - Size--; - } - return {Oid::NewOid(), Data}; - } + std::pair<Oid, IoBuffer> CreateBinaryBlob(size_t Size) { return {Oid::NewOid(), CreateRandomBlob(Size)}; } std::vector<std::pair<Oid, CompressedBuffer>> CreateCompressedAttachment(CidStore& Store, const std::span<const size_t>& Sizes) { @@ -1105,7 +1061,7 @@ TEST_CASE("z$.gc") for (const auto& Key : Keys) { - IoBuffer Value = testutils::CreateBinaryCacheValue(128 << 10); + IoBuffer Value = CreateRandomBlob(128 << 10); Zcs.Put(Bucket, Key, {.Value = Value}, {}); } @@ -1153,7 +1109,7 @@ TEST_CASE("z$.gc") for (const auto& Key : Keys) { - IoBuffer Value = testutils::CreateBinaryCacheValue(128); + IoBuffer Value = CreateRandomBlob(128); Zcs.Put(Bucket, Key, {.Value = Value}, {}); } @@ -1224,7 +1180,7 @@ TEST_CASE("z$.threadedinsert") // * doctest::skip(true)) { while (true) { - IoBuffer Chunk = testutils::CreateBinaryCacheValue(kChunkSize); + IoBuffer Chunk = CreateRandomBlob(kChunkSize); IoHash Hash = HashBuffer(Chunk); if (Chunks.contains(Hash)) { @@ -1235,7 +1191,7 @@ TEST_CASE("z$.threadedinsert") // * doctest::skip(true)) } while (true) { - IoBuffer Chunk = testutils::CreateBinaryCacheValue(kChunkSize); + IoBuffer Chunk = CreateRandomBlob(kChunkSize); IoHash Hash = HashBuffer(Chunk); if (Chunks.contains(Hash)) { @@ -1303,12 +1259,12 @@ TEST_CASE("z$.threadedinsert") // * doctest::skip(true)) for (int32_t Idx = 0; Idx < kChunkCount; ++Idx) { { - IoBuffer Chunk = testutils::CreateBinaryCacheValue(kChunkSize); + IoBuffer Chunk = CreateRandomBlob(kChunkSize); IoHash Hash = HashBuffer(Chunk); NewChunks[Hash] = {.Bucket = Bucket1, .Buffer = Chunk}; } { - IoBuffer Chunk = testutils::CreateBinaryCacheValue(kChunkSize); + IoBuffer Chunk = CreateRandomBlob(kChunkSize); IoHash Hash = HashBuffer(Chunk); NewChunks[Hash] = {.Bucket = Bucket2, .Buffer = Chunk}; } @@ -1759,7 +1715,7 @@ TEST_CASE("z$.scrub") Record.EndObject(); for (size_t Index = 0; Index < AttachmentSizes.size(); Index++) { - IoBuffer AttachmentData = CreateBinaryCacheValue(AttachmentSizes[Index]); + IoBuffer AttachmentData = CreateRandomBlob(AttachmentSizes[Index]); CompressedBuffer CompressedAttachmentData = CompressedBuffer::Compress(SharedBuffer(AttachmentData)); Record.AddBinaryAttachment(fmt::format("attachment-{}", Index), CompressedAttachmentData.DecodeRawHash()); Result.Attachments[Index] = CompressedAttachmentData; @@ -1781,7 +1737,7 @@ TEST_CASE("z$.scrub") DataPtr += RecordData.length() + 1; for (size_t AttachmentSize : AttachmentSizes) { - IoBuffer AttachmentData = CreateBinaryCacheValue(AttachmentSize); + IoBuffer AttachmentData = CreateRandomBlob(AttachmentSize); memcpy(DataPtr, AttachmentData.GetData(), AttachmentData.GetSize()); DataPtr += AttachmentData.GetSize(); } |