/// <summary> /// Attempts to ensure that the minimum size for this node is achieved by transferring entries from the left-hand sibling /// </summary> /// <param name="txnId"></param> /// <param name="leftSibling">The left-hand sibling that will provide entries</param> /// <param name="joinKey">The value of the key that is present in the parent node between the pointer to this node and its left sibling</param> /// <param name="newJoinKey">The replacement value for the join key in the parent node</param> /// <returns>True if the node achieves its minimum size by the redistribution process, false otherwise</returns> public bool RedistributeFromLeft(ulong txnId, IInternalNode leftSibling, byte[] joinKey, byte[] newJoinKey) { InternalNode left = leftSibling as InternalNode; if (left == null) { throw new ArgumentException("Expected a InternalNode as left sibling", "leftSibling"); } int required = _config.InternalSplitIndex - KeyCount; if (leftSibling.KeyCount - required < _config.InternalSplitIndex) { // Can't fulfill requirements with a borrow from left sibling return(false); } int evenOut = (KeyCount + left.KeyCount) / 2 - KeyCount; if (leftSibling.KeyCount - evenOut > _config.InternalSplitIndex) { required = evenOut; } EnsureWriteable(txnId); left.EnsureWriteable(txnId); // Make space for new keys and child pointers RightShift(required); _page.SetData(joinKey, 0, KeyOffset(required - 1), _config.KeySize); _page.SetData(left.GetData(), KeyOffset(left.KeyCount - (required - 1)), KeyOffset(0), (required - 1) * _config.KeySize); _page.SetData(left.GetData(), PointerOffset(left.KeyCount - (required - 1)), PointerOffset(0), (required) * 8); Array.Copy(left.GetData(), KeyOffset(left.KeyCount - required), newJoinKey, 0, _config.KeySize); KeyCount += required; left.KeyCount -= required; return(true); }
private KeyValuePair <byte[], ulong> WriteNode(ulong txnId, InternalNode node, byte[] lowestLeafKey, BrightstarProfiler profiler) { _pageStore.Write(txnId, node.PageId, node.GetData(), profiler: profiler); return(new KeyValuePair <byte[], ulong>(lowestLeafKey, node.PageId)); }
private KeyValuePair<byte[], ulong > WriteNode(ulong txnId, InternalNode node, byte[] lowestLeafKey, BrightstarProfiler profiler) { _pageStore.Write(txnId, node.PageId, node.GetData(), profiler:profiler); return new KeyValuePair<byte[], ulong>(lowestLeafKey, node.PageId); }