Пример #1
0
        public Transaction(StorageEnvironment env, long id, TransactionFlags flags, IFreeSpaceHandling freeSpaceHandling)
        {
            _dataPager = env.Options.DataPager;
            _env = env;
            _journal = env.Journal;
            _id = id;
            _freeSpaceHandling = freeSpaceHandling;
            Flags = flags;
            var scratchPagerState = env.ScratchBufferPool.PagerState;
            scratchPagerState.AddRef();
            _pagerStates.Add(scratchPagerState);
            if (flags.HasFlag(TransactionFlags.ReadWrite) == false)
            {
                // for read transactions, we need to keep the pager state frozen
                // for write transactions, we can use the current one (which == null)
                _scratchPagerState = scratchPagerState;

                _state = env.State.Clone(this);
                _journal.GetSnapshots().ForEach(AddJournalSnapshot);
                return;
            }

            _state = env.State.Clone(this);

            InitTransactionHeader();

            MarkTreesForWriteTransaction();
        }
Пример #2
0
        public Transaction(StorageEnvironment env, long id, TransactionFlags flags, IFreeSpaceHandling freeSpaceHandling)
        {
            _dataPager         = env.Options.DataPager;
            _env               = env;
            _journal           = env.Journal;
            _id                = id;
            _freeSpaceHandling = freeSpaceHandling;
            Flags              = flags;
            var scratchPagerStates = env.ScratchBufferPool.GetPagerStatesOfAllScratches();

            foreach (var scratchPagerState in scratchPagerStates.Values)
            {
                scratchPagerState.AddRef();
                _pagerStates.Add(scratchPagerState);
            }


            if (flags.HasFlag(TransactionFlags.ReadWrite) == false)
            {
                // for read transactions, we need to keep the pager state frozen
                // for write transactions, we can use the current one (which == null)
                _scratchPagerStates = scratchPagerStates;

                _state = env.State.Clone(this);
                _journal.GetSnapshots().ForEach(AddJournalSnapshot);
                return;
            }

            _state = env.State.Clone(this);

            InitTransactionHeader();

            MarkTreesForWriteTransaction();
        }
Пример #3
0
        public Transaction(StorageEnvironment env, long id, TransactionFlags flags, IFreeSpaceHandling freeSpaceHandling)
        {
            _dataPager         = env.Options.DataPager;
            _env               = env;
            _journal           = env.Journal;
            _id                = id;
            _freeSpaceHandling = freeSpaceHandling;
            Flags              = flags;

            var scratchPagerState = env.ScratchBufferPool.PagerState;

            scratchPagerState.AddRef();
            _pagerStates.Add(scratchPagerState);

            if (flags.HasFlag(TransactionFlags.ReadWrite) == false)
            {
                _state = env.State;
                _journal.GetSnapshots().ForEach(AddJournalSnapshot);
                return;
            }

            _state = env.State.Clone();

            InitTransactionHeader();

            MarkTreesForWriteTransaction();
        }
Пример #4
0
        public LowLevelTransaction(StorageEnvironment env, long id, TransactionPersistentContext transactionPersistentContext, TransactionFlags flags, IFreeSpaceHandling freeSpaceHandling, ByteStringContext context = null)
        {
            env.AssertNoCatastrophicFailure();

            DataPager          = env.Options.DataPager;
            _env               = env;
            _journal           = env.Journal;
            _id                = id;
            _freeSpaceHandling = freeSpaceHandling;
            _allocator         = context ?? new ByteStringContext();
            _disposeAllocator  = context == null;
            _pagerStates       = new HashSet <PagerState>(ReferenceEqualityComparer <PagerState> .Default);

            PersistentContext = transactionPersistentContext;
            Flags             = flags;

            PageSize = DataPager.PageSize;

            var scratchPagerStates = env.ScratchBufferPool.GetPagerStatesOfAllScratches();

            foreach (var scratchPagerState in scratchPagerStates.Values)
            {
                scratchPagerState.AddRef();
                _pagerStates.Add(scratchPagerState);
            }

            if (flags != TransactionFlags.ReadWrite)
            {
                // for read transactions, we need to keep the pager state frozen
                // for write transactions, we can use the current one (which == null)
                _scratchPagerStates = scratchPagerStates;

                _state = env.State.Clone();

                InitializeRoots();

                JournalSnapshots = _journal.GetSnapshots();

                return;
            }

            EnsureNoDuplicateTransactionId(id);

            _env.WriteTransactionPool.Reset();
            _dirtyOverflowPages  = _env.WriteTransactionPool.DirtyOverflowPagesPool;
            _scratchPagesTable   = _env.WriteTransactionPool.ScratchPagesTablePool;
            _dirtyPages          = _env.WriteTransactionPool.DirtyPagesPool;
            _freedPages          = new HashSet <long>(NumericEqualityComparer.Instance);
            _unusedScratchPages  = new List <PageFromScratchBuffer>();
            _transactionPages    = new HashSet <PageFromScratchBuffer>(PageFromScratchBufferEqualityComparer.Instance);
            _pagesToFreeOnCommit = new Stack <long>();

            _state = env.State.Clone();
            InitializeRoots();
            InitTransactionHeader();
        }
