public TransactionHead Lock(ITransaction transaction, PageHead pageHead)
        {
            TransactionHead transactionHead;

            lock (_transactions)
                if (!_transactions.TryGetValue(transaction.TransactionId, out transactionHead))
                {
                    throw new FileLayerException("You must begin the transaction before you can lock pages with it");
                }

            transactionHead.Lock(pageHead);

            return(transactionHead);
        }
        /// <summary>
        /// Returns the page head for a page number. The page head is the had
        /// of a linked list of versions of that page
        /// </summary>
        /// <returns>Null if the page does not exist in storage</returns>
        public PageHead GetPageHead(ulong pageNumber, CacheHints hints)
        {
            PageHead pageHead;

            lock (_pages)
            {
                if (!_pages.TryGetValue(pageNumber, out pageHead))
                {
                    var page = GetFromFileSet(pageNumber);
                    if (page == null)
                    {
                        return(null);
                    }

                    pageHead = new PageHead(pageNumber, page);
                    _pages.Add(pageNumber, pageHead);
                }
            }

            return(pageHead);
        }
Beispiel #3
0
 public void Unlock(PageHead pageHead)
 {
 }
Beispiel #4
0
        public bool Lock(PageHead pageHead)
        {
            if (Parent == null)
            {
                EnsureLockedPages();

                lock (LockedPages)
                {
                    if (LockedPages.Contains(pageHead))
                    {
                        return(false);
                    }

                    LockedPages.Add(pageHead);
                }

                pageHead.Lock(this);

                using (var latestVersion = pageHead.GetVersion(null))
                {
                    using (var newPage = _pagePool.Get(pageHead.PageNumber))
                    {
                        latestVersion.Data.CopyTo(newPage.Data, 0);

                        if (Updates != null)
                        {
                            lock (Updates)
                            {
                                foreach (var update in Updates)
                                {
                                    if (update.PageNumber == pageHead.PageNumber)
                                    {
                                        update.Data.CopyTo(newPage.Data, update.Offset);
                                    }
                                }
                            }
                        }
                        SetModifiedPage(newPage);
                    }
                }

                return(true);
            }

            if (!Parent.Lock(pageHead))
            {
                return(false);
            }

            using (var parentPage = Parent.GetModifiedPage(pageHead.PageNumber))
            {
                using (var newPage = _pagePool.Get(pageHead.PageNumber))
                {
                    parentPage.Data.CopyTo(newPage.Data, 0);

                    if (Updates != null)
                    {
                        lock (Updates)
                        {
                            foreach (var update in Updates)
                            {
                                if (update.PageNumber == pageHead.PageNumber)
                                {
                                    update.Data.CopyTo(newPage.Data, update.Offset);
                                }
                            }
                        }
                    }

                    SetModifiedPage(newPage);
                }
            }

            return(true);
        }
Beispiel #5
0
 /// <summary>
 /// This is split out from the constructor to make thread locking more efficient
 /// </summary>
 public void Added(PageHead pageHead, OwinContainers.LinkedList <PageVersion> .ListElement listElement)
 {
     _pageHead            = pageHead;
     _pageVersionsElement = listElement;
 }