コード例 #1
0
        public ScratchBufferPool(StorageEnvironment env)
        {
            _logger = LoggingSource.Instance.GetLogger <ScratchBufferPool>(Path.GetFileName(env.ToString()));

            _disposeOnceRunner = new DisposeOnce <ExceptionRetry>(() =>
            {
                if (_pagerStatesAllScratchesCache != null)
                {
                    foreach (var pagerState in _pagerStatesAllScratchesCache)
                    {
                        pagerState.Value.Release();
                    }
                }

                foreach (var scratch in _scratchBuffers)
                {
                    scratch.Value.File.Dispose();
                    _scratchSpaceMonitor.Decrease(scratch.Value.File.NumberOfAllocatedPages * Constants.Storage.PageSize);
                }

                _scratchBuffers.Clear();

                while (_recycleArea.First != null)
                {
                    var recycledScratch = _recycleArea.First.Value;

                    if (recycledScratch.File.IsDisposed == false)
                    {
                        recycledScratch.File.Dispose();
                        _scratchSpaceMonitor.Decrease(recycledScratch.File.NumberOfAllocatedPages * Constants.Storage.PageSize);
                    }

                    _recycleArea.RemoveFirst();
                }

                _current = null;
            });

            _env                 = env;
            _options             = env.Options;
            _scratchSpaceMonitor = env.Options.ScratchSpaceUsage;
            _current             = NextFile(_options.InitialLogFileSize, null);
            UpdateCacheForPagerStatesOfAllScratches();

            LowMemoryNotification.Instance.RegisterLowMemoryHandler(this);
        }