Пример #5
0
        public LowLevelTransaction(StorageEnvironment env, long id, TransactionFlags flags, IFreeSpaceHandling freeSpaceHandling, ByteStringContext context = null)
        {
            _dataPager         = env.Options.DataPager;
            _pageSize          = this.DataPager.PageSize;
            _env               = env;
            _journal           = env.Journal;
            _id                = id;
            _freeSpaceHandling = freeSpaceHandling;
            _allocator         = context ?? new ByteStringContext();
            _pageCache         = new PageCache(this, 8);

            Flags    = flags;
            PageSize = _dataPager.PageSize;

            var scratchPagerStates = env.ScratchBufferPool.GetPagerStatesOfAllScratches();

            foreach (var scratchPagerState in scratchPagerStates.Values)
            {
                scratchPagerState.AddRef();
                _pagerStates.Add(scratchPagerState);
            }

            if (flags != TransactionFlags.ReadWrite)
            {
                // for read transactions, we need to keep the pager state frozen
                // for write transactions, we can use the current one (which == null)
                _scratchPagerStates = scratchPagerStates;

                _state = env.State.Clone();

                InitializeRoots();

                foreach (var snapshot in _journal.GetSnapshots())
                {
                    AddJournalSnapshot(snapshot);
                }

                return;
            }

            _state = env.State.Clone();
            InitializeRoots();
            InitTransactionHeader();
        }
Пример #6
0
        public LowLevelTransaction(StorageEnvironment env, long id, TransactionPersistentContext transactionPersistentContext, TransactionFlags flags, IFreeSpaceHandling freeSpaceHandling, ByteStringContext context = null)
        {
            TxStartTime = DateTime.UtcNow;

            if (flags == TransactionFlags.ReadWrite)
            {
                env.Options.AssertNoCatastrophicFailure();
            }

            DataPager          = env.Options.DataPager;
            _env               = env;
            _journal           = env.Journal;
            _id                = id;
            _freeSpaceHandling = freeSpaceHandling;
            _allocator         = context ?? new ByteStringContext(SharedMultipleUseFlag.None);
            _disposeAllocator  = context == null;
            _pagerStates       = new HashSet <PagerState>(ReferenceEqualityComparer <PagerState> .Default);

            PersistentContext = transactionPersistentContext;
            Flags             = flags;

            var scratchPagerStates = env.ScratchBufferPool.GetPagerStatesOfAllScratches();

            foreach (var scratchPagerState in scratchPagerStates.Values)
            {
                scratchPagerState.AddRef();
                _pagerStates.Add(scratchPagerState);
            }

            _pageLocator = transactionPersistentContext.AllocatePageLocator(this);

            if (flags != TransactionFlags.ReadWrite)
            {
                // for read transactions, we need to keep the pager state frozen
                // for write transactions, we can use the current one (which == null)
                _scratchPagerStates = scratchPagerStates;

                _state = env.State.Clone();

                InitializeRoots();

                JournalSnapshots = _journal.GetSnapshots();

                return;
            }

            EnsureNoDuplicateTransactionId(id);
            // we keep this copy to make sure that if we use async commit, we have a stable copy of the jounrals
            // as they were at the time we started the original transaction, this is required because async commit
            // may modify the list of files we have available
            JournalFiles = _journal.Files;
            foreach (var journalFile in JournalFiles)
            {
                journalFile.AddRef();
            }
            _env.WriteTransactionPool.Reset();
            _dirtyOverflowPages  = _env.WriteTransactionPool.DirtyOverflowPagesPool;
            _scratchPagesTable   = _env.WriteTransactionPool.ScratchPagesInUse;
            _dirtyPages          = _env.WriteTransactionPool.DirtyPagesPool;
            _freedPages          = new HashSet <long>(NumericEqualityComparer.BoxedInstanceInt64);
            _unusedScratchPages  = new List <PageFromScratchBuffer>();
            _transactionPages    = new HashSet <PageFromScratchBuffer>(PageFromScratchBufferEqualityComparer.Instance);
            _pagesToFreeOnCommit = new Stack <long>();

            _state = env.State.Clone();
            InitializeRoots();
            InitTransactionHeader();
        }
