本文整理汇总了C#中Voron.Trees.Page类的典型用法代码示例。如果您正苦于以下问题:C# Page类的具体用法?C# Page怎么用?C# Page使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Page类属于Voron.Trees命名空间,在下文中一共展示了Page类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Write
public override int Write(Page page, long? pageNumber)
{
var toWrite = page.IsOverflow ? GetNumberOfOverflowPages(page.OverflowSize) : 1;
var requestedPageNumber = pageNumber ?? page.PageNumber;
return WriteDirect(page, requestedPageNumber, toWrite);
}
示例2: DumpHumanReadable
public static void DumpHumanReadable(Transaction tx, string path, Page start)
{
using (var writer = File.CreateText(path))
{
var stack = new Stack<Page>();
stack.Push(start);
writer.WriteLine("Root page #{0}",start.PageNumber);
while (stack.Count > 0)
{
var currentPage = stack.Pop();
if (currentPage.IsLeaf)
{
writer.WriteLine();
writer.WriteLine("Page #{0}, NumberOfEntries = {1}, Flags = {2} (Leaf), Used: {3} : {4}", currentPage.PageNumber,currentPage.NumberOfEntries,currentPage.Flags, currentPage.SizeUsed, currentPage.CalcSizeUsed());
if(currentPage.NumberOfEntries <= 0)
writer.WriteLine("Empty page (tree corrupted?)");
for (int nodeIndex = 0; nodeIndex < currentPage.NumberOfEntries;nodeIndex++)
{
var node = currentPage.GetNode(nodeIndex);
var key = currentPage.GetNodeKey(node);
writer.WriteLine("Node #{0}, Flags = {1}, {4} = {2}, Key = {3}, Entry Size: {5}", nodeIndex, node->Flags, node->DataSize, MaxString(key.ToString(), 25), node->Flags == NodeFlags.Data ? "Size" : "Page",
SizeOf.NodeEntry(node));
}
writer.WriteLine();
}
else if(currentPage.IsBranch)
{
writer.WriteLine();
writer.WriteLine("Page #{0}, NumberOfEntries = {1}, Flags = {2} (Branch), Used: {3} : {4}", currentPage.PageNumber, currentPage.NumberOfEntries, currentPage.Flags, currentPage.SizeUsed, currentPage.SizeUsed);
var key = new Slice(SliceOptions.Key);
for (int nodeIndex = 0; nodeIndex < currentPage.NumberOfEntries; nodeIndex++)
{
var node = currentPage.GetNode(nodeIndex);
writer.WriteLine("Node #{2}, {0} / to page #{1}, Entry Size: {3}", GetBranchNodeString(nodeIndex, key, currentPage, node), node->PageNumber, nodeIndex,
SizeOf.NodeEntry(node));
}
for (int nodeIndex = 0; nodeIndex < currentPage.NumberOfEntries; nodeIndex++)
{
var node = currentPage.GetNode(nodeIndex);
if (node->PageNumber < 0 || node->PageNumber > tx.State.NextPageNumber)
{
writer.Write("Found invalid reference to page #{0}", currentPage.PageNumber);
stack.Clear();
break;
}
var child = tx.GetReadOnlyPage(node->PageNumber);
stack.Push(child);
}
writer.WriteLine();
}
}
}
}
示例3: PageSplitter
public PageSplitter(Transaction tx,
Tree tree,
SliceComparer cmp,
Slice newKey,
int len,
long pageNumber,
NodeFlags nodeType,
ushort nodeVersion,
Cursor cursor,
TreeMutableState treeState)
{
_tx = tx;
_tree = tree;
_cmp = cmp;
_newKey = newKey;
_len = len;
_pageNumber = pageNumber;
_nodeType = nodeType;
_nodeVersion = nodeVersion;
_cursor = cursor;
_treeState = treeState;
Page page = _cursor.Pages.First.Value;
_page = tx.ModifyPage(page.PageNumber, page);
_cursor.Pop();
}
示例4: Execute
public byte* Execute()
{
Page rightPage = Tree.NewPage(_tx, _page.Flags, 1);
_treeState.RecordNewPage(_page, 1);
rightPage.Flags = _page.Flags;
if (_cursor.PageCount == 0) // we need to do a root split
{
Page newRootPage = Tree.NewPage(_tx, PageFlags.Branch, 1);
_cursor.Push(newRootPage);
_treeState.RootPageNumber = newRootPage.PageNumber;
_treeState.Depth++;
_treeState.RecordNewPage(newRootPage, 1);
// now add implicit left page
newRootPage.AddPageRefNode(0, Slice.BeforeAllKeys, _page.PageNumber);
_parentPage = newRootPage;
_parentPage.LastSearchPosition++;
}
else
{
// we already popped the page, so the current one on the stack is what the parent of the page
_parentPage = _tx.ModifyPage(_cursor.CurrentPage.PageNumber, _cursor.CurrentPage);
_cursor.Update(_cursor.Pages.First, _parentPage);
}
if (_page.IsLeaf)
{
_tx.ClearRecentFoundPages(_tree);
}
if (_page.LastSearchPosition >= _page.NumberOfEntries)
{
// when we get a split at the end of the page, we take that as a hint that the user is doing
// sequential inserts, at that point, we are going to keep the current page as is and create a new
// page, this will allow us to do minimal amount of work to get the best density
byte* pos;
if (_page.IsBranch)
{
// here we steal the last entry from the current page so we maintain the implicit null left entry
NodeHeader* node = _page.GetNode(_page.NumberOfEntries - 1);
Debug.Assert(node->Flags == NodeFlags.PageRef);
rightPage.AddPageRefNode(0, Slice.Empty, node->PageNumber);
pos = AddNodeToPage(rightPage, 1);
AddSeparatorToParentPage(rightPage, new Slice(node));
_page.RemoveNode(_page.NumberOfEntries - 1);
}
else
{
AddSeparatorToParentPage(rightPage, _newKey);
pos = AddNodeToPage(rightPage, 0);
}
_cursor.Push(rightPage);
return pos;
}
return SplitPageInHalf(rightPage);
}
示例5: AddSeparator
public byte* AddSeparator(MemorySlice separator, long pageRefNumber, int? nodePos = null)
{
var originalLastSearchPositionOfParent = _parentPage.LastSearchPosition;
if (nodePos == null)
nodePos = _parentPage.NodePositionFor(separator); // select the appropriate place for this
var separatorKeyToInsert = _parentPage.PrepareKeyToInsert(separator, nodePos.Value);
if (_parentPage.HasSpaceFor(_tx, SizeOf.BranchEntry(separatorKeyToInsert) + Constants.NodeOffsetSize + SizeOf.NewPrefix(separatorKeyToInsert)) == false)
{
var pageSplitter = new PageSplitter(_tx, _tree, separator, -1, pageRefNumber, NodeFlags.PageRef, 0, _cursor, _tree.State);
var posToInsert = pageSplitter.Execute();
ParentOfAddedPageRef = _cursor.CurrentPage;
var adjustParentPageOnCursor = true;
for (int i = 0; i < _cursor.CurrentPage.NumberOfEntries; i++)
{
if (_cursor.CurrentPage.GetNode(i)->PageNumber == _currentPage.PageNumber)
{
adjustParentPageOnCursor = false;
_cursor.CurrentPage.LastSearchPosition = i;
break;
}
}
if (adjustParentPageOnCursor)
{
// the above page split has modified the cursor that its first page points to the parent of the leaf where 'separatorKey' was inserted
// and it doesn't have the reference to _page, we need to ensure that the actual parent is first at the cursor
_cursor.Pop();
_cursor.Push(_parentPage);
EnsureValidLastSearchPosition(_parentPage, _currentPage.PageNumber, originalLastSearchPositionOfParent);
}
#if VALIDATE
Debug.Assert(_cursor.CurrentPage.GetNode(_cursor.CurrentPage.LastSearchPosition)->PageNumber == _currentPage.PageNumber,
"The parent page is not referencing a page which is being split");
var parentToValidate = ParentOfAddedPageRef;
Debug.Assert(Enumerable.Range(0, parentToValidate.NumberOfEntries).Any(i => parentToValidate.GetNode(i)->PageNumber == pageRefNumber),
"The parent page of a page reference isn't referencing it");
#endif
return posToInsert;
}
ParentOfAddedPageRef = _parentPage;
var pos = _parentPage.AddPageRefNode(nodePos.Value, separatorKeyToInsert, pageRefNumber);
EnsureValidLastSearchPosition(_parentPage, _currentPage.PageNumber, originalLastSearchPositionOfParent);
return pos;
}
示例6: FoundPage
public FoundPage(long number, Page page, MemorySlice firstKey, MemorySlice lastKey, long[] cursorPath)
{
Number = number;
Page = page;
FirstKey = firstKey;
LastKey = lastKey;
CursorPath = cursorPath;
}
示例7: ParentPageAction
public ParentPageAction(Page parentPage, Page currentPage, Tree tree, Cursor cursor, Transaction tx)
{
_parentPage = parentPage;
_currentPage = currentPage;
_tree = tree;
_cursor = cursor;
_tx = tx;
}
示例8: Write
public override int Write(Page page, long? pageNumber)
{
long startPage = pageNumber ?? page.PageNumber;
//note: GetNumberOfOverflowPages and WriteDirect can throw ObjectDisposedException if the pager is already disposed
int toWrite = page.IsOverflow ? GetNumberOfOverflowPages(page.OverflowSize) : 1;
return WriteDirect(page, startPage, toWrite);
}
示例9: HasDuplicateBranchReferences
public static unsafe bool HasDuplicateBranchReferences(Transaction tx, Page start,out long pageNumberWithDuplicates)
{
var stack = new Stack<Page>();
var existingTreeReferences = new ConcurrentDictionary<long, List<long>>();
stack.Push(start);
while (stack.Count > 0)
{
var currentPage = stack.Pop();
if (currentPage.IsBranch)
{
for (int nodeIndex = 0; nodeIndex < currentPage.NumberOfEntries; nodeIndex++)
{
var node = currentPage.GetNode(nodeIndex);
existingTreeReferences.AddOrUpdate(currentPage.PageNumber, new List<long> { node->PageNumber },
(branchPageNumber, pageNumberReferences) =>
{
pageNumberReferences.Add(node->PageNumber);
return pageNumberReferences;
});
}
for (int nodeIndex = 0; nodeIndex < currentPage.NumberOfEntries; nodeIndex++)
{
var node = currentPage.GetNode(nodeIndex);
if (node->PageNumber < 0 || node->PageNumber > tx.State.NextPageNumber)
{
throw new InvalidDataException("found invalid reference on branch - tree is corrupted");
}
var child = tx.GetReadOnlyPage(node->PageNumber);
stack.Push(child);
}
}
}
Func<long, HashSet<long>> relevantPageReferences =
branchPageNumber => new HashSet<long>(existingTreeReferences
.Where(kvp => kvp.Key != branchPageNumber)
.SelectMany(kvp => kvp.Value));
// ReSharper disable once LoopCanBeConvertedToQuery
foreach (var branchReferences in existingTreeReferences)
{
if (
branchReferences.Value.Any(
referencePageNumber => relevantPageReferences(branchReferences.Key).Contains(referencePageNumber)))
{
pageNumberWithDuplicates = branchReferences.Key;
return true;
}
}
pageNumberWithDuplicates = -1;
return false;
}
示例10: Seek
public bool Seek(Slice key)
{
Lazy<Cursor> lazy;
_currentPage = _tree.FindPageFor(_tx, key, out lazy);
_cursor = lazy.Value;
_cursor.Pop();
var node = _currentPage.Search(key, _cmp);
if (node == null)
{
return false;
}
_currentKey.Set(node);
return this.ValidateCurrentKey(Current, _cmp);
}
示例11: RecordNewPage
public void RecordNewPage(Page p, int num)
{
PageCount++;
var flags = p.Flags;
if ((flags & PageFlags.Branch) == PageFlags.Branch)
{
BranchPages++;
}
else if ((flags & PageFlags.Leaf) == PageFlags.Leaf)
{
LeafPages++;
}
else if ((flags & PageFlags.Overflow) == PageFlags.Overflow)
{
OverflowPages += num;
}
}
示例12: RecordNewPage
public void RecordNewPage(Page p, int num)
{
PageCount += num;
if (p.IsBranch)
{
BranchPages++;
}
else if (p.IsLeaf)
{
LeafPages++;
}
else if (p.IsOverflow)
{
OverflowPages += num;
}
}
示例13: Update
public void Update(LinkedListNode<Page> node, Page newVal)
{
var oldPageNumber = node.Value.PageNumber;
var newPageNumber = newVal.PageNumber;
if (oldPageNumber == newPageNumber)
{
_pagesByNum[oldPageNumber] = newVal;
node.Value = newVal;
return;
}
_anyOverrides = true;
_pagesByNum[oldPageNumber] = newVal;
_pagesByNum.Add(newPageNumber, newVal);
node.Value = newVal;
}
示例14: Seek
public bool Seek(Slice key)
{
Lazy<Cursor> lazy;
_currentPage = _tree.FindPageFor(key, out lazy);
_cursor = lazy.Value;
_cursor.Pop();
var node = _currentPage.Search(key);
if (node != null)
{
_currentKey.Set(node);
return this.ValidateCurrentKey(Current);
}
// The key is not found in the db, but we are Seek()ing for equals or starts with.
// We know that the exact value isn't there, but it is possible that the next page has values
// that is actually greater than the key, so we need to check it as well.
_currentPage.LastSearchPosition = _currentPage.NumberOfEntries; // force next MoveNext to move to the next _page_.
return MoveNext();
}
示例15: RecordFreedPage
public void RecordFreedPage(Page p, int num)
{
PageCount -= num;
Debug.Assert(PageCount >= 0);
if (p.IsBranch)
{
BranchPages--;
Debug.Assert(BranchPages >= 0);
}
else if (p.IsLeaf)
{
LeafPages--;
Debug.Assert(LeafPages >= 0);
}
else if (p.IsOverflow)
{
OverflowPages -= num;
Debug.Assert(OverflowPages >= 0);
}
}