当前位置: 首页>>代码示例>>C#>>正文


C# Transaction.AddMultiValueTree方法代码示例

本文整理汇总了C#中Voron.Impl.Transaction.AddMultiValueTree方法的典型用法代码示例。如果您正苦于以下问题:C# Transaction.AddMultiValueTree方法的具体用法?C# Transaction.AddMultiValueTree怎么用?C# Transaction.AddMultiValueTree使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Voron.Impl.Transaction的用法示例。


在下文中一共展示了Transaction.AddMultiValueTree方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OpenOrCreateMultiValueTree

		private Tree OpenOrCreateMultiValueTree(Transaction tx, Slice key, NodeHeader* item)
		{
			Tree tree;
			if (tx.TryGetMultiValueTree(this, key, out tree))
				return tree;

			var childTreeHeader =
				(TreeRootHeader*)((byte*)item + item->KeySize + Constants.NodeHeaderSize);
			Debug.Assert(childTreeHeader->RootPageNumber < tx.State.NextPageNumber);
			tree = childTreeHeader != null ?
				Open(tx, childTreeHeader) :
				Create(tx);

			tx.AddMultiValueTree(this, key, tree);
			return tree;
		}
开发者ID:ReginaBricker,项目名称:ravendb,代码行数:16,代码来源:Tree.MultiTree.cs

示例2: MultiAdd

		public void MultiAdd(Transaction tx, Slice key, Slice value, ushort? version = null)
		{
			if (value == null) throw new ArgumentNullException("value");
			int maxNodeSize = tx.DataPager.MaxNodeSize;
			if (value.Size > maxNodeSize)
				throw new ArgumentException(
					"Cannot add a value to child tree that is over " + maxNodeSize + " bytes in size", "value");
			if (value.Size == 0)
				throw new ArgumentException("Cannot add empty value to child tree");

			State.IsModified = true;

			Lazy<Cursor> lazy;
			var page = FindPageFor(tx, key, out lazy);
			if ((page == null || page.LastMatch != 0))
			{
				MultiAddOnNewValue(tx, key, value, version, maxNodeSize);
				return;
			}

			page = tx.ModifyPage(page.PageNumber, page);

			var item = page.GetNode(page.LastSearchPosition);

			// already was turned into a multi tree, not much to do here
			if (item->Flags == NodeFlags.MultiValuePageRef)
			{
				var existingTree = OpenOrCreateMultiValueTree(tx, key, item);
				existingTree.DirectAdd(tx, value, 0, version: version);
				return;
			}

			var nestedPagePtr = NodeHeader.DirectAccess(tx, item);
			var nestedPage = new Page(nestedPagePtr, "multi tree", (ushort) NodeHeader.GetDataSize(tx, item));

			var existingItem = nestedPage.Search(value, NativeMethods.memcmp);
			if (nestedPage.LastMatch != 0)
				existingItem = null;// not an actual match, just greater than

			ushort previousNodeRevision = existingItem != null ?  existingItem->Version : (ushort)0;
			CheckConcurrency(key, value, version, previousNodeRevision, TreeActionType.Add);
			
			if (existingItem != null)
			{
				// maybe same value added twice?
				var tmpKey = new Slice(item);
				if (tmpKey.Compare(value, _cmp) == 0)
					return; // already there, turning into a no-op
				nestedPage.RemoveNode(nestedPage.LastSearchPosition);
			}

			if (nestedPage.HasSpaceFor(tx, value, 0))
			{
				// we are now working on top of the modified root page, we can just modify the memory directly
				nestedPage.AddDataNode(nestedPage.LastSearchPosition, value, 0, previousNodeRevision);
				return;
			}

			int pageSize = nestedPage.CalcSizeUsed() + Constants.PageHeaderSize;
			var newRequiredSize = pageSize + nestedPage.GetRequiredSpace(value, 0);
			if (newRequiredSize <= maxNodeSize)
			{
				// we can just expand the current value... no need to create a nested tree yet
				var actualPageSize = (ushort)Math.Min(Utils.NearestPowerOfTwo(newRequiredSize), maxNodeSize);
				ExpandMultiTreeNestedPageSize(tx, key, value, nestedPagePtr, actualPageSize, item->DataSize);

				return;
			}
			// we now have to convert this into a tree instance, instead of just a nested page
			var tree = Create(tx, _cmp, TreeFlags.MultiValue);
			for (int i = 0; i < nestedPage.NumberOfEntries; i++)
			{
				var existingValue = nestedPage.GetNodeKey(i);
				tree.DirectAdd(tx, existingValue, 0);
			}
			tree.DirectAdd(tx, value, 0, version: version);
			tx.AddMultiValueTree(this, key, tree);
			// we need to record that we switched to tree mode here, so the next call wouldn't also try to create the tree again
			DirectAdd(tx, key, sizeof (TreeRootHeader), NodeFlags.MultiValuePageRef);
		}
