private void MoveBranchNode(Page parentPage, Page from, Page to) { Debug.Assert(from.IsBranch); var originalFromKeyStart = GetActualKey(from, from.LastSearchPositionOrLastEntry); var fromNode = from.GetNode(from.LastSearchPosition); long pageNum = fromNode->PageNumber; var itemsMoved = _tx.Pager.Get(_tx, pageNum).ItemCount; from.ItemCount -= itemsMoved; to.ItemCount += itemsMoved; if (to.LastSearchPosition == 0) { // cannot add to left implicit side, adjust by moving the left node // to the right by one, then adding the new one as the left var implicitLeftKey = GetActualKey(to, 0); var leftPageNumber = to.GetNode(0)->PageNumber; to.AddNode(1, implicitLeftKey, -1, leftPageNumber); to.AddNode(0, Slice.BeforeAllKeys, -1, pageNum); to.RemoveNode(1); } else { to.AddNode(to.LastSearchPosition, originalFromKeyStart, -1, pageNum); } if (from.LastSearchPositionOrLastEntry == 0) { // cannot just remove the left node, need to adjust those var rightPageNumber = from.GetNode(1)->PageNumber; from.RemoveNode(0); // remove the original node from.RemoveNode(0); // remove the next node from.AddNode(0, Slice.BeforeAllKeys, -1, rightPageNumber); Debug.Assert(from.NumberOfEntries >= 2); } else { from.RemoveNode(from.LastSearchPositionOrLastEntry); } var pos = parentPage.LastSearchPositionOrLastEntry; parentPage.RemoveNode(pos); var newKey = GetActualKey(to, 0); // get the next smallest key it has now var pageNumber = to.PageNumber; if (parentPage.GetNode(0)->PageNumber == to.PageNumber) { pageNumber = from.PageNumber; newKey = GetActualKey(from, 0); } parentPage.AddNode(pos, newKey, -1, pageNumber); }
private void MoveLeafNode(Page parentPage, Page from, Page to) { Debug.Assert(from.IsBranch == false); var originalFromKeyStart = GetActualKey(from, from.LastSearchPositionOrLastEntry); var fromNode = from.GetNode(from.LastSearchPosition); byte *val = @from.Base + @from.KeysOffsets[@from.LastSearchPosition] + Constants.NodeHeaderSize + originalFromKeyStart.Size; var dataPos = to.AddNode(to.LastSearchPosition, originalFromKeyStart, fromNode->DataSize, -1); NativeMethods.memcpy(dataPos, val, fromNode->DataSize); [email protected]; ++to.ItemCount; from.RemoveNode(from.LastSearchPositionOrLastEntry); var pos = parentPage.LastSearchPositionOrLastEntry; parentPage.RemoveNode(pos); var newKey = GetActualKey(to, 0); // get the next smallest key it has now var pageNumber = to.PageNumber; if (parentPage.GetNode(0)->PageNumber == to.PageNumber) { pageNumber = from.PageNumber; newKey = GetActualKey(from, 0); } parentPage.AddNode(pos, newKey, -1, pageNumber); }
private byte *InsertNewKey(Page p) { var pos = p.NodePositionFor(_newKey, _cmp); var dataPos = p.AddNode(pos, _newKey, _len, _pageNumber); _cursor.Push(p); IncrementItemCountIfNecessary(); return(dataPos); }
private void AddSeperatorToParentPage(Page rightPage, Slice seperatorKey) { if (_parentPage.SizeLeft < SizeOf.BranchEntry(seperatorKey) + Constants.NodeOffsetSize) { new PageSplitter(_tx, _cmp, seperatorKey, -1, rightPage.PageNumber, _cursor, _txInfo).Execute(); } else { _parentPage.NodePositionFor(seperatorKey, _cmp); // select the appropriate place for this _parentPage.AddNode(_parentPage.LastSearchPosition, seperatorKey, -1, rightPage.PageNumber); } }