AddPagerState() private method

private AddPagerState ( Voron.Impl.PagerState state ) : void
state Voron.Impl.PagerState
return void
Esempio n. 1
0
        public override void AllocateMorePages(Transaction tx, long newLength)
        {
            if (newLength < _fileStream.Length)
            {
                throw new ArgumentException("Cannot set the legnth to less than the current length");
            }

            if (newLength == _fileStream.Length)
            {
                return;
            }

            // need to allocate memory again
            _fileStream.SetLength(newLength);
            PagerState.Release();             // when the last transaction using this is over, will dispose it
            PagerState newPager = CreateNewPagerState();

            if (tx != null)             // we only pass null during startup, and we don't need it there
            {
                newPager.AddRef();      // one for the current transaction
                tx.AddPagerState(newPager);
            }

            PagerState             = newPager;
            NumberOfAllocatedPages = newPager.Accessor.Capacity / PageSize;
        }
Esempio n. 2
0
        public override void AllocateMorePages(Transaction tx, long newLength)
        {
            if (newLength <= _allocatedSize)
            {
                throw new ArgumentException("Cannot set the legnth to less than the current length");
            }

            var oldSize = _allocatedSize;

            _allocatedSize         = newLength;
            NumberOfAllocatedPages = _allocatedSize / PageSize;
            var newPtr  = Marshal.AllocHGlobal(new IntPtr(_allocatedSize));
            var newBase = (byte *)newPtr.ToPointer();

            NativeMethods.memcpy(newBase, _base, new IntPtr(oldSize));
            _base = newBase;
            _ptr  = newPtr;

            var oldPager = PagerState;

            var newPager = new PagerState {
                Ptr = newPtr
            };

            newPager.AddRef();          // one for the pager

            if (tx != null)             // we only pass null during startup, and we don't need it there
            {
                newPager.AddRef();      // one for the current transaction
                tx.AddPagerState(PagerState);
            }

            PagerState = newPager;
            oldPager.Release();
        }
Esempio n. 3
0
		public override void AllocateMorePages(Transaction tx, long newLength)
		{
			if (newLength < _fileStream.Length)
				throw new ArgumentException("Cannot set the legnth to less than the current length");

			if (newLength == _fileStream.Length)
				return;

			// need to allocate memory again
			_fileStream.SetLength(newLength);
			PagerState.Release(); // when the last transaction using this is over, will dispose it
			PagerState newPager = CreateNewPagerState();

			if (tx != null) // we only pass null during startup, and we don't need it there
			{
				newPager.AddRef(); // one for the current transaction
				tx.AddPagerState(newPager);
			}

			PagerState = newPager;
			NumberOfAllocatedPages = newPager.Accessor.Capacity / PageSize;
		}
		public override void AllocateMorePages(Transaction tx, long newLength)
		{
			ThrowObjectDisposedIfNeeded();

			var newLengthAfterAdjustment = NearestSizeToAllocationGranularity(newLength);

			if (newLengthAfterAdjustment < _totalAllocationSize)
				throw new ArgumentException("Cannot set the length to less than the current length");

			if (newLengthAfterAdjustment == _totalAllocationSize)
				return;

			var allocationSize = newLengthAfterAdjustment - _totalAllocationSize;

			Win32NativeFileMethods.SetFileLength(_handle, _totalAllocationSize + allocationSize);
			if (TryAllocateMoreContinuousPages(allocationSize) == false)
			{
				PagerState newPagerState = CreatePagerState();
				if (newPagerState == null)
				{
					var errorMessage = string.Format(
						"Unable to allocate more pages - unsuccessfully tried to allocate continuous block of virtual memory with size = {0:##,###;;0} bytes",
						(_totalAllocationSize + allocationSize));

					throw new OutOfMemoryException(errorMessage);
				}

				newPagerState.DebugVerify(newLengthAfterAdjustment);

				if (tx != null)
				{
					newPagerState.AddRef();
					tx.AddPagerState(newPagerState);
				}

				var tmp = PagerState;
				PagerState = newPagerState;
				tmp.Release(); //replacing the pager state --> so one less reference for it
			}

			_totalAllocationSize += allocationSize;
			NumberOfAllocatedPages = _totalAllocationSize / PageSize;
		}
        public override void AllocateMorePages(Transaction tx, long newLength)
        {
            ThrowObjectDisposedIfNeeded();

            var newLengthAfterAdjustment = NearestSizeToPageSize(newLength);

            if (newLengthAfterAdjustment <= _totalAllocationSize) //nothing to do
                return;

            var allocationSize = newLengthAfterAdjustment - _totalAllocationSize;

            PosixHelper.AllocateFileSpace(_fd, (ulong)(_totalAllocationSize + allocationSize));
            _totalAllocationSize += allocationSize;

            PagerState newPagerState = CreatePagerState();
            if (newPagerState == null)
            {
                var errorMessage = string.Format(
                    "Unable to allocate more pages - unsuccessfully tried to allocate continuous block of virtual memory with size = {0:##,###;;0} bytes",
                    (_totalAllocationSize + allocationSize));

                throw new OutOfMemoryException(errorMessage);
            }

            newPagerState.DebugVerify(newLengthAfterAdjustment);

            if (tx != null)
            {
                newPagerState.AddRef();
                tx.AddPagerState(newPagerState);
            }

            var tmp = PagerState;
            PagerState = newPagerState;
            tmp.Release(); //replacing the pager state --> so one less reference for it

            NumberOfAllocatedPages = _totalAllocationSize / PageSize;
        }
