Exemplo n.º 1
0
        public MutexUI()
        {
            _releaser = new Releaser(_semaphore);
            _releaserTask = Task.FromResult(_releaser);

            Tasks.Enqueue(Task.Factory.StartNew(() => { }));
        }
Exemplo n.º 2
0
        public MetadataManager(IPageManager pageAllocator, HeapWithOffsets <char[]> stringHeap, IBootPageAllocator bootPageAllocator, ILogManager logManager)
        {
            this.pageAllocator = pageAllocator;
            this.stringHeap    = stringHeap;
            this.logManager    = logManager;

            if (!bootPageAllocator.BootPageInitialized())
            {
                using (ITransaction tran = this.logManager.CreateTransaction(this.pageAllocator, false, "GET_BOOT_PAGE"))
                    using (Releaser releaser = tran.AcquireLock(IBootPageAllocator.BootPageId, LockManager.LockTypeEnum.Exclusive).Result)
                    {
                        bootPageAllocator.AllocatePageBootPage(PageType.MixedPage, this.masterPageColumnDefinition, tran);
                        this.masterMetadataCollection = new PageListCollection(this.pageAllocator, this.masterPageColumnDefinition, IBootPageAllocator.BootPageId);
                        tran.Commit();
                    }

                MetadataInitialSetup();
            }
            else
            {
                using (ITransaction tran = this.logManager.CreateTransaction(this.pageAllocator, false, "GET_BOOT_PAGE"))
                {
                    using Releaser releaser       = tran.AcquireLock(IBootPageAllocator.BootPageId, LockManager.LockTypeEnum.Exclusive).Result;
                    this.masterMetadataCollection = new PageListCollection(this.pageAllocator, this.masterPageColumnDefinition, IBootPageAllocator.BootPageId);
                    tran.Commit();
                }
            }
        }
Exemplo n.º 3
0
        // TODO: This should be part of buffer pool class.
        // Ideally page manager shouldn't keep track of in memory-disk mappings.
        private async Task RecordUsageAndEvict(ulong pageId, ITransaction tran)
        {
            ulong[] pageIdsToEvict = this.bufferPool.GetEvictionPolicy().RecordUsageAndEvict(pageId).ToArray();

            foreach (ulong pageIdToEvict in pageIdsToEvict)
            {
                if (tran.AmIHoldingALock(pageIdToEvict, out LockTypeEnum heldLockType))
                {
                    // If this page is needed for myself don't release the lock.
                    // Just ignore for now.
                    continue;
                }

                using (Releaser lckReleaser = await tran.AcquireLockWithCallerOwnership(pageIdToEvict, LockTypeEnum.Exclusive).ConfigureAwait(false))
                {
                    logger.LogDebug($"Evicting page {pageIdToEvict}");
                    IPage pageToEvict = this.bufferPool.GetPage(pageIdToEvict);

                    // Somebody came before us and evicted the page.
                    if (pageToEvict == null)
                    {
                        continue;
                    }

                    await this.FlushPage(pageToEvict).ConfigureAwait(false);

                    bufferPool.EvictPage(pageToEvict.PageId(), pageToEvict.GetBufferPoolToken());

                    logger.LogDebug($"Page {pageIdToEvict} evicted from buffer pool and flushed to the disk.");
                }
            }
        }
Exemplo n.º 4
0
 public AsyncLock()
 {
     _pending       = new LinkedList <CancelableCompletionSource <IDisposable> >();
     _semaphoreSlim = new SemaphoreSlim(1, 1);
     _releaser      = new Releaser(Release);
     _completedTask = Task.FromResult((IDisposable)_releaser);
 }
Exemplo n.º 5
0
        public static IDisposable For <T>(T obj)
        {
            var rel = new Releaser(obj);

            Releasers[obj] = rel;
            return(rel);
        }
