Exemple #1
0
        public bool ReadOneTransaction(StorageEnvironmentOptions options, bool checkCrc = true)
        {
            if (_readingPage >= _pager.NumberOfAllocatedPages)
            {
                return(false);
            }

            if (MaxPageToRead != null && _readingPage >= MaxPageToRead.Value)
            {
                return(false);
            }

            TransactionHeader *current;

            if (!TryReadAndValidateHeader(options, out current))
            {
                return(false);
            }

            var transactionSize = GetNumberOfPagesFromSize(current->Compressed ? current->CompressedSize : current->UncompressedSize);

            if (current->TransactionId <= _lastSyncedTransactionId)
            {
                LastTransactionHeader = current;
                _readingPage         += transactionSize;
                return(true);                // skipping
            }

            if (checkCrc && !ValidatePagesCrc(options, transactionSize, current))
            {
                return(false);
            }

            _recoveryPager.EnsureContinuous(null, _recoveryPage, (current->PageCount + current->OverflowPageCount) + 1);
            var dataPage = _recoveryPager.AcquirePagePointer(_recoveryPage);

            UnmanagedMemory.Set(dataPage, 0, (current->PageCount + current->OverflowPageCount) * AbstractPager.PageSize);
            if (current->Compressed)
            {
                if (TryDecompressTransactionPages(options, current, dataPage) == false)
                {
                    return(false);
                }
            }
            else
            {
                Memory.Copy(dataPage, _pager.AcquirePagePointer(_readingPage), (current->PageCount + current->OverflowPageCount) * AbstractPager.PageSize);
            }

            var tempTransactionPageTranslaction = new Dictionary <long, RecoveryPagePosition>();

            for (var i = 0; i < current->PageCount; i++)
            {
                Debug.Assert(_pager.Disposed == false);
                Debug.Assert(_recoveryPager.Disposed == false);

                var page = _recoveryPager.Read(_recoveryPage);

                var pagePosition = new RecoveryPagePosition
                {
                    JournalPos    = _recoveryPage,
                    TransactionId = current->TransactionId
                };

                if (page.IsOverflow)
                {
                    var numOfPages = _recoveryPager.GetNumberOfOverflowPages(page.OverflowSize);

                    pagePosition.IsOverflow            = true;
                    pagePosition.NumberOfOverflowPages = numOfPages;

                    _recoveryPage += numOfPages;
                }
                else
                {
                    _recoveryPage++;
                }

                tempTransactionPageTranslaction[page.PageNumber] = pagePosition;
            }

            _readingPage += transactionSize;

            LastTransactionHeader = current;

            foreach (var pagePosition in tempTransactionPageTranslaction)
            {
                _transactionPageTranslation[pagePosition.Key] = pagePosition.Value;

                if (pagePosition.Value.IsOverflow)
                {
                    Debug.Assert(pagePosition.Value.NumberOfOverflowPages != -1);

                    for (int i = 1; i < pagePosition.Value.NumberOfOverflowPages; i++)
                    {
                        _transactionPageTranslation.Remove(pagePosition.Key + i);
                    }
                }
            }

            return(true);
        }