Esempio n. 6
0
        public Transaction NewTransaction(TransactionFlags flags, TimeSpan? timeout = null)
        {
            bool txLockTaken = false;
	        try
	        {
		        if (flags == (TransactionFlags.ReadWrite))
		        {
			        var wait = timeout ?? (Debugger.IsAttached ? TimeSpan.FromMinutes(30) : TimeSpan.FromSeconds(30));
					Monitor.TryEnter(_txWriter, wait, ref txLockTaken);
					if (txLockTaken == false)
					{
						throw new TimeoutException("Waited for " + wait +
													" for transaction write lock, but could not get it");
					}
					
			        if (_endOfDiskSpace != null)
			        {
				        if (_endOfDiskSpace.CanContinueWriting)
				        {
					        var flushingTask = _flushingTask;
					        Debug.Assert(flushingTask != null && (flushingTask.Status == TaskStatus.Canceled || flushingTask.Status == TaskStatus.RanToCompletion));
					        _cancellationTokenSource = new CancellationTokenSource();
					        _flushingTask = FlushWritesToDataFileAsync();
					        _endOfDiskSpace = null;
				        }
			        }
		        }

		        Transaction tx;

		        _txCommit.EnterReadLock();
		        try
		        {
			        long txId = flags == TransactionFlags.ReadWrite ? _transactionsCounter + 1 : _transactionsCounter;
			        tx = new Transaction(this, txId, flags, _freeSpaceHandling);

			        if (IsDebugRecording)
			        {
				        RecordTransactionState(tx, DebugActionType.TransactionStart);
				        tx.RecordTransactionState = RecordTransactionState;
			        }
		        }
		        finally
		        {
			        _txCommit.ExitReadLock();
		        }

		        _activeTransactions.Add(tx);
		        var state = _dataPager.TransactionBegan();
		        tx.AddPagerState(state);

		        if (flags == TransactionFlags.ReadWrite)
		        {
			        tx.AfterCommit = TransactionAfterCommit;
		        }

		        return tx;
	        }
            catch (Exception)
            {
                if (txLockTaken)
					Monitor.Exit(_txWriter);
                throw;
            }
        }
		public override void AllocateMorePages(Transaction tx, long newLength)
		{
			ThrowObjectDisposedIfNeeded();
			var newLengthAfterAdjustment = NearestSizeToAllocationGranularity(newLength);

			if (newLengthAfterAdjustment < _totalAllocationSize)
				throw new ArgumentException("Cannot set the length to less than the current length");

			if (newLengthAfterAdjustment == _totalAllocationSize)
				return;

			var allocationSize = newLengthAfterAdjustment - _totalAllocationSize;

		    if (TryAllocateMoreContinuousPages(allocationSize) == false)
		    {
		        var newPagerState = AllocateMorePagesAndRemapContinuously(allocationSize);
		        if (newPagerState == null)
		        {
		            var errorMessage = string.Format(
		                "Unable to allocate more pages - unsuccessfully tried to allocate continuous block of virtual memory with size = {0:##,###;;0} bytes",
		                (_totalAllocationSize + allocationSize));

		            throw new OutOfMemoryException(errorMessage);
		        }
                newPagerState.DebugVerify(newLengthAfterAdjustment);

		        newPagerState.AddRef();
		        if (tx != null)
		        {
		            newPagerState.AddRef();
		            tx.AddPagerState(newPagerState);
		        }
                // we always share the same memory mapped files references between all pages, since to close them 
                // would be to lose all the memory associated with them
		        PagerState.DisposeFilesOnDispose = false;
		        var tmp = PagerState;
                PagerState = newPagerState;
                tmp.Release(); //replacing the pager state --> so one less reference for it
		    }

		    _totalAllocationSize += allocationSize;
            NumberOfAllocatedPages = _totalAllocationSize / PageSize;
		}
Esempio n. 8
0
        public void RefreshMappedView(Transaction tx)
        {
            PagerState newPagerState = CreatePagerState();

            if (tx != null)
            {
                newPagerState.AddRef();
                tx.AddPagerState(newPagerState);
            }

            var tmp = PagerState;
            PagerState = newPagerState;
            tmp.Release(); //replacing the pager state --> so one less reference for it
        }