Exemplo n.º 6
0
        static async Task <int> Main(string[] args)
        {
            // Setup
            var argumentString = string.Join(" ", args.Skip(1));

            Console.Title = $@"{nameof(GitHubReleaser)} {argumentString}";

            Log.Logger = new LoggerConfiguration()
                         .WriteTo.Console(theme: AnsiConsoleTheme.Code)
                         .CreateLogger();

            // CommandLineParameters
            var commandLine = GetCommandline(args);

            // Execute
            try
            {
                Releaser releaser = new Releaser(commandLine);
                await releaser.ExecuteAsync();

                Log.Information("All looks good, have fun with your release!");
                return(0);
            }
            catch
            {
                return(100);
            }
        }
        public ActionResult DeleteConfirmed(int id)
        {
            Releaser releaser = db.Releaser.Find(id);

            db.Releaser.Remove(releaser);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 8
0
        public async Task <char[]> Fetch(PagePointerOffsetPair loc, ITransaction tran)
        {
            using Releaser lckReleaser = await tran.AcquireLock((ulong) loc.PageId, LockManager.LockTypeEnum.Shared).ConfigureAwait(false);

            StringOnlyPage page = await allocator.GetPageStr((ulong)loc.PageId, tran).ConfigureAwait(false);

            return(page.FetchWithOffset((uint)loc.OffsetInPage, tran));
        }
 public ActionResult Edit([Bind(Include = "Id,Code,Name,Notes,Status")] Releaser releaser)
 {
     if (ModelState.IsValid)
     {
         db.Entry(releaser).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index", "Releasers"));
     }
     return(View(releaser));
 }
Exemplo n.º 10
0
        public ActionResult Create([Bind(Include = "Id,Code,Name,Notes,Status")] Releaser releaser)
        {
            if (ModelState.IsValid)
            {
                db.Releaser.Add(releaser);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(releaser));
        }
Exemplo n.º 11
0
        public async Task <IPage> AllocatePage(PageType pageType, ColumnInfo[] columnTypes, ulong prevPageId, ulong nextPageId, ulong pageId, ITransaction tran)
        {
            logger.LogDebug($"Allocating new page {pageId}");
            IPage page;

            using Releaser releaser = await tran.AcquireLockWithCallerOwnership(pageId, LockTypeEnum.Exclusive).ConfigureAwait(false);

            (Memory <byte> memory, ulong token) = this.bufferPool.GetMemory();

            page = pageType switch
            {
                PageType.StringPage => new StringOnlyPage(pageSize, pageId, prevPageId, nextPageId, tran),
                PageType.MixedPage => new MixedPage(pageSize, pageId, columnTypes, prevPageId, nextPageId, memory, token, tran),
                _ => throw new ArgumentException("Unknown page type")
            };

            Interlocked.Increment(ref this.pageCount);

            if (prevPageId != PageManagerConstants.NullPageId)
            {
                tran.VerifyLock(prevPageId, LockTypeEnum.Exclusive);
                IPage prevPage = await GetPage(prevPageId, tran, pageType, columnTypes).ConfigureAwait(false);

                if (prevPage.NextPageId() != page.NextPageId())
                {
                    throw new ArgumentException("Breaking the link");
                }

                // TODO: Set next page id needs to be logged as well...
                prevPage.SetNextPageId(page.PageId());
            }

            if (nextPageId != PageManagerConstants.NullPageId)
            {
                IPage nextPage = await GetPage(nextPageId, tran, pageType, columnTypes).ConfigureAwait(false);

                if (nextPage.PrevPageId() != page.PrevPageId())
                {
                    throw new ArgumentException("breaking the link");
                }

                nextPage.SetPrevPageId(page.PageId());
            }

            await RecordUsageAndEvict(page.PageId(), tran).ConfigureAwait(false);

            bufferPool.AddPage(page);

            AddToAllocationMap(page);

            return(page);
        }
Exemplo n.º 12
0
        public AsyncLock(int initialCount = 1)
        {
            if (initialCount < 0)
            {
                throw new ArgumentOutOfRangeException("initialCount");
            }

            _maxCount = _currentCount = initialCount;

            _releaser            = new Releaser(this);
            _releaserTask        = Task.FromResult((IDisposable)_releaser);
            _releaseCoreCallback = ReleaseCore;
        }
Exemplo n.º 13
0
        public Releaser ReaderLock(bool isUpgradeable = false)
        {
            if (isUpgradeable)
            {
                this.innerLock.EnterUpgradeableReadLock();
            }
            else
            {
                this.innerLock.EnterReadLock();
            }

            return(Releaser.CreateReadReleaser(this, isUpgradeable));
        }
Exemplo n.º 14
0
        // GET: Releasers/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Releaser releaser = db.Releaser.Find(id);

            if (releaser == null)
            {
                return(HttpNotFound());
            }
            return(View(releaser));
        }
