Example #1
0
        public void Delete(Transaction tx, Slice key)
        {
            if (tx.Flags == (TransactionFlags.ReadWrite) == false)
            {
                throw new ArgumentException("Cannot delete a value in a read only transaction");
            }

            var txInfo = tx.GetTreeInformation(this);

            using (var cursor = tx.NewCursor(this))
            {
                var page = FindPageFor(tx, key, cursor);

                page.NodePositionFor(key, _cmp);
                if (page.LastMatch != 0)
                {
                    return; // not an exact match, can't delete
                }
                page = tx.ModifyCursor(this, cursor);

                txInfo.State.EntriesCount--;
                RemoveLeafNode(tx, cursor, page);
                var treeRebalancer = new TreeRebalancer(tx, txInfo, _cmp);
                var changedPage    = page;
                while (changedPage != null)
                {
                    changedPage = treeRebalancer.Execute(cursor, changedPage);
                }

                page.DebugValidate(tx, _cmp, txInfo.RootPageNumber);
            }
        }
Example #2
0
        public void Delete(Slice key, ushort?version = null)
        {
            if (_tx.Flags == (TransactionFlags.ReadWrite) == false)
            {
                throw new ArgumentException("Cannot delete a value in a read only transaction");
            }

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

            if (page.LastMatch != 0)
            {
                return; // not an exact match, can't delete
            }
            page = _tx.ModifyPage(page.PageNumber, this, page);

            State.EntriesCount--;
            ushort nodeVersion;

            RemoveLeafNode(page, out nodeVersion);

            CheckConcurrency(key, version, nodeVersion, TreeActionType.Delete);

            var treeRebalancer = new TreeRebalancer(_tx, this, lazy.Value);
            var changedPage    = page;

            while (changedPage != null)
            {
                changedPage = treeRebalancer.Execute(changedPage);
            }

            page.DebugValidate(_tx, State.RootPageNumber);
        }
Example #3
0
		public void Delete(Transaction tx, Slice key, ushort? version = null)
		{
			if (tx.Flags == (TransactionFlags.ReadWrite) == false)
				throw new ArgumentException("Cannot delete a value in a read only transaction");

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

			page.NodePositionFor(key, _cmp);
			if (page.LastMatch != 0)
				return; // not an exact match, can't delete

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

			State.EntriesCount--;
			ushort nodeVersion;
			RemoveLeafNode(tx, page, out nodeVersion);

			CheckConcurrency(key, version, nodeVersion, TreeActionType.Delete);

			var treeRebalancer = new TreeRebalancer(tx, this);
			var changedPage = page;
			while (changedPage != null)
			{
				changedPage = treeRebalancer.Execute(lazy.Value, changedPage);
			}

			page.DebugValidate(tx, _cmp, State.RootPageNumber);
		}