Skip to content

Commit

Permalink
RavenDB-22986 - fix the usages and add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
grisha-kotler committed Oct 14, 2024
1 parent 35351ea commit b732e8b
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/Voron/Impl/FreeSpace/FreeSpaceHandling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ public int GetFreePagesCount(LowLevelTransaction tx)
{
var stream = it.CreateReaderForCurrent();
var current = new StreamBitArray(stream);
count += current.GetNumberOfSetBits();
count += current.SetCount;

} while (it.MoveNext());

Expand Down
13 changes: 0 additions & 13 deletions src/Voron/Impl/FreeSpace/StreamBitArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Numerics;
using Sparrow.Server;

namespace Voron.Impl.FreeSpace
Expand Down Expand Up @@ -111,18 +110,6 @@ public bool Get(int index)
return (_inner[index >> 5] & (1 << (index & 31))) != 0;
}

public int GetNumberOfSetBits()
{
var count = 0;

for (int i = 0; i < _inner.Length; i++)
{
count += BitOperations.PopCount((uint)_inner[i]);
}

return count;
}

public void Set(int index, bool value)
{
if (value)
Expand Down
4 changes: 2 additions & 2 deletions src/Voron/StorageEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,7 @@ private long GetNumberOfAllocatedPages()
public StorageReport GenerateReport(Transaction tx)
{
var numberOfAllocatedPages = GetNumberOfAllocatedPages();
var numberOfFreePages = _freeSpaceHandling.AllPages(tx.LowLevelTransaction).Count;
var numberOfFreePages = _freeSpaceHandling.GetFreePagesCount(tx.LowLevelTransaction);

var countOfTrees = 0;
var countOfTables = 0;
Expand Down Expand Up @@ -1106,7 +1106,7 @@ public unsafe DetailedStorageReport GenerateDetailedReport(Transaction tx, bool
public unsafe DetailedReportInput CreateDetailedReportInput(Transaction tx, bool includeDetails)
{
var numberOfAllocatedPages = Math.Max(_dataPager.NumberOfAllocatedPages, NextPageNumber - 1); // async apply to data file task
var numberOfFreePages = _freeSpaceHandling.AllPages(tx.LowLevelTransaction).Count;
var numberOfFreePages = _freeSpaceHandling.GetFreePagesCount(tx.LowLevelTransaction);

var totalCryptoBufferSize = GetTotalCryptoBufferSize();

Expand Down
2 changes: 2 additions & 0 deletions test/FastTests/Voron/Trees/FreeSpaceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ public void CanGetListOfAllFreedPages(int maxPageNumber, int numberOfFreedPages,
using (var tx = Env.WriteTransaction())
{
var retrievedFreePages = Env.FreeSpaceHandling.AllPages(tx.LowLevelTransaction);
var freePagesCount = Env.FreeSpaceHandling.GetFreePagesCount(tx.LowLevelTransaction);
Assert.Equal(freePagesCount, retrievedFreePages.Count);

freedPages.ExceptWith(Env.FreeSpaceHandling.GetFreePagesOverheadPages(tx.LowLevelTransaction)); // need to take into account that some of free pages might be used for free space handling
var sorted = freedPages.OrderBy(x => x).ToList();
Expand Down

0 comments on commit b732e8b

Please sign in to comment.