Exemplo n.º 15
0
        public async IAsyncEnumerable <RowHolder> Iterate(ITransaction tran)
        {
            MixedPage currPage;

            for (ulong currPageId = collectionRootPageId; currPageId != PageManagerConstants.NullPageId; currPageId = currPage.NextPageId())
            {
                using Releaser lck = await tran.AcquireLock(currPageId, LockManager.LockTypeEnum.Shared).ConfigureAwait(false);

                currPage = await pageAllocator.GetMixedPage(currPageId, tran, this.columnTypes).ConfigureAwait(false);

                foreach (RowHolder rhf in currPage.Fetch(tran))
                {
                    yield return(rhf);
                }
            }
        }
Exemplo n.º 16
0
        public async Task Add(RowHolder item, ITransaction tran)
        {
            MixedPage currPage = null;

            for (ulong currPageId = this.lastPageId; currPageId != PageManagerConstants.NullPageId; currPageId = currPage.NextPageId())
            {
                using Releaser lck = await tran.AcquireLock(currPageId, LockManager.LockTypeEnum.Shared).ConfigureAwait(false);

                currPage = await pageAllocator.GetMixedPage(currPageId, tran, this.columnTypes).ConfigureAwait(false);

                if (currPage.CanFit(item, tran))
                {
                    lck.Dispose();

                    using Releaser writeLock = await tran.AcquireLock(currPageId, LockManager.LockTypeEnum.Exclusive).ConfigureAwait(false);

                    // Need to check can fit one more time.
                    if (currPage.CanFit(item, tran))
                    {
                        currPage.Insert(item, tran);
                        return;
                    }
                }
            }

            {
                using Releaser prevPageLck = await tran.AcquireLock(currPage.PageId(), LockManager.LockTypeEnum.Exclusive).ConfigureAwait(false);

                if (currPage.NextPageId() != PageManagerConstants.NullPageId)
                {
                    // TODO: it would be good if caller had ability to control this lock.
                    // This dispose doesn't mean anything in current implementation of read committed.
                    prevPageLck.Dispose();
                    await Add(item, tran).ConfigureAwait(false);
                }
                else
                {
                    currPage = await this.pageAllocator.AllocateMixedPage(this.columnTypes, currPage.PageId(), PageManagerConstants.NullPageId, tran).ConfigureAwait(false);

                    using Releaser currPageLck = await tran.AcquireLock(currPage.PageId(), LockManager.LockTypeEnum.Exclusive).ConfigureAwait(false);

                    this.lastPageId = currPage.PageId();
                    currPage.Insert(item, tran);
                }
            }
        }
Exemplo n.º 17
0
        public async Task <ulong> Count(ITransaction tran)
        {
            ulong rowCount = 0;

            IPage currPage;

            for (ulong currPageId = collectionRootPageId; currPageId != PageManagerConstants.NullPageId; currPageId = currPage.NextPageId())
            {
                using Releaser lck = await tran.AcquireLock(currPageId, LockManager.LockTypeEnum.Shared).ConfigureAwait(false);

                currPage = await pageAllocator.GetMixedPage(currPageId, tran, this.columnTypes).ConfigureAwait(false);

                rowCount += currPage.RowCount();
            }

            return(rowCount);
        }