Exemple #2
0
        public bool ReadOneTransaction(StorageEnvironmentOptions options, bool checkCrc = true)
        {
            if (_readingPage >= _pager.NumberOfAllocatedPages)
            {
                return(false);
            }

            TransactionHeader *current;

            if (!TryReadAndValidateHeader(options, out current))
            {
                return(false);
            }

            var compressedPages = (current->CompressedSize / AbstractPager.PageSize) + (current->CompressedSize % AbstractPager.PageSize == 0 ? 0 : 1);

            if (current->TransactionId <= _lastSyncedTransactionId)
            {
                LastTransactionHeader = current;
                _readingPage         += compressedPages;
                return(true); // skipping
            }

            if (checkCrc && !ValidatePagesCrc(options, compressedPages, current))
            {
                return(false);
            }

            _recoveryPager.EnsureContinuous(null, _recoveryPage, (current->PageCount + current->OverflowPageCount) + 1);
            var dataPage = _recoveryPager.AcquirePagePointer(_recoveryPage);

            StdLib.memset(dataPage, 0, (current->PageCount + current->OverflowPageCount) * AbstractPager.PageSize);
            try
            {
                LZ4.Decode64(_pager.AcquirePagePointer(_readingPage), current->CompressedSize, dataPage, current->UncompressedSize, true);
            }
            catch (Exception e)
            {
                options.InvokeRecoveryError(this, "Could not de-compress, invalid data", e);
                RequireHeaderUpdate = true;

                return(false);
            }

            var tempTransactionPageTranslaction = new Dictionary <long, RecoveryPagePosition>();

            for (var i = 0; i < current->PageCount; i++)
            {
                Debug.Assert(_pager.Disposed == false);
                Debug.Assert(_recoveryPager.Disposed == false);

                var page = _recoveryPager.Read(_recoveryPage);

                var pagePosition = new RecoveryPagePosition
                {
                    JournalPos    = _recoveryPage,
                    TransactionId = current->TransactionId
                };

                if (page.IsOverflow)
                {
                    var numOfPages = _recoveryPager.GetNumberOfOverflowPages(page.OverflowSize);

                    pagePosition.IsOverflow            = true;
                    pagePosition.NumberOfOverflowPages = numOfPages;

                    _recoveryPage += numOfPages;
                }
                else
                {
                    _recoveryPage++;
                }

                tempTransactionPageTranslaction[page.PageNumber] = pagePosition;
            }

            _readingPage += compressedPages;

            LastTransactionHeader = current;

            foreach (var pagePosition in tempTransactionPageTranslaction)
            {
                _transactionPageTranslation[pagePosition.Key] = pagePosition.Value;

                if (pagePosition.Value.IsOverflow)
                {
                    Debug.Assert(pagePosition.Value.NumberOfOverflowPages != -1);

                    for (int i = 1; i < pagePosition.Value.NumberOfOverflowPages; i++)
                    {
                        _transactionPageTranslation.Remove(pagePosition.Key + i);
                    }
                }
            }

            return(true);
        }
