FreePage() private method

private FreePage ( long pageNumber ) : void
pageNumber long
return void
Example #1
0
	    public void DeleteTree(Transaction tx, string name)
        {
            if (tx.Flags == (TransactionFlags.ReadWrite) == false)
                throw new ArgumentException("Cannot create a new newRootTree with a read only transaction");

	        Tree tree = tx.ReadTree(name);
	        if (tree == null)
	            return;

            foreach (var page in tree.AllPages())
            {
                tx.FreePage(page);
            }

            tx.State.Root.Delete((Slice) name);

            tx.RemoveTree(name);
        }
Example #2
0
		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;
		}
Example #3
0
		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);
			}
		}
Example #4
0
		private void RemoveLeafNode(Transaction tx, Page page, out ushort nodeVersion)
		{
			var node = page.GetNode(page.LastSearchPosition);
			nodeVersion = node->Version;
			if (node->Flags == (NodeFlags.PageRef)) // this is an overflow pointer
			{
				var overflowPage = tx.GetReadOnlyPage(node->PageNumber);
				var numberOfPages = tx.DataPager.GetNumberOfOverflowPages(overflowPage.OverflowSize);
				for (int i = 0; i < numberOfPages; i++)
				{
					tx.FreePage(overflowPage.PageNumber + i);
				}

				State.OverflowPages -= numberOfPages;
				State.PageCount -= numberOfPages;
			}
			page.RemoveNode(page.LastSearchPosition);
		}
Example #5
0
	    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);
		    }
	    }