Ejemplo n.º 1
0
        public MapReduceResultsStore(ulong reduceKeyHash, MapResultsStorageType type, TransactionOperationContext indexContext, MapReduceIndexingContext mapReduceContext, bool create, PageLocator pageLocator = null)
        {
            _reduceKeyHash    = reduceKeyHash;
            Type              = type;
            _indexContext     = indexContext;
            _mapReduceContext = mapReduceContext;
            _tx          = indexContext.Transaction.InnerTransaction;
            _pageLocator = pageLocator;

            switch (Type)
            {
            case MapResultsStorageType.Tree:
                InitializeTree(create);
                break;

            case MapResultsStorageType.Nested:
                _nestedValueKeyScope = Slice.From(indexContext.Allocator, NestedValuesPrefix + reduceKeyHash, ByteStringType.Immutable, out _nestedValueKey);
                break;

            default:
                throw new ArgumentOutOfRangeException(Type.ToString());
            }
        }
Ejemplo n.º 2
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;
            PersistentContext  = previous.PersistentContext;

            _allocator        = new ByteStringContext(SharedMultipleUseFlag.None);
            _disposeAllocator = true;

            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();
        }
Ejemplo n.º 3
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();
        }
Ejemplo n.º 4
0
        public Page ResolvePageFor <T>(object args = null) where T : IViewModel
        {
            var page = PageLocator.ResolvePageAndViewModel(typeof(T), args);

            return(page);
        }
Ejemplo n.º 5
0
        public Page ResolvePageFor(Type pageType, object args = null)
        {
            var page = PageLocator.ResolvePageAndViewModel(pageType, args);

            return(page);
        }
Ejemplo n.º 6
0
 /* 构造函数 */
 public Contents(List <Module> modList, PageLocator locator, int masterType) : base(modList, locator, masterType)
 {
 }
Ejemplo n.º 7
0
 /* 构造函数 */
 public StyleExtractor(string templatePath, string paperPath, List <Module> modList, int masterType, bool usePageLocator) : base(templatePath, paperPath, modList)
 {
     locator         = new PageLocator(paperPath, usePageLocator);
     this.masterType = masterType;
 }
Ejemplo n.º 8
0
        public static Tree Create(LowLevelTransaction llt, Transaction tx, TreeFlags flags = TreeFlags.None, RootObjectType type = RootObjectType.VariableSizeTree, PageLocator pageLocator = null)
        {
            if (type != RootObjectType.VariableSizeTree && type != RootObjectType.Table)
            {
                throw new ArgumentException($"Only valid types are {nameof(RootObjectType.VariableSizeTree)} or {nameof(RootObjectType.Table)}.", nameof(type));
            }

            var newRootPage = AllocateNewPage(llt, TreePageFlags.Leaf, 1);
            var tree        = new Tree(llt, tx, newRootPage.PageNumber, pageLocator)
            {
                _state =
                {
                    RootObjectType = type,
                    Depth          =     1,
                    Flags          = flags,
                }
            };

            if ((flags & TreeFlags.LeafsCompressed) == TreeFlags.LeafsCompressed)
            {
                tree.InitializeCompression();
            }

            tree.State.RecordNewPage(newRootPage, 1);
            return(tree);
        }
Ejemplo n.º 9
0
 //构造函数
 public FigureStyle(List <Module> modList, PageLocator locator, int masterType) : base(modList, locator, masterType)
 {
 }
Ejemplo n.º 10
0
 public Formula(List <Module> modList, PageLocator locator, int masterType)
     : base(modList, locator, masterType)
 {
 }
Ejemplo n.º 11
0
 public static Tree Open(LowLevelTransaction llt, Transaction tx, TreeRootHeader *header, RootObjectType type = RootObjectType.VariableSizeTree, PageLocator pageLocator = null)
 {
     return(new Tree(llt, tx, header->RootPageNumber, pageLocator)
     {
         _state =
         {
             RootObjectType  = type,
             PageCount       = header->PageCount,
             BranchPages     = header->BranchPages,
             Depth           = header->Depth,
             OverflowPages   = header->OverflowPages,
             LeafPages       = header->LeafPages,
             NumberOfEntries = header->NumberOfEntries,
             Flags           = header->Flags
         }
     });
 }
Ejemplo n.º 12
0
        public Tree ReadTree(Slice treeName, RootObjectType type = RootObjectType.VariableSizeTree, PageLocator pageLocator = null)
        {
            EnsureTrees();

            Tree tree;

            if (_trees.TryGetValue(treeName, out tree))
            {
                return(tree);
            }

            TreeRootHeader *header = (TreeRootHeader *)_lowLevelTransaction.RootObjects.DirectRead(treeName);

            if (header != null)
            {
                if (header->RootObjectType != type)
                {
                    throw new InvalidOperationException($"Tried to open {treeName} as a {type}, but it is actually a " + header->RootObjectType);
                }

                tree      = Tree.Open(_lowLevelTransaction, this, header, type, pageLocator);
                tree.Name = treeName;

                if ((tree.State.Flags & TreeFlags.LeafsCompressed) == TreeFlags.LeafsCompressed)
                {
                    tree.InitializeCompression();
                }

                _trees.Add(treeName, tree);

                return(tree);
            }

            _trees.Add(treeName, null);
            return(null);
        }
Ejemplo n.º 13
0
        public Tree ReadTree(string treeName, RootObjectType type = RootObjectType.VariableSizeTree, PageLocator pageLocator = null)
        {
            Slice treeNameSlice;

            Slice.From(Allocator, treeName, ByteStringType.Immutable, out treeNameSlice);
            return(ReadTree(treeNameSlice, type, pageLocator));
        }
Ejemplo n.º 14
0
        public Tree CreateTree(Slice name, RootObjectType type = RootObjectType.VariableSizeTree, TreeFlags flags = TreeFlags.None, PageLocator pageLocator = null)
        {
            Tree tree = ReadTree(name, type, pageLocator);

            if (tree != null)
            {
                return(tree);
            }

            if (_lowLevelTransaction.Flags == TransactionFlags.ReadWrite == false)
            {
                throw new InvalidOperationException("No such tree: '" + name +
                                                    "' and cannot create trees in read transactions");
            }

            tree      = Tree.Create(_lowLevelTransaction, this, flags, pageLocator: pageLocator);
            tree.Name = name;
            tree.State.RootObjectType = type;

            var space = (TreeRootHeader *)_lowLevelTransaction.RootObjects.DirectAdd(name, sizeof(TreeRootHeader));

            tree.State.CopyTo(space);

            tree.State.IsModified = true;
            AddTree(name, tree);

            return(tree);
        }
Ejemplo n.º 15
0
        public Tree CreateTree(string name, RootObjectType type = RootObjectType.VariableSizeTree, TreeFlags flags = TreeFlags.None, PageLocator pageLocator = null)
        {
            Slice treeNameSlice;

            Slice.From(Allocator, name, ByteStringType.Immutable, out treeNameSlice);
            return(CreateTree(treeNameSlice, type, flags, pageLocator));
        }
Ejemplo n.º 16
0
 //构造函数
 public HeaderFooter(List <Module> modList, PageLocator locator, int masterType)
     : base(modList, locator, masterType)
 {
 }