Exemple #3
0
		public bool ReadOneTransaction(StorageEnvironmentOptions options, bool checkCrc = true)
		{
			if (_readingPage >= _pager.NumberOfAllocatedPages)
				return false;

			if (MaxPageToRead != null && _readingPage >= MaxPageToRead.Value)
				return false;

			TransactionHeader* current;
			if (!TryReadAndValidateHeader(options, out current))
				return false;

			var transactionSize = GetNumberOfPagesFromSize(current->Compressed ? current->CompressedSize : current->UncompressedSize);

			if (current->TransactionId <= _lastSyncedTransactionId)
			{
				LastTransactionHeader = current;
				_readingPage += transactionSize;
				return true; // skipping
			}

			if (checkCrc && !ValidatePagesCrc(options, transactionSize, current))
				return false;

			_recoveryPager.EnsureContinuous(null, _recoveryPage, (current->PageCount + current->OverflowPageCount) + 1);
			var dataPage = _recoveryPager.AcquirePagePointer(_recoveryPage);

			UnmanagedMemory.Set(dataPage, 0, (current->PageCount + current->OverflowPageCount) * AbstractPager.PageSize);
			if (current->Compressed)
			{
				if (TryDecompressTransactionPages(options, current, dataPage) == false)
					return false;
			}
			else
			{
                Memory.Copy(dataPage, _pager.AcquirePagePointer(_readingPage), (current->PageCount + current->OverflowPageCount) * AbstractPager.PageSize);
			}

			var tempTransactionPageTranslaction = new Dictionary<long, RecoveryPagePosition>();

			for (var i = 0; i < current->PageCount; i++)
			{
				Debug.Assert(_pager.Disposed == false);
				Debug.Assert(_recoveryPager.Disposed == false);

				var page = _recoveryPager.Read(_recoveryPage);

				var pagePosition = new RecoveryPagePosition
				{
					JournalPos = _recoveryPage,
					TransactionId = current->TransactionId
				};

				if (page.IsOverflow)
				{
					var numOfPages = _recoveryPager.GetNumberOfOverflowPages(page.OverflowSize);

					pagePosition.IsOverflow = true;
					pagePosition.NumberOfOverflowPages = numOfPages;

					_recoveryPage += numOfPages;
				}
				else
				{
					_recoveryPage++;
				}

				tempTransactionPageTranslaction[page.PageNumber] = pagePosition;
			}

			_readingPage += transactionSize;

			LastTransactionHeader = current;

			foreach (var pagePosition in tempTransactionPageTranslaction)
			{
				_transactionPageTranslation[pagePosition.Key] = pagePosition.Value;

				if (pagePosition.Value.IsOverflow)
				{
					Debug.Assert(pagePosition.Value.NumberOfOverflowPages != -1);

					for (int i = 1; i < pagePosition.Value.NumberOfOverflowPages; i++)
					{
						_transactionPageTranslation.Remove(pagePosition.Key + i);
					}
				}
			}

			return true;
		}
        public bool ReadOneTransaction(StorageEnvironmentOptions options,bool checkCrc = true)
        {
            if (_readingPage >= _pager.NumberOfAllocatedPages)
                return false;

            TransactionHeader* current;
            if (!TryReadAndValidateHeader(options, out current))
                return false;

            var compressedPages = (current->CompressedSize / AbstractPager.PageSize) + (current->CompressedSize % AbstractPager.PageSize == 0 ? 0 : 1);

            if (current->TransactionId <= _lastSyncedTransactionId)
            {
	            LastTransactionHeader = current;
                _readingPage += compressedPages;
                return true; // skipping
            }

			if (checkCrc && !ValidatePagesCrc(options, compressedPages, current))
				return false;

            _recoveryPager.EnsureContinuous(null, _recoveryPage, (current->PageCount + current->OverflowPageCount) + 1);
            var dataPage = _recoveryPager.AcquirePagePointer(_recoveryPage);

			StdLib.memset(dataPage, 0, (current->PageCount + current->OverflowPageCount) * AbstractPager.PageSize);
            try
            {
                LZ4.Decode64(_pager.AcquirePagePointer(_readingPage), current->CompressedSize, dataPage, current->UncompressedSize, true);
            }
            catch (Exception e)
            {
                options.InvokeRecoveryError(this, "Could not de-compress, invalid data", e);
                RequireHeaderUpdate = true;

                return false;   
            }

			var tempTransactionPageTranslaction = new Dictionary<long, RecoveryPagePosition>();

            for (var i = 0; i < current->PageCount; i++)
            {
                Debug.Assert(_pager.Disposed == false);
                Debug.Assert(_recoveryPager.Disposed == false);

                var page = _recoveryPager.Read(_recoveryPage);

	            var pagePosition = new RecoveryPagePosition
	            {
		            JournalPos = _recoveryPage,
		            TransactionId = current->TransactionId
	            };
	            
                if (page.IsOverflow)
                {
                    var numOfPages = _recoveryPager.GetNumberOfOverflowPages(page.OverflowSize);

	                pagePosition.IsOverflow = true;
	                pagePosition.NumberOfOverflowPages = numOfPages;
					
					_recoveryPage += numOfPages;
                }
                else
                {
                    _recoveryPage++;
                }

				tempTransactionPageTranslaction[page.PageNumber] = pagePosition;
            }

            _readingPage += compressedPages;

            LastTransactionHeader = current;
			
            foreach (var pagePosition in tempTransactionPageTranslaction)
            {
                _transactionPageTranslation[pagePosition.Key] = pagePosition.Value;

	            if (pagePosition.Value.IsOverflow)
	            {
					Debug.Assert(pagePosition.Value.NumberOfOverflowPages != -1);

		            for (int i = 1; i < pagePosition.Value.NumberOfOverflowPages; i++)
		            {
			            _transactionPageTranslation.Remove(pagePosition.Key + i);
		            }
	            }
            }

            return true;
        }