public MutexUI() { _releaser = new Releaser(_semaphore); _releaserTask = Task.FromResult(_releaser); Tasks.Enqueue(Task.Factory.StartNew(() => { })); }
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(); } } }
// 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."); } } }
public AsyncLock() { _pending = new LinkedList <CancelableCompletionSource <IDisposable> >(); _semaphoreSlim = new SemaphoreSlim(1, 1); _releaser = new Releaser(Release); _completedTask = Task.FromResult((IDisposable)_releaser); }
public static IDisposable For <T>(T obj) { var rel = new Releaser(obj); Releasers[obj] = rel; return(rel); }
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")); }
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)); }
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)); }
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); }
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; }
public Releaser ReaderLock(bool isUpgradeable = false) { if (isUpgradeable) { this.innerLock.EnterUpgradeableReadLock(); } else { this.innerLock.EnterReadLock(); } return(Releaser.CreateReadReleaser(this, isUpgradeable)); }
// 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)); }
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); } } }
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); } } }
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); }
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)); } } }
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); }
public AsyncLock() { semaphore = new SemaphoreSlim(1); releaser = new Releaser(this); }
/// <summary> /// Initializes an instance of the <see cref="EntityLoadLock"/> class. /// </summary> private EntityLoadLock() { _releaser = new Releaser(this); _releaserTask = Task.FromResult(_releaser); }
/// <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); }
public void Add(PeerMessage message, Releaser releaser) { Messages.Add(message); Releasers.Add(releaser); }
public AsyncLock(string label) { this.label = label; this.releaser = null; this.locker = new object(); }
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); }
public Releaser WriterLock() { this.innerLock.EnterWriteLock(); return(Releaser.CreateWriteReleaser(this)); }
public AsyncLock() { _releaser = new Releaser(this); _releaserAsync = Task.FromResult((IDisposable)_releaser); }