private void UpdatePageTranslationTable(LowLevelTransaction tx, HashSet <PagePosition> unused, Dictionary <long, PagePosition> ptt)
        {
            foreach (var freedPageNumber in tx.GetFreedPagesNumbers())
            {
                // set freed page marker - note it can be overwritten below by later allocation

                ptt[freedPageNumber] = new PagePosition
                {
                    ScratchPos        = -1,
                    ScratchNumber     = -1,
                    TransactionId     = tx.Id,
                    JournalNumber     = Number,
                    IsFreedPageMarker = true
                };
            }

            var txPages = tx.GetTransactionPages();

            foreach (var txPage in txPages)
            {
                var scratchPage = tx.Environment.ScratchBufferPool.ReadPage(tx, txPage.ScratchFileNumber, txPage.PositionInScratchBuffer);
                var pageNumber  = scratchPage.PageNumber;

                PagePosition value;
                if (_pageTranslationTable.TryGetValue(tx, pageNumber, out value))
                {
                    value.UnusedInPTT = true;
                    unused.Add(value);
                }

                PagePosition pagePosition;
                if (ptt.TryGetValue(pageNumber, out pagePosition) && pagePosition.IsFreedPageMarker == false)
                {
                    unused.Add(pagePosition);
                }

                ptt[pageNumber] = new PagePosition
                {
                    ScratchPos    = txPage.PositionInScratchBuffer,
                    ScratchNumber = txPage.ScratchFileNumber,
                    TransactionId = tx.Id,
                    JournalNumber = Number
                };
            }

            foreach (var freedPage in tx.GetUnusedScratchPages())
            {
                unused.Add(new PagePosition
                {
                    ScratchPos    = freedPage.PositionInScratchBuffer,
                    ScratchNumber = freedPage.ScratchFileNumber,
                    TransactionId = tx.Id,
                    JournalNumber = Number
                });
            }
        }
Exemple #2
0
        private void UpdatePageTranslationTable(LowLevelTransaction tx, HashSet <PagePosition> unused, Dictionary <long, PagePosition> ptt)
        {
            // REVIEW: This number do not grow easily. There is no way we can go higher than int.MaxValue
            //         Make sure that we upgrade later upwards so journal numbers are always ints.
            long journalNumber = Number;

            foreach (var freedPageNumber in tx.GetFreedPagesNumbers())
            {
                // set freed page marker - note it can be overwritten below by later allocation

                ptt[freedPageNumber] = new PagePosition(-1, tx.Id, journalNumber, -1, true);
            }

            var scratchBufferPool = tx.Environment.ScratchBufferPool;
            var txPages           = tx.GetTransactionPages();

            foreach (var txPage in txPages)
            {
                long pageNumber = txPage.ScratchPageNumber;
                if (pageNumber == -1) // if we don't already have it from TX preparing then ReadPage
                {
                    var scratchPage = scratchBufferPool.ReadPage(tx, txPage.ScratchFileNumber, txPage.PositionInScratchBuffer);
                    pageNumber = scratchPage.PageNumber;
                }

                Debug.Assert(pageNumber >= 0);
                PagePosition value;
                if (_pageTranslationTable.TryGetValue(tx, pageNumber, out value))
                {
                    value.UnusedInPTT = true;
                    unused.Add(value);
                }

                PagePosition pagePosition;
                if (ptt.TryGetValue(pageNumber, out pagePosition) && pagePosition.IsFreedPageMarker == false)
                {
                    unused.Add(pagePosition);
                }

                ptt[pageNumber] = new PagePosition(txPage.PositionInScratchBuffer, tx.Id, journalNumber, txPage.ScratchFileNumber);
            }

            foreach (var freedPage in tx.GetUnusedScratchPages())
            {
                unused.Add(new PagePosition(freedPage.PositionInScratchBuffer, tx.Id, journalNumber, freedPage.ScratchFileNumber));
            }
        }