本文整理汇总了C#中Voron.Impl.Transaction.TryRemoveMultiValueTree方法的典型用法代码示例。如果您正苦于以下问题:C# Transaction.TryRemoveMultiValueTree方法的具体用法?C# Transaction.TryRemoveMultiValueTree怎么用?C# Transaction.TryRemoveMultiValueTree使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Voron.Impl.Transaction
的用法示例。
在下文中一共展示了Transaction.TryRemoveMultiValueTree方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MultiDelete
public void MultiDelete(Transaction tx, Slice key, Slice value, ushort? version = null)
{
State.IsModified = true;
Lazy<Cursor> lazy;
var page = FindPageFor(tx, key, out lazy);
if (page == null || page.LastMatch != 0)
{
return; //nothing to delete - key not found
}
page = tx.ModifyPage(page.PageNumber, page);
var item = page.GetNode(page.LastSearchPosition);
if (item->Flags == NodeFlags.MultiValuePageRef) //multi-value tree exists
{
var tree = OpenOrCreateMultiValueTree(tx, key, item);
tree.Delete(tx, value, version);
// previously, we would convert back to a simple model if we dropped to a single entry
// however, it doesn't really make sense, once you got enough values to go to an actual nested
// tree, you are probably going to remain that way, or be removed completely.
if (tree.State.EntriesCount != 0)
return;
tx.TryRemoveMultiValueTree(this, key);
tx.FreePage(tree.State.RootPageNumber);
Delete(tx, key);
}
else // we use a nested page here
{
var nestedPage = new Page(NodeHeader.DirectAccess(tx, item), "multi tree", (ushort)NodeHeader.GetDataSize(tx, item));
var nestedItem = nestedPage.Search(value, NativeMethods.memcmp);
if (nestedItem == null) // value not found
return;
CheckConcurrency(key, value, version, nestedItem->Version, TreeActionType.Delete);
nestedPage.RemoveNode(nestedPage.LastSearchPosition);
if (nestedPage.NumberOfEntries == 0)
Delete(tx, key);
}
}
示例2: MultiDelete
public void MultiDelete(Transaction tx, Slice key, Slice value, ushort? version = null)
{
State.IsModified = true;
Lazy<Cursor> lazy;
var page = FindPageFor(tx, key, out lazy);
if (page == null || page.LastMatch != 0)
{
return; //nothing to delete - key not found
}
page = tx.ModifyPage(page.PageNumber, page);
var item = page.GetNode(page.LastSearchPosition);
if (item->Flags == NodeFlags.MultiValuePageRef) //multi-value tree exists
{
var tree = OpenOrCreateMultiValueTree(tx, key, item);
tree.Delete(tx, value, version);
if (tree.State.EntriesCount > 1)
return;
// convert back to simple key/val
var iterator = tree.Iterate(tx);
if (!iterator.Seek(Slice.BeforeAllKeys))
throw new InvalidDataException(
"MultiDelete() failed : sub-tree is empty where it should not be, this is probably a Voron bug.");
var dataToSave = iterator.CurrentKey;
var ptr = DirectAdd(tx, key, dataToSave.Size);
dataToSave.CopyTo(ptr);
tx.TryRemoveMultiValueTree(this, key);
tx.FreePage(tree.State.RootPageNumber);
}
else //the regular key->value pattern
{
Delete(tx, key, version);
}
}