private Page GetPageInternal(long pageNumber) { // Check if we can hit the lowest level locality cache. Page p; PageFromScratchBuffer value; if (_scratchPagesTable != null && _scratchPagesTable.TryGetValue(pageNumber, out value)) // Scratch Pages Table will be null in read transactions { Debug.Assert(value != null); PagerState state = null; if (_scratchPagerStates != null) { var lastUsed = _lastScratchFileUsed; if (lastUsed.FileNumber == value.ScratchFileNumber) { state = lastUsed.State; } else { state = _scratchPagerStates[value.ScratchFileNumber]; _lastScratchFileUsed = new PagerStateCacheItem(value.ScratchFileNumber, state); } } p = _env.ScratchBufferPool.ReadPage(this, value.ScratchFileNumber, value.PositionInScratchBuffer, state); Debug.Assert(p.PageNumber == pageNumber, string.Format("Requested ReadOnly page #{0}. Got #{1} from scratch", pageNumber, p.PageNumber)); } else { var pageFromJournal = _journal.ReadPage(this, pageNumber, _scratchPagerStates); if (pageFromJournal != null) { p = pageFromJournal.Value; Debug.Assert(p.PageNumber == pageNumber, string.Format("Requested ReadOnly page #{0}. Got #{1} from journal", pageNumber, p.PageNumber)); } else { p = new Page(DataPager.AcquirePagePointerWithOverflowHandling(this, pageNumber)); Debug.Assert(p.PageNumber == pageNumber, string.Format("Requested ReadOnly page #{0}. Got #{1} from data file", pageNumber, p.PageNumber)); // When encryption is off, we do validation by checksum if (_env.Options.EncryptionEnabled == false) { _env.ValidatePageChecksum(pageNumber, (PageHeader *)p.Pointer); } } } TrackReadOnlyPage(p); _pageLocator.SetReadable(p.PageNumber, p); return(p); }