private ScratchBufferItem NextFile(long minSize, long?requestedSize) { var current = _recycleArea.Last; var oldestTx = _env.PossibleOldestReadTransaction(null); while (current != null) { var recycled = current.Value; if (recycled.File.Size >= Math.Max(minSize, requestedSize ?? 0) && // even though this is in the recyle bin, there might still be some transactions looking at it // so we have to make sure that this is really unused before actually reusing it recycled.File.HasActivelyUsedBytes(oldestTx) == false) { recycled.File.Reset(); recycled.RecycledAt = default(DateTime); _recycleArea.Remove(current); AddScratchBufferFile(recycled); _scratchSpaceMonitor.Increase(recycled.File.NumberOfAllocatedPages * Constants.Storage.PageSize); return(recycled); } current = current.Previous; } _currentScratchNumber++; AbstractPager scratchPager; if (requestedSize != null) { try { scratchPager = _options.CreateScratchPager(StorageEnvironmentOptions.ScratchBufferName(_currentScratchNumber), requestedSize.Value); } catch (Exception) { // this can fail because of disk space issue, let us just ignore it // we'll allocate the minimum amount in a bit anyway return(NextFile(minSize, null)); } } else { scratchPager = _options.CreateScratchPager(StorageEnvironmentOptions.ScratchBufferName(_currentScratchNumber), Math.Max(_options.InitialLogFileSize, minSize)); } var scratchFile = new ScratchBufferFile(scratchPager, _currentScratchNumber); var item = new ScratchBufferItem(scratchFile.Number, scratchFile); AddScratchBufferFile(item); _scratchSpaceMonitor.Increase(item.File.NumberOfAllocatedPages * Constants.Storage.PageSize); return(item); }
private ScratchBufferItem NextFile(long minSize, long?requestedSize, LowLevelTransaction tx) { if (_recycleArea.Count > 0) { var recycled = _recycleArea.Last.Value.Item2; _recycleArea.RemoveLast(); if (recycled.File.Size <= Math.Max(minSize, requestedSize ?? 0)) { recycled.File.Reset(tx); _scratchBuffers.TryAdd(recycled.Number, recycled); return(recycled); } } _currentScratchNumber++; AbstractPager scratchPager; if (requestedSize != null) { try { scratchPager = _options.CreateScratchPager(StorageEnvironmentOptions.ScratchBufferName(_currentScratchNumber), requestedSize.Value); } catch (Exception) { // this can fail because of disk space issue, let us just ignore it // we'll allocate the minimum amount in a bit anway return(NextFile(minSize, null, tx)); } } else { scratchPager = _options.CreateScratchPager(StorageEnvironmentOptions.ScratchBufferName(_currentScratchNumber), Math.Max(_options.InitialLogFileSize, minSize)); } var scratchFile = new ScratchBufferFile(scratchPager, _currentScratchNumber); var item = new ScratchBufferItem(scratchFile.Number, scratchFile); _scratchBuffers.TryAdd(item.Number, item); return(item); }
private ScratchBufferItem NextFile() { _currentScratchNumber++; var scratchPager = _options.CreateScratchPager(StorageEnvironmentOptions.ScratchBufferName(_currentScratchNumber)); scratchPager.EnsureContinuous(0, (int)(Math.Max(_options.InitialFileSize ?? 0, _options.InitialLogFileSize) / _options.PageSize)); var scratchFile = new ScratchBufferFile(scratchPager, _currentScratchNumber); var item = new ScratchBufferItem(scratchFile.Number, scratchFile); _scratchBuffers.TryAdd(item.Number, item); return(item); }
private ScratchBufferFile NextFile() { _currentScratchNumber++; var scratchPager = _options.CreateScratchPager(StorageEnvironmentOptions.ScratchBufferName(_currentScratchNumber)); scratchPager.AllocateMorePages(null, Math.Max(_options.InitialFileSize ?? 0, _options.InitialLogFileSize)); var scratchFile = new ScratchBufferFile(scratchPager, _currentScratchNumber); _scratchBuffers.Add(_currentScratchNumber, scratchFile); _oldestTransactionWhenFlushWasForced = -1; return(scratchFile); }
private ScratchBufferItem NextFile() { _currentScratchNumber++; var scratchPager = _options.CreateScratchPager(StorageEnvironmentOptions.ScratchBufferName(_currentScratchNumber)); scratchPager.AllocateMorePages(null, Math.Max(_options.InitialFileSize ?? 0, _options.InitialLogFileSize)); var scratchFile = new ScratchBufferFile(scratchPager, _currentScratchNumber); var item = new ScratchBufferItem(scratchFile.Number, scratchFile); _scratchBuffers.TryAdd(item.Number, item); return(item); }
public LazyTransactionBuffer(StorageEnvironmentOptions options) { _options = options; _lazyTransactionPager = _options.CreateScratchPager("lazy-transactions.buffer"); }
public LazyTransactionBuffer(StorageEnvironmentOptions options) { _lazyTransactionPager = options.CreateScratchPager("lazy-transactions.buffer", options.InitialFileSize ?? options.InitialLogFileSize); _transactionPersistentContext = new TransactionPersistentContext(true); }