Skip to content

Commit

Permalink
RavendB-22457 - Adding more free space tests, simplifying merging of …
Browse files Browse the repository at this point in the history
…free space across sections
  • Loading branch information
ayende committed Sep 26, 2024
1 parent a3d2933 commit 9bea94b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 31 deletions.
35 changes: 4 additions & 31 deletions src/Voron/Impl/FreeSpace/StreamBitArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,36 +212,9 @@ public int GetEndRangeCount()

public bool HasStartRangeCount(int max)
{
int count = 0;
for (int i = 0; i < CountOfItems; i += Vector256<int>.Count)
{
var a = Vector256.LoadUnsafe(ref _inner[i]);
var eq = Vector256.Equals(a, Vector256<uint>.AllBitsSet);
if (eq == Vector256<uint>.AllBitsSet)
{
count += 256;
if (count >= max)
return true;

continue;
}
for (int j = i; j < i + Vector256<uint>.Count; j--)
{
if (_inner[j] == uint.MaxValue)
{
count += 32;
if (count >= max)
return true;

continue;
}

count += BitOperations.TrailingZeroCount(~_inner[j]);
break;
}
break;
}

return count >= max;
Debug.Assert(max <= 2048, "max <= 2048 - maximum range inside the bit array");

var next = NextUnsetBits(0);
return next == -1 || next >= max;
}
}
24 changes: 24 additions & 0 deletions test/FastTests/Voron/Trees/FreeSpaceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,30 @@ public void FindConsecutiveRange2()
}
}

[RavenFact(RavenTestCategory.Voron)]
public void FindConsecutiveRange_AcrossSections()
{
using (var tx = Env.WriteTransaction())
{
for (int i = 0; i < 48; i++)
{
Env.FreeSpaceHandling.FreePage(tx.LowLevelTransaction, 250 + i);
}

for (int i = 0; i < 50; i++)
{
Env.FreeSpaceHandling.FreePage(tx.LowLevelTransaction, 2040 + i);
}


tx.Commit();
}

using (var tx = Env.WriteTransaction())
{
Assert.Equal(2040 , Env.FreeSpaceHandling.TryAllocateFromFreeSpace(tx.LowLevelTransaction, 50));
}
}

[RavenTheory(RavenTestCategory.Voron)]
[InlineData(400, 10, 3)]
Expand Down

0 comments on commit 9bea94b

Please sign in to comment.