|
10 | 10 | #include <ydb/core/driver_lib/version/ut/ut_helpers.h> |
11 | 11 | #include <ydb/core/testlib/actors/test_runtime.h> |
12 | 12 |
|
| 13 | +#include <ydb/library/actors/interconnect/rdma/mem_pool.h> |
| 14 | + |
13 | 15 | #include <util/system/hp_timer.h> |
14 | 16 |
|
15 | 17 | namespace NKikimr { |
@@ -1562,9 +1564,10 @@ Y_UNIT_TEST_SUITE(TPDiskTest) { |
1562 | 1564 | return data; |
1563 | 1565 | } |
1564 | 1566 |
|
1565 | | - void ChunkWriteDifferentOffsetAndSizeImpl(bool plainDataChunks) { |
| 1567 | + void ChunkWriteDifferentOffsetAndSizeImpl(bool plainDataChunks, bool rdmaAlloc) { |
1566 | 1568 | TActorTestContext testCtx({ |
1567 | 1569 | .PlainDataChunks = plainDataChunks, |
| 1570 | + .UseRdmaAllocator = rdmaAlloc, |
1568 | 1571 | }); |
1569 | 1572 | Cerr << "plainDataChunks# " << plainDataChunks << Endl; |
1570 | 1573 |
|
@@ -1609,8 +1612,8 @@ Y_UNIT_TEST_SUITE(TPDiskTest) { |
1609 | 1612 | } |
1610 | 1613 | } |
1611 | 1614 | Y_UNIT_TEST(ChunkWriteDifferentOffsetAndSize) { |
1612 | | - for (int i = 0; i <= 1; ++i) { |
1613 | | - ChunkWriteDifferentOffsetAndSizeImpl(i); |
| 1615 | + for (ui32 i = 0; i <= 3; ++i) { |
| 1616 | + ChunkWriteDifferentOffsetAndSizeImpl(i & 1, i & 2); |
1614 | 1617 | } |
1615 | 1618 | } |
1616 | 1619 |
|
@@ -3033,4 +3036,86 @@ Y_UNIT_TEST_SUITE(TPDiskPrefailureDiskTest) { |
3033 | 3036 | } |
3034 | 3037 | } |
3035 | 3038 |
|
| 3039 | +Y_UNIT_TEST_SUITE(RDMA) { |
| 3040 | + void TestChunkReadWithRdmaAllocator(bool plainDataChunks) { |
| 3041 | + TActorTestContext testCtx({ |
| 3042 | + .PlainDataChunks = plainDataChunks, |
| 3043 | + .UseRdmaAllocator = true, |
| 3044 | + }); |
| 3045 | + TVDiskMock vdisk(&testCtx); |
| 3046 | + |
| 3047 | + vdisk.InitFull(); |
| 3048 | + vdisk.ReserveChunk(); |
| 3049 | + vdisk.CommitReservedChunks(); |
| 3050 | + auto chunk = *vdisk.Chunks[EChunkState::COMMITTED].begin(); |
| 3051 | + |
| 3052 | + for (i64 writeSize: {1_KB - 123, 64_KB, 128_KB + 8765}) { |
| 3053 | + for (i64 readOffset: {0_KB, 0_KB + 123, 4_KB, 8_KB + 123}) { |
| 3054 | + for (i64 readSize: {writeSize, writeSize - 567, writeSize - i64(8_KB), writeSize - i64(8_KB) + 987}) { |
| 3055 | + if (readOffset < 0 || readSize < 0 || readOffset + readSize > writeSize) { |
| 3056 | + continue; |
| 3057 | + } |
| 3058 | + Cerr << "chunkBufSize: " << writeSize << ", readOffset: " << readOffset << ", readSize: " << readSize << Endl; |
| 3059 | + auto parts = MakeIntrusive<NPDisk::TEvChunkWrite::TAlignedParts>(PrepareData(writeSize)); |
| 3060 | + testCtx.Send(new NPDisk::TEvChunkWrite( |
| 3061 | + vdisk.PDiskParams->Owner, vdisk.PDiskParams->OwnerRound, |
| 3062 | + chunk, 0, parts, nullptr, false, 0)); |
| 3063 | + auto write = testCtx.Recv<NPDisk::TEvChunkWriteResult>(); |
| 3064 | + |
| 3065 | + testCtx.Send(new NPDisk::TEvChunkRead( |
| 3066 | + vdisk.PDiskParams->Owner, vdisk.PDiskParams->OwnerRound, |
| 3067 | + chunk, readOffset, readSize, 0, nullptr)); |
| 3068 | + auto read = testCtx.Recv<NPDisk::TEvChunkReadResult>(); |
| 3069 | + TRcBuf readBuf = read->Data.ToString(); |
| 3070 | + NInterconnect::NRdma::TMemRegionSlice memReg = NInterconnect::NRdma::TryExtractFromRcBuf(readBuf); |
| 3071 | + UNIT_ASSERT_C(!memReg.Empty(), "Failed to extract RDMA memory region from RcBuf"); |
| 3072 | + UNIT_ASSERT_VALUES_EQUAL_C(memReg.GetSize(), readSize, "Unexpected size of RDMA memory region"); |
| 3073 | + } |
| 3074 | + } |
| 3075 | + } |
| 3076 | + } |
| 3077 | + |
| 3078 | + Y_UNIT_TEST(TestChunkReadWithRdmaAllocatorEncryptedChunks) { |
| 3079 | + TestChunkReadWithRdmaAllocator(false); |
| 3080 | + } |
| 3081 | + Y_UNIT_TEST(TestChunkReadWithRdmaAllocatorPlainChunks) { |
| 3082 | + TestChunkReadWithRdmaAllocator(true); |
| 3083 | + } |
| 3084 | + |
| 3085 | + Y_UNIT_TEST(TestRcBuf) { |
| 3086 | + ui32 size = 129961; |
| 3087 | + ui32 offset = 123; |
| 3088 | + ui32 tailRoom = 1111; |
| 3089 | + ui32 totalSize = size + tailRoom; |
| 3090 | + UNIT_ASSERT_VALUES_EQUAL(totalSize, 131072); |
| 3091 | + |
| 3092 | + auto alloc1 = [](ui32 size, ui32 headRoom, ui32 tailRoom) { |
| 3093 | + TRcBuf buf = TRcBuf::UninitializedPageAligned(size + headRoom + tailRoom); |
| 3094 | + buf.TrimFront(size + tailRoom); |
| 3095 | + buf.TrimBack(size); |
| 3096 | + Cerr << "alloc1: " << buf.Size() << " " << buf.Tailroom() << " " << buf.UnsafeTailroom() << Endl; |
| 3097 | + return buf; |
| 3098 | + }; |
| 3099 | + auto memPool = NInterconnect::NRdma::CreateDummyMemPool(); |
| 3100 | + auto alloc2 = [memPool](ui32 size, ui32 headRoom, ui32 tailRoom) -> TRcBuf { |
| 3101 | + TRcBuf buf = memPool->AllocRcBuf(size + headRoom + tailRoom, NInterconnect::NRdma::IMemPool::EMPTY).value(); |
| 3102 | + buf.TrimFront(size + tailRoom); |
| 3103 | + buf.TrimBack(size); |
| 3104 | + Cerr << "alloc2: " << buf.Size() << " " << buf.Tailroom() << " " << buf.UnsafeTailroom() << Endl; |
| 3105 | + return buf; |
| 3106 | + }; |
| 3107 | + |
| 3108 | + auto buf1 = TBufferWithGaps(offset, alloc1(size, 0, tailRoom)); |
| 3109 | + auto buf2 = TBufferWithGaps(offset, alloc2(size, 0, tailRoom)); |
| 3110 | + |
| 3111 | + Cerr << "buf1: " << buf1.PrintState() << " " << buf1.Size() << " " << buf1.SizeWithTail() << Endl; |
| 3112 | + Cerr << "buf2: " << buf2.PrintState() << " " << buf2.Size() << " " << buf2.SizeWithTail() << Endl; |
| 3113 | + |
| 3114 | + UNIT_ASSERT_VALUES_EQUAL_C(buf1.Size(), buf2.Size(), "Buffers should have the same size"); |
| 3115 | + |
| 3116 | + buf1.RawDataPtr(0, totalSize); |
| 3117 | + buf2.RawDataPtr(0, totalSize); |
| 3118 | + } |
| 3119 | +} |
| 3120 | + |
3036 | 3121 | } // namespace NKikimr |
0 commit comments