Пример #1
0
 public PageSplitter(Transaction tx,
     Tree tree,
     SliceComparer cmp,
     Slice newKey,
     int len,
     long pageNumber,
     NodeFlags nodeType,
     ushort nodeVersion,
     Cursor cursor,
     TreeMutableState treeState)
 {
     _tx = tx;
     _tree = tree;
     _cmp = cmp;
     _newKey = newKey;
     _len = len;
     _pageNumber = pageNumber;
     _nodeType = nodeType;
     _nodeVersion = nodeVersion;
     _cursor = cursor;
     _treeState = treeState;
     Page page = _cursor.Pages.First.Value;
     _page = tx.ModifyPage(page.PageNumber, page);
     _cursor.Pop();
 }
Пример #2
0
        private long WriteToOverflowPages(TreeMutableState txInfo, int overflowSize, out byte *dataPos)
        {
            var numberOfPages     = _tx.DataPager.GetNumberOfOverflowPages(overflowSize);
            var overflowPageStart = _tx.AllocatePage(numberOfPages);

            overflowPageStart.Flags        = PageFlags.Overflow;
            overflowPageStart.OverflowSize = overflowSize;
            dataPos = overflowPageStart.Base + Constants.PageHeaderSize;
            txInfo.OverflowPages += numberOfPages;
            txInfo.PageCount     += numberOfPages;
            return(overflowPageStart.PageNumber);
        }
Пример #3
0
        private bool TryOverwriteOverflowPages(TreeMutableState treeState, NodeHeader *updatedNode,
                                               MemorySlice 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);
        }
Пример #4
0
        public PageSplitter(Transaction tx,
                            Tree tree,
                            MemorySlice newKey,
                            int len,
                            long pageNumber,
                            NodeFlags nodeType,
                            ushort nodeVersion,
                            Cursor cursor,
                            TreeMutableState treeState)
        {
            _tx          = tx;
            _tree        = tree;
            _newKey      = newKey;
            _len         = len;
            _pageNumber  = pageNumber;
            _nodeType    = nodeType;
            _nodeVersion = nodeVersion;
            _cursor      = cursor;
            _treeState   = treeState;
            Page page = _cursor.Pages.First.Value;

            _page = tx.ModifyPage(page.PageNumber, _tree, page);
            _cursor.Pop();
        }
Пример #5
0
 private Tree(Transaction tx, TreeMutableState state)
 {
     _tx    = tx;
     _state = state;
 }
Пример #6
0
 internal void SetState(TreeMutableState state)
 {
     _state = state;
 }
Пример #7
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;
		}
Пример #8
0
		internal void SetState(TreeMutableState state)
		{
			_state = state;
		}
Пример #9
0
		private Tree(SliceComparer cmp, TreeMutableState state)
		{
			_cmp = cmp;
			_state = state;
		}
Пример #10
0
		private long WriteToOverflowPages(Transaction tx, TreeMutableState txInfo, int overflowSize, out byte* dataPos)
		{
			var numberOfPages = tx.DataPager.GetNumberOfOverflowPages(overflowSize);
			var overflowPageStart = tx.AllocatePage(numberOfPages);
			overflowPageStart.Flags = PageFlags.Overflow;
			overflowPageStart.OverflowSize = overflowSize;
			dataPos = overflowPageStart.Base + Constants.PageHeaderSize;
			txInfo.OverflowPages += numberOfPages;
			txInfo.PageCount += numberOfPages;
			return overflowPageStart.PageNumber;
		}
Пример #11
0
 private Tree(SliceComparer cmp, TreeMutableState state)
 {
     _cmp   = cmp;
     _state = state;
 }
Пример #12
0
 private Tree(Transaction tx, TreeMutableState state)
 {
     _tx = tx;
     _state = state;
 }
Пример #13
0
		private Tree(Transaction tx, SliceComparer cmp, TreeMutableState state)
		{
			_tx = tx;
			_cmp = cmp;
			_state = state;
		}