本文整理汇总了C#中Voron.Impl.Transaction.GetReadOnlyPage方法的典型用法代码示例。如果您正苦于以下问题:C# Transaction.GetReadOnlyPage方法的具体用法?C# Transaction.GetReadOnlyPage怎么用?C# Transaction.GetReadOnlyPage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Voron.Impl.Transaction
的用法示例。
在下文中一共展示了Transaction.GetReadOnlyPage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DumpHumanReadable
public static void DumpHumanReadable(Transaction tx, long startPageNumber,string filenamePrefix = null)
{
if (Debugger.IsAttached == false)
return;
var path = Path.Combine(Environment.CurrentDirectory, String.Format("{0}tree.hdump", filenamePrefix ?? String.Empty));
TreeDumper.DumpHumanReadable(tx, path, tx.GetReadOnlyPage(startPageNumber));
}
示例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: GetDataSize
public static int GetDataSize(Transaction tx, NodeHeader* node)
{
if (node->Flags == (NodeFlags.PageRef))
{
var overFlowPage = tx.GetReadOnlyPage(node->PageNumber);
return overFlowPage.OverflowSize;
}
return node->DataSize;
}
示例4: Reader
public unsafe static ValueReader Reader(Transaction tx, NodeHeader* node)
{
if (node->Flags == (NodeFlags.PageRef))
{
var overFlowPage = tx.GetReadOnlyPage(node->PageNumber);
return new ValueReader(overFlowPage.Base + Constants.PageHeaderSize, overFlowPage.OverflowSize);
}
return new ValueReader((byte*)node + node->KeySize + Constants.NodeHeaderSize, node->DataSize);
}
示例5: DirectAccess
public static byte* DirectAccess(Transaction tx, NodeHeader* node)
{
if (node->Flags == (NodeFlags.PageRef))
{
var overFlowPage = tx.GetReadOnlyPage(node->PageNumber);
return overFlowPage.Base + Constants.PageHeaderSize;
}
return (byte*) node + node->KeySize + Constants.NodeHeaderSize;
}
示例6: CopyTo
public static void CopyTo(Transaction tx, NodeHeader* node, byte* dest)
{
if (node->Flags == (NodeFlags.PageRef))
{
var overFlowPage = tx.GetReadOnlyPage(node->PageNumber);
Memory.Copy(dest, overFlowPage.Base + Constants.PageHeaderSize, overFlowPage.OverflowSize);
}
Memory.Copy(dest, (byte*)node + node->KeySize + Constants.NodeHeaderSize, node->DataSize);
}
示例7: 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;
}
示例8: GetData
public static Slice GetData(Transaction tx, NodeHeader* node)
{
if (node->Flags == (NodeFlags.PageRef))
{
var overFlowPage = tx.GetReadOnlyPage(node->PageNumber);
if (overFlowPage.OverflowSize > ushort.MaxValue)
throw new InvalidOperationException("Cannot convert big data to a slice, too big");
return new Slice(overFlowPage.Base + Constants.PageHeaderSize, (ushort)overFlowPage.OverflowSize);
}
return new Slice((byte*)node + node->KeySize + Constants.NodeHeaderSize, (ushort) node->DataSize);
}
示例9: Reader
public static ValueReader Reader(Transaction tx, NodeHeader* node)
{
if (node->Flags == (NodeFlags.PageRef))
{
var overFlowPage = tx.GetReadOnlyPage(node->PageNumber);
Debug.Assert(overFlowPage.IsOverflow, "Requested oveflow page but got " + overFlowPage.Flags);
Debug.Assert(overFlowPage.OverflowSize > 0, "Overflow page cannot be size equal 0 bytes");
return new ValueReader(overFlowPage.Base + Constants.PageHeaderSize, overFlowPage.OverflowSize);
}
return new ValueReader((byte*)node + node->KeySize + Constants.NodeHeaderSize, node->DataSize);
}
示例10: DebugValidateTree
public void DebugValidateTree(Transaction tx, long rootPageNumber)
{
var pages = new HashSet<long>();
var stack = new Stack<Page>();
var root = tx.GetReadOnlyPage(rootPageNumber);
stack.Push(root);
pages.Add(rootPageNumber);
while (stack.Count > 0)
{
var p = stack.Pop();
if (p.NumberOfEntries == 0 && p != root)
{
DebugStuff.RenderAndShow(tx, rootPageNumber, 1);
throw new InvalidOperationException("The page " + p.PageNumber + " is empty");
}
p.DebugValidate(tx, _cmp, rootPageNumber);
if (p.IsBranch == false)
continue;
for (int i = 0; i < p.NumberOfEntries; i++)
{
var page = p.GetNode(i)->PageNumber;
if (pages.Add(page) == false)
{
DebugStuff.RenderAndShow(tx, rootPageNumber, 1);
throw new InvalidOperationException("The page " + page + " already appeared in the tree!");
}
stack.Push(tx.GetReadOnlyPage(page));
}
}
}
示例11: TryOverwriteOverflowPages
private bool TryOverwriteOverflowPages(Transaction tx, TreeMutableState treeState, NodeHeader* updatedNode,
Slice key, int len, ushort? version, out byte* pos)
{
if (updatedNode->Flags == NodeFlags.PageRef &&
tx.Id <= tx.Environment.OldestTransaction) // ensure MVCC - do not overwrite if there is some older active transaction that might read those overflows
{
var overflowPage = tx.GetReadOnlyPage(updatedNode->PageNumber);
if (len <= overflowPage.OverflowSize)
{
CheckConcurrency(key, version, updatedNode->Version, TreeActionType.Add);
if (updatedNode->Version == ushort.MaxValue)
updatedNode->Version = 0;
updatedNode->Version++;
var availableOverflows = tx.DataPager.GetNumberOfOverflowPages(overflowPage.OverflowSize);
var requestedOverflows = tx.DataPager.GetNumberOfOverflowPages(len);
var overflowsToFree = availableOverflows - requestedOverflows;
for (int i = 0; i < overflowsToFree; i++)
{
tx.FreePage(overflowPage.PageNumber + requestedOverflows + i);
}
treeState.OverflowPages -= overflowsToFree;
treeState.PageCount -= overflowsToFree;
overflowPage.OverflowSize = len;
pos = overflowPage.Base + Constants.PageHeaderSize;
return true;
}
}
pos = null;
return false;
}
示例12: AllPages
public List<long> AllPages(Transaction tx)
{
var results = new List<long>();
var stack = new Stack<Page>();
var root = tx.GetReadOnlyPage(State.RootPageNumber);
stack.Push(root);
while (stack.Count > 0)
{
var p = stack.Pop();
results.Add(p.PageNumber);
for (int i = 0; i < p.NumberOfEntries; i++)
{
var node = p.GetNode(i);
var pageNumber = node->PageNumber;
if (p.IsBranch)
{
stack.Push(tx.GetReadOnlyPage(pageNumber));
}
else if (node->Flags == NodeFlags.PageRef)
{
// This is an overflow page
var overflowPage = tx.GetReadOnlyPage(pageNumber);
var numberOfPages = tx.DataPager.GetNumberOfOverflowPages(overflowPage.OverflowSize);
for (long j = 0; j < numberOfPages; ++j)
results.Add(overflowPage.PageNumber + j);
}
else if (node->Flags == NodeFlags.MultiValuePageRef)
{
var childTreeHeader = (TreeRootHeader*)((byte*)node + node->KeySize + Constants.NodeHeaderSize);
results.Add(childTreeHeader->RootPageNumber);
// this is a multi value
var tree = OpenOrCreateMultiValueTree(tx, new Slice(node), node);
results.AddRange(tree.AllPages(tx));
}
}
}
return results;
}
示例13: DirectRead
internal byte* DirectRead(Transaction tx, Slice key)
{
Lazy<Cursor> lazy;
var p = FindPageFor(tx, key, out lazy);
var node = p.Search(key, _cmp);
if (node == null)
return null;
var item1 = new Slice(node);
if (item1.Compare(key, _cmp) != 0)
return null;
if (node->Flags == (NodeFlags.PageRef))
{
var overFlowPage = tx.GetReadOnlyPage(node->PageNumber);
return overFlowPage.Base + Constants.PageHeaderSize;
}
return (byte*) node + node->KeySize + Constants.NodeHeaderSize;
}
示例14: TryUseRecentTransactionPage
private bool TryUseRecentTransactionPage(Transaction tx, Slice key, out Lazy<Cursor> cursor, out Page page)
{
page = null;
cursor = null;
var recentPages = tx.GetRecentlyFoundPages(this);
if (recentPages == null)
return false;
var foundPage = recentPages.Find(key);
if (foundPage == null)
return false;
var lastFoundPageNumber = foundPage.Number;
page = tx.GetReadOnlyPage(lastFoundPageNumber);
if (page.IsLeaf == false)
throw new DataException("Index points to a non leaf page");
page.NodePositionFor(key, _cmp); // will set the LastSearchPosition
var cursorPath = foundPage.CursorPath;
var pageCopy = page;
cursor = new Lazy<Cursor>(() =>
{
var c = new Cursor();
foreach (var p in cursorPath)
{
if (p == lastFoundPageNumber)
c.Push(pageCopy);
else
{
var cursorPage = tx.GetReadOnlyPage(p);
if (key.Options == SliceOptions.BeforeAllKeys)
{
cursorPage.LastSearchPosition = 0;
}
else if (key.Options == SliceOptions.AfterAllKeys)
{
cursorPage.LastSearchPosition = (ushort)(cursorPage.NumberOfEntries - 1);
}
else if (cursorPage.Search(key, _cmp) != null)
{
if (cursorPage.LastMatch != 0)
{
cursorPage.LastSearchPosition--;
}
}
c.Push(cursorPage);
}
}
return c;
});
return true;
}
示例15: Dump
public static void Dump(Transaction tx, string path, Page start, int showNodesEvery = 25)
{
using (var writer = File.CreateText(path))
{
writer.WriteLine(@"
digraph structs {
node [shape=Mrecord]
rankdir=LR;
bgcolor=transparent;
");
var stack = new Stack<Page>();
stack.Push(start);
var references = new StringBuilder();
while (stack.Count > 0)
{
var p = stack.Pop();
writer.WriteLine(@"
subgraph cluster_p_{0} {{
label=""Page #{0}"";
color={3};
p_{0} [label=""Page: {0}|{1}|Entries: {2:#,#} | {4:p} : {5:p} utilization""];
", p.PageNumber, p.Flags, p.NumberOfEntries, p.IsLeaf ? "black" : "blue",
Math.Round(((AbstractPager.PageSize - p.SizeLeft) / (double)AbstractPager.PageSize), 2),
Math.Round(((AbstractPager.PageSize - p.CalcSizeLeft()) / (double)AbstractPager.PageSize), 2));
MemorySlice key = new Slice(SliceOptions.Key);
if (p.IsLeaf && showNodesEvery > 0)
{
writer.WriteLine(" p_{0}_nodes [label=\" Entries:", p.PageNumber);
for (int i = 0; i < p.NumberOfEntries; i += showNodesEvery)
{
if (i != 0 && showNodesEvery >= 5)
{
writer.WriteLine(" ... {0:#,#} keys redacted ...", showNodesEvery - 1);
}
var node = p.GetNode(i);
key = p.GetNodeKey(node);
writer.WriteLine("{0} - {2} {1:#,#}", MaxString(key.ToString(), 25),
node->DataSize, node->Flags == NodeFlags.Data ? "Size" : "Page");
}
if (p.NumberOfEntries < showNodesEvery)
{
writer.WriteLine(" ... {0:#,#} keys redacted ...", p.NumberOfEntries - 1);
}
writer.WriteLine("\"];");
}
else if (p.IsBranch)
{
writer.Write(" p_{0}_refs [label=\"", p.PageNumber);
for (int i = 0; i < p.NumberOfEntries; i++)
{
var node = p.GetNode(i);
writer.Write("{3}<{2}> {0} / to page {1}", GetBranchNodeString(i, key, p, node), node->PageNumber,
i, i == 0 ? "" : "|");
}
writer.WriteLine("\"];");
var prev = -1L;
for (int i = 0; i < p.NumberOfEntries; i++)
{
var node = p.GetNode(i);
if (node->PageNumber < 0 || node->PageNumber > tx.State.NextPageNumber)
{
writer.Write(" p_{0}_refs [label=\"CORRUPTED\"; Color=RED];", p.PageNumber);
stack.Clear();
break;
}
var child = tx.GetReadOnlyPage(node->PageNumber);
stack.Push(child);
references.AppendFormat(" p_{0}_refs:{3} -> p_{1} [label=\"{2}\"];", p.PageNumber, child.PageNumber, GetBranchNodeString(i, key, p, node), i).AppendLine();
if (prev > -1)
references.AppendFormat(" p_{0} -> p_{1} [style=\"invis\"];", child.PageNumber, prev);
prev = child.PageNumber;
}
}
writer.WriteLine(" }");
}
writer.WriteLine(references.ToString());
writer.WriteLine("}");
}
}