Пример #7
0
        private LowLevelTransaction(LowLevelTransaction previous, long txId)
        {
            // this is meant to be used with transaction merging only
            // so it makes a lot of assumptions about the usage scenario
            // and what it can do

            Debug.Assert(previous.Flags == TransactionFlags.ReadWrite);

            var env = previous._env;

            env.Options.AssertNoCatastrophicFailure();

            FlushInProgressLockTaken = previous.FlushInProgressLockTaken;
            CurrentTransactionHolder = previous.CurrentTransactionHolder;
            TxStartTime        = DateTime.UtcNow;
            DataPager          = env.Options.DataPager;
            _env               = env;
            _journal           = env.Journal;
            _id                = txId;
            _freeSpaceHandling = previous._freeSpaceHandling;
            _allocator         = previous._allocator;

            _disposeAllocator          = previous._disposeAllocator;
            previous._disposeAllocator = false;

            PersistentContext = previous.PersistentContext;
            Flags             = TransactionFlags.ReadWrite;

            _pagerStates = new HashSet <PagerState>(ReferenceEqualityComparer <PagerState> .Default);

            JournalFiles = previous.JournalFiles;

            foreach (var journalFile in JournalFiles)
            {
                journalFile.AddRef();
            }

            var pagers = new HashSet <AbstractPager>();

            foreach (var scratchAndDataPagerState in previous._pagerStates)
            {
                // in order to avoid "dragging" pager state ref on non active scratch - we will not copy disposed scratches from previous async tx. RavenDB-6766
                if (scratchAndDataPagerState.DiscardOnTxCopy)
                {
                    continue;
                }

                // copy the "current pager" which is the last pager used, and by that do not "drag" old non used pager state refs to the next async commit (i.e. older views of data file). RavenDB-6949
                var currentPager = scratchAndDataPagerState.CurrentPager;
                if (pagers.Add(currentPager) == false)
                {
                    continue;
                }

                var state = currentPager.PagerState;
                state.AddRef();
                _pagerStates.Add(state);
            }


            EnsureNoDuplicateTransactionId(_id);

            // we can reuse those instances, not calling Reset on the pool
            // because we are going to need to scratch buffer pool
            _dirtyOverflowPages = previous._dirtyOverflowPages;
            _dirtyOverflowPages.Clear();

            _scratchPagesTable = _env.WriteTransactionPool.ScratchPagesReadyForNextTx;

            foreach (var kvp in previous._scratchPagesTable)
            {
                if (previous._dirtyPages.Contains(kvp.Key))
                {
                    _scratchPagesTable.Add(kvp.Key, kvp.Value);
                }
            }
            previous._scratchPagesTable.Clear();
            _env.WriteTransactionPool.ScratchPagesInUse          = _scratchPagesTable;
            _env.WriteTransactionPool.ScratchPagesReadyForNextTx = previous._scratchPagesTable;

            _dirtyPages = previous._dirtyPages;
            _dirtyPages.Clear();

            _freedPages          = new HashSet <long>(NumericEqualityComparer.BoxedInstanceInt64);
            _unusedScratchPages  = new List <PageFromScratchBuffer>();
            _transactionPages    = new HashSet <PageFromScratchBuffer>(PageFromScratchBufferEqualityComparer.Instance);
            _pagesToFreeOnCommit = new Stack <long>();

            _state = previous._state.Clone();

            _pageLocator = PersistentContext.AllocatePageLocator(this);
            InitializeRoots();
            InitTransactionHeader();
        }