开发者ID:paulcbetts,项目名称:ravendb,代码行数:80,代码来源:Tree.MultiTree.cs

示例3: MultiAddOnNewValue

		private void MultiAddOnNewValue(Transaction tx, Slice key, Slice value, ushort? version, int maxNodeSize)
		{
			var requiredPageSize = Constants.PageHeaderSize + SizeOf.LeafEntry(-1, value, 0) + Constants.NodeOffsetSize;
			if (requiredPageSize > maxNodeSize)
			{
				// no choice, very big value, we might as well just put it in its own tree from the get go...
				// otherwise, we would have to put this in overflow page, and that won't save us any space anyway

				var tree = Create(tx, TreeFlags.MultiValue);
				tree.DirectAdd(value, 0);
				tx.AddMultiValueTree(this, key, tree);

				DirectAdd(key, sizeof (TreeRootHeader), NodeFlags.MultiValuePageRef);
				return;
			}

			var actualPageSize = (ushort) Math.Min(Utils.NearestPowerOfTwo(requiredPageSize), maxNodeSize);

			var ptr = DirectAdd(key, actualPageSize);

			var nestedPage = new Page(ptr, "multi tree", actualPageSize)
			{
				PageNumber = -1L,// hint that this is an inner page
				Lower = (ushort) Constants.PageHeaderSize,
				Upper = actualPageSize,
				Flags = PageFlags.Leaf,
			};

			CheckConcurrency(key, value, version, 0, TreeActionType.Add);

			nestedPage.AddDataNode(0, value, 0, 0);
		}
开发者ID:ReginaBricker,项目名称:ravendb,代码行数:32,代码来源:Tree.MultiTree.cs

示例4: MultiAdd

		public void MultiAdd(Transaction tx, Slice key, Slice value, ushort? version = null)
		{
			if (value == null) throw new ArgumentNullException("value");
			if (value.Size > tx.DataPager.MaxNodeSize)
				throw new ArgumentException(
					"Cannot add a value to child tree that is over " + tx.DataPager.MaxNodeSize + " bytes in size", "value");
			if (value.Size == 0)
				throw new ArgumentException("Cannot add empty value to child tree");

			State.IsModified = true;
			Lazy<Cursor> lazy;
			var page = FindPageFor(tx, key, out lazy);

			if (page == null || page.LastMatch != 0)
			{
				var ptr = DirectAdd(tx, key, value.Size, version: version);
				value.CopyTo(ptr);
				return;
			}

			page = tx.ModifyPage(page.PageNumber, page);

			var item = page.GetNode(page.LastSearchPosition);

			CheckConcurrency(key, version, item->Version, TreeActionType.Add);
			var existingValue = new Slice(DirectRead(tx, key), (ushort) item->DataSize);
			if (existingValue.Compare(value, _cmp) == 0)
				return; //nothing to do, the exact value is already there				

			if (item->Flags == NodeFlags.MultiValuePageRef)
			{
				var tree = OpenOrCreateMultiValueTree(tx, key, item);
				tree.DirectAdd(tx, value, 0);
			}
			else // need to turn to tree
			{
				var tree = Create(tx, _cmp, TreeFlags.MultiValue);
				var current = NodeHeader.GetData(tx, item);
				tree.DirectAdd(tx, current, 0);
				tree.DirectAdd(tx, value, 0);
				tx.AddMultiValueTree(this, key, tree);

				// we need to record that we switched to tree mode here, so the next call wouldn't also try to create the tree again
				DirectAdd(tx, key, sizeof (TreeRootHeader), NodeFlags.MultiValuePageRef);
			}
		}
开发者ID:randacc,项目名称:ravendb,代码行数:46,代码来源:Tree.cs


注:本文中的Voron.Impl.Transaction.AddMultiValueTree方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。