Skip to content

Commit

Permalink
RavenDB-4735 Fixing calculation of the number of entries in a fixed s…
Browse files Browse the repository at this point in the history
…ize tree. (#3978)
  • Loading branch information
arekpalinski authored and ayende committed Jul 9, 2016
1 parent c416c20 commit c7f6167
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions Raven.Voron/Voron/Trees/Fixed/FixedSizeTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,6 @@ public bool Add(long key, byte[] val)
isNew = false;
return page.Base + page.FixedSize_StartPosition + (page.LastSearchPosition * _entrySize) + sizeof(long);
}
var headerToWrite = (FixedSizeTreeHeader.Large*)_parent.DirectAdd(_treeName, sizeof(FixedSizeTreeHeader.Large));
headerToWrite->NumberOfEntries++;

if (page.LastMatch > 0)
page.LastSearchPosition++; // after the last one
Expand All @@ -148,6 +146,8 @@ public bool Add(long key, byte[] val)
return addLargeEntry;
}

var headerToWrite = (FixedSizeTreeHeader.Large*)_parent.DirectAdd(_treeName, sizeof(FixedSizeTreeHeader.Large));

ResetStartPosition(page);

var entriesToMove = page.FixedSize_NumberOfEntries - page.LastSearchPosition;
Expand All @@ -157,7 +157,10 @@ public bool Add(long key, byte[] val)
page.Base + page.FixedSize_StartPosition + (page.LastSearchPosition * _entrySize),
entriesToMove * _entrySize);
}

page.FixedSize_NumberOfEntries++;
headerToWrite->NumberOfEntries++;

isNew = true;
*((long*)(page.Base + page.FixedSize_StartPosition + (page.LastSearchPosition * _entrySize))) = key;
return (page.Base + page.FixedSize_StartPosition + (page.LastSearchPosition * _entrySize) + sizeof(long));
Expand Down Expand Up @@ -213,16 +216,15 @@ private Page FindPageFor(long key)

private Page PageSplit(Page page, long key)
{
var largePtr = (FixedSizeTreeHeader.Large*)_parent.DirectAdd(_treeName, sizeof(FixedSizeTreeHeader.Large));
Page parentPage = _cursor.Count > 0 ? _cursor.Pop() : null;
if (parentPage == null) // root split
{
parentPage = _parent.NewPage(PageFlags.Branch | PageFlags.FixedSize, 1);
parentPage.FixedSize_NumberOfEntries = 1;
parentPage.FixedSize_StartPosition = (ushort)Constants.PageHeaderSize;
parentPage.FixedSize_ValueSize = _valSize;

var largePtr =
(FixedSizeTreeHeader.Large*)_parent.DirectAdd(_treeName, sizeof(FixedSizeTreeHeader.Large));

largePtr->RootPageNumber = parentPage.PageNumber;
largePtr->Depth++;
var dataStart = GetSeparatorKeyAtPosition(parentPage);
Expand All @@ -245,6 +247,8 @@ private Page PageSplit(Page page, long key)
AddLeafKey(newPage, 0, key);

AddSeparatorToParentPage(parentPage, parentPage.LastSearchPosition + 1, key, newPage.PageNumber);

largePtr->NumberOfEntries++;
}
else // not at end, random inserts, split page 3/4 to 1/4
{
Expand Down

0 comments on commit c7f6167

Please sign in to comment.