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


C# Transaction.AddPagerState方法代码示例

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


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

示例1: AllocateMorePages

        public override void AllocateMorePages(Transaction tx, long newLength)
        {
            if (newLength < _length)
                throw new ArgumentException("Cannot set the legnth to less than the current length");

            if (newLength == _length)
                return;

            // need to allocate memory again
            NativeFileMethods.SetFileLength(_handle, newLength);

            Debug.Assert(_fileStream.Length == newLength);

            _length = 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 = newLength/PageSize;
        }
开发者ID:WimVergouwe,项目名称:ravendb,代码行数:26,代码来源:MemoryMappedPager.cs

示例2: Allocate

		public PageFromScratchBuffer Allocate(Transaction tx, int numberOfPages)
		{
			if (tx == null)
				throw new ArgumentNullException("tx");
			var size = Utils.NearestPowerOfTwo(numberOfPages);

			PageFromScratchBuffer result;
			if (_current.TryGettingFromAllocatedBuffer(tx, numberOfPages, size, out result))
				return result;

			long sizeAfterAllocation = _current.SizeAfterAllocation(size);
			long oldestActiveTransaction = tx.Environment.OldestTransaction;

			if (_scratchBuffers.Count > 1)
			{
				var scratchesToDelete = new List<int>();

				// determine how many bytes of older scratches are still in use
				foreach (var olderScratch in _scratchBuffers.Values.Except(new []{_current}))
				{
					var bytesInUse = olderScratch.ActivelyUsedBytes(oldestActiveTransaction);

					if (bytesInUse > 0)
						sizeAfterAllocation += bytesInUse;
					else
						scratchesToDelete.Add(olderScratch.Number);
				}

				// delete inactive scratches
				foreach (var scratchNumber in scratchesToDelete)
				{
					var scratchBufferFile = _scratchBuffers[scratchNumber];
					_scratchBuffers.Remove(scratchNumber);
					scratchBufferFile.Dispose();
				}
			}

			if (sizeAfterAllocation > 0.8 * _sizeLimit && oldestActiveTransaction > _oldestTransactionWhenFlushWasForced)
			{
				_oldestTransactionWhenFlushWasForced = oldestActiveTransaction;

				// We are starting to force a flush to free scratch pages. We are doing it at this point (80% of the max scratch size)
				// to make sure that next transactions will be able to allocate pages that we are going to free in the current transaction.
				// Important notice: all pages freed by this run will get ValidAfterTransactionId == tx.Id (so only next ones can use it)

				tx.Environment.ForceLogFlushToDataFile(tx, allowToFlushOverwrittenPages: true);
			}

			if (sizeAfterAllocation > _sizeLimit)
			{
				var sp = Stopwatch.StartNew();

				// Our problem is that we don't have any available free pages, probably because
				// there are read transactions that are holding things open. We are going to see if
				// there are any free pages that _might_ be freed for us if we wait for a bit. The idea
				// is that we let the read transactions time to complete and do their work, at which point
				// we can continue running. It is possible that a long running read transaction
				// would in fact generate enough work for us to timeout, but hopefully we can avoid that.

				while (sp.ElapsedMilliseconds < tx.Environment.Options.ScratchBufferOverflowTimeout)
				{
					if (_current.TryGettingFromAllocatedBuffer(tx, numberOfPages, size, out result))
						return result;
					Thread.Sleep(32);
				}

				sp.Stop();

				if (_current.HasDiscontinuousSpaceFor(tx, size))
				{
					// there is enough space for the requested allocation but the problem is its fragmentation
					// so we will create a new scratch file and will allow to allocate new continuous range from there

					_current = NextFile();

					_current.PagerState.AddRef();
					tx.AddPagerState(_current.PagerState);

					return _current.Allocate(tx, numberOfPages, size);
				}

				var debugInfoBuilder = new StringBuilder();

				debugInfoBuilder.AppendFormat("Requested number of pages: {0} (NearestPowerOfTwo: {1})\r\n", numberOfPages, size);
				debugInfoBuilder.AppendFormat("Oldest active transaction: {0} (snapshot: {1})\r\n", tx.Environment.OldestTransaction, oldestActiveTransaction);
				debugInfoBuilder.AppendFormat("Oldest active transaction when flush was forced: {0}\r\n", _oldestTransactionWhenFlushWasForced);
				debugInfoBuilder.AppendFormat("Next write transaction id: {0}\r\n", tx.Environment.NextWriteTransactionId);

				debugInfoBuilder.AppendLine("Active transactions:");
				foreach (var activeTransaction in tx.Environment.ActiveTransactions)
				{
					debugInfoBuilder.AppendFormat("\tId: {0} - {1}\r\n", activeTransaction.Id, activeTransaction.Flags);
				}

				debugInfoBuilder.AppendLine("Scratch files usage:");
				foreach (var scratchBufferFile in _scratchBuffers)
				{
					debugInfoBuilder.AppendFormat("\t{0} - size: {1:#,#;;0} KB, in active use: {2:#,#;;0} KB\r\n", StorageEnvironmentOptions.ScratchBufferName(scratchBufferFile.Value.Number), scratchBufferFile.Value.Size / 1024, scratchBufferFile.Value.ActivelyUsedBytes(oldestActiveTransaction) / 1024);
				}

//.........这里部分代码省略.........
开发者ID:kijanawoodard,项目名称:ravendb,代码行数:101,代码来源:ScratchBufferPool.cs

示例3: AllocateMorePages

		public override void AllocateMorePages(Transaction tx, long newLength)
		{
			ThrowObjectDisposedIfNeeded();
			var newLengthAfterAdjustment = NearestSizeToAllocationGranularity(newLength);

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

			if (newLengthAfterAdjustment == _totalAllocationSize)
				return;

			var allocationSize = newLengthAfterAdjustment - _totalAllocationSize;

			if (_totalAllocationSize + allocationSize >= long.MaxValue) //probably would never be true, but just in case
				throw new OutOfMemoryException("failed to allocated more pages - reached maximum allowed space usage");

		    if (TryAllocateMoreContinuousPages(allocationSize) == false)
		    {
		        var newPagerState = AllocateMorePagesAndRemapContinuously(allocationSize);
		        if (newPagerState == null)
		        {
		            var errorMessage = string.Format(
		                "Unable to allocate more pages - unsucsessfully 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 assoicated 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;
		}
开发者ID:ReginaBricker,项目名称:ravendb,代码行数:46,代码来源:Win32PageFileBackedMemoryMappedPager.cs

示例4: AllocateMorePages

		public override void AllocateMorePages(Transaction tx, long newLength)
		{
			var oldSize = NumberOfAllocatedPages * PageSize;
			if (newLength < oldSize)
				throw new ArgumentException("Cannot set the legnth to less than the current length");
			if (newLength == oldSize)
		        return; // nothing to do

			var increaseSize = (newLength - oldSize);
			NumberOfAllocatedPages += increaseSize / PageSize;
			var newPtr = Marshal.AllocHGlobal(new IntPtr(increaseSize));

			var buffer = new Buffer
			{
				Handle = newPtr,
				Base = (byte*) newPtr.ToPointer(),
				Size = increaseSize
			};

			_buffers = _buffers.Append(buffer);

		    var newPager = new PagerState(this);
			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(newPager);
			}
			PagerState.Release();
			PagerState = newPager;
		}
开发者ID:WimVergouwe,项目名称:ravendb,代码行数:32,代码来源:PureMemoryPager.cs


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