diff --git a/src/Sparrow.Server/ByteString.cs b/src/Sparrow.Server/ByteString.cs index f7f274fb05f..0b6f884fbc0 100644 --- a/src/Sparrow.Server/ByteString.cs +++ b/src/Sparrow.Server/ByteString.cs @@ -671,6 +671,7 @@ public sealed class ByteStringContext : ByteStringContext public const int MaxAllocationBlockSizeInBytes = 256 * MinBlockSizeInBytes; public const int DefaultAllocationBlockSizeInBytes = 1 * MinBlockSizeInBytes; public const int MinReusableBlockSizeInBytes = 8; + public const int MaxAllocatedBlockSize = 2 * Sparrow.Global.Constants.Size.Megabyte; static unsafe ByteStringContext() { @@ -1040,7 +1041,7 @@ private ByteString AllocateExternal(byte* valuePtr, int size, ByteStringType typ { if (_externalCurrentLeft == 0) { - var tmp = Math.Min(2 * Sparrow.Global.Constants.Size.Megabyte, AllocationBlockSize * 2); + var tmp = Math.Min(ByteStringContext.MaxAllocatedBlockSize, AllocationBlockSize * 2); AllocateExternalSegment(tmp); AllocationBlockSize = tmp; } @@ -1184,7 +1185,7 @@ private ByteString AllocateInternalUnlikely(int length, int allocationUnit, Byte } else { - AllocationBlockSize = Math.Min(2 * Sparrow.Global.Constants.Size.Megabyte, AllocationBlockSize * 2); + AllocationBlockSize = Math.Min(ByteStringContext.MaxAllocatedBlockSize, AllocationBlockSize * 2); var toAllocate = Math.Max(AllocationBlockSize, allocationUnit); _internalCurrent = AllocateSegment(toAllocate); Debug.Assert(_internalCurrent.SizeLeft >= allocationUnit, $"{_internalCurrent.SizeLeft} >= {allocationUnit}"); diff --git a/test/FastTests/Sparrow/ByteStringTests.cs b/test/FastTests/Sparrow/ByteStringTests.cs index 0b3210d337d..d6f87338c2b 100644 --- a/test/FastTests/Sparrow/ByteStringTests.cs +++ b/test/FastTests/Sparrow/ByteStringTests.cs @@ -1,5 +1,4 @@ -using Sparrow.Global; -using Sparrow.Server; +using Sparrow.Server; using Sparrow.Threading; using Tests.Infrastructure; using Xunit; @@ -200,12 +199,12 @@ public void CanReuseMemory() { using (var context = new ByteStringContext(SharedMultipleUseFlag.None)) { - while (context.AllocationBlockSize != 2 * Constants.Size.Megabyte) + while (context.AllocationBlockSize != ByteStringContext.MaxAllocatedBlockSize) { context.Allocate(ByteStringContext.MinBlockSizeInBytes / 2, out _); } - Assert.Equal(2 * Constants.Size.Megabyte, context.AllocationBlockSize); + Assert.Equal(ByteStringContext.MaxAllocatedBlockSize, context.AllocationBlockSize); const int toAllocate = ByteStringContext.MinBlockSizeInBytes * 5; context.Allocate(toAllocate, out var first);