Exemplo n.º 18
0
        public async Task <PagePointerOffsetPair> Add(char[] item, ITransaction tran)
        {
            StringOnlyPage currPage = null;
            int            offset;

            for (ulong currPageId = this.lastPageId; currPageId != PageManagerConstants.NullPageId; currPageId = currPage.NextPageId())
            {
                using Releaser lckReleaser = await tran.AcquireLock(currPageId, LockManager.LockTypeEnum.Shared).ConfigureAwait(false);

                currPage = await allocator.GetPageStr(currPageId, tran).ConfigureAwait(false);

                if (currPage.CanFit(item))
                {
                    lckReleaser.Dispose();

                    using Releaser writeLock = await tran.AcquireLock(currPageId, LockManager.LockTypeEnum.Exclusive).ConfigureAwait(false);

                    // Need to check can fit one more time.
                    if (currPage.CanFit(item))
                    {
                        offset = currPage.Insert(item, tran);
                        return(new PagePointerOffsetPair((long)currPage.PageId(), (int)offset));
                    }
                }
            }

            {
                using Releaser prevPage = await tran.AcquireLock(currPage.PageId(), LockManager.LockTypeEnum.Exclusive).ConfigureAwait(false);

                if (currPage.NextPageId() != PageManagerConstants.NullPageId)
                {
                    prevPage.Dispose();
                    return(await Add(item, tran).ConfigureAwait(false));
                }
                else
                {
                    currPage = await this.allocator.AllocatePageStr(currPage.PageId(), PageManagerConstants.NullPageId, tran).ConfigureAwait(false);

                    using Releaser lckReleaser = await tran.AcquireLock(currPage.PageId(), LockManager.LockTypeEnum.Exclusive).ConfigureAwait(false);

                    offset          = currPage.Insert(item, tran);
                    this.lastPageId = currPage.PageId();
                    return(new PagePointerOffsetPair((long)currPage.PageId(), (int)offset));
                }
            }
        }
Exemplo n.º 19
0
        public async Task <U> Max <U>(Func <RowHolder, U> projector, U startMin, ITransaction tran) where U : IComparable
        {
            MixedPage currPage;
            U         max = startMin;

            for (ulong currPageId = collectionRootPageId; currPageId != PageManagerConstants.NullPageId; currPageId = currPage.NextPageId())
            {
                using Releaser lck = await tran.AcquireLock(currPageId, LockManager.LockTypeEnum.Shared).ConfigureAwait(false);

                currPage = await pageAllocator.GetMixedPage(currPageId, tran, this.columnTypes).ConfigureAwait(false);

                foreach (RowHolder rhf in currPage.Fetch(tran))
                {
                    U curr = projector(rhf);
                    if (curr.CompareTo(max) == 1)
                    {
                        max = curr;
                    }
                }
            }

            return(max);
        }
Exemplo n.º 20
0
 public AsyncLock()
 {
     semaphore = new SemaphoreSlim(1);
     releaser  = new Releaser(this);
 }
Exemplo n.º 21
0
 /// <summary>
 /// Initializes an instance of the <see cref="EntityLoadLock"/> class.
 /// </summary>
 private EntityLoadLock()
 {
     _releaser     = new Releaser(this);
     _releaserTask = Task.FromResult(_releaser);
 }
Exemplo n.º 22
0
 /// <summary>
 ///     This API supports the Entity Framework Core infrastructure and is not intended to be used
 ///     directly from your code. This API may change or be removed in future releases.
 /// </summary>
 public AsyncLock()
 {
     _releaser     = new Releaser(this);
     _releaserTask = Task.FromResult(_releaser);
 }
Exemplo n.º 23
0
 public void Add(PeerMessage message, Releaser releaser)
 {
     Messages.Add(message);
     Releasers.Add(releaser);
 }
Exemplo n.º 24
0
 public AsyncLock(string label)
 {
     this.label    = label;
     this.releaser = null;
     this.locker   = new object();
 }
Exemplo n.º 25
0
 public AsyncLock()
 {
     _mSemaphore = new SemaphoreSlim(1);
     _mReleaser  = new Releaser(this);
 }
 public AsyncReaderWriterLock()
 {
     _writerReleaser     = new Releaser(this, true);
     _readerReleaser     = new Releaser(this, false);
     _readerReleaserTask = Task.FromResult(_readerReleaser);
 }
Exemplo n.º 27
0
        public Releaser WriterLock()
        {
            this.innerLock.EnterWriteLock();

            return(Releaser.CreateWriteReleaser(this));
        }
Exemplo n.º 28
0
 public AsyncLock()
 {
     _mSemaphore = new SemaphoreSlim(1);
     _mReleaser = new Releaser(this);
 }
Exemplo n.º 29
0
 public AsyncLock()
 {
     _releaser      = new Releaser(this);
     _releaserAsync = Task.FromResult((IDisposable)_releaser);
 }