Exemple #1
0
        public VersionHeadCollection(
            IStartupLog startupLog,
            IErrorLog errorLog,
            IDatabase database)
        {
            _versions   = new Dictionary <ulong, VersionHead>();
            _startupLog = startupLog;
            _errorLog   = errorLog;
            _database   = database;

            _cleanupThread = new Thread(() =>
            {
                _startupLog.WriteLine("Version clean up thread starting");

                while (!_disposing)
                {
                    try
                    {
                        Thread.Sleep(50);

                        List <VersionHead> versions;
                        lock (_versions) versions = _versions.Values.OrderBy(v => v.VersionNumber).ToList();

                        foreach (var version in versions)
                        {
                            if (version.IsReferenced || version.VersionNumber == _database.CurrentVersion)
                            {
                                break;
                            }

                            lock (_versions) _versions.Remove(version.VersionNumber);
                            version.Dispose();
                        }
                    }
                    catch (ThreadAbortException)
                    {
                        return;
                    }
                    catch (Exception ex)
                    {
                        _errorLog.WriteLine("Exception in page collection cleanup thread. " + ex.Message, ex);
                    }
                }

                _startupLog.WriteLine("Version clean up thread exiting");
            })
            {
                IsBackground = true,
                Name         = "Version collection cleanup",
                Priority     = ThreadPriority.AboveNormal
            };

            _cleanupThread.Start();
        }
        public PageHeadCollection(
            IFileSet fileSet,
            IStartupLog startupLog,
            IErrorLog errorLog,
            IPagePool pagePool)
        {
            _pages      = new Dictionary <ulong, PageHead>();
            _fileSet    = fileSet;
            _startupLog = startupLog;
            _errorLog   = errorLog;
            _pagePool   = pagePool;

            _cleanupThread = new Thread(() =>
            {
                _startupLog.WriteLine("Stale page clean up thread starting");

                while (!_disposing)
                {
                    try
                    {
                        Thread.Sleep(50);

                        // TODO: Delete pages that have not been touched for a while and
                        //       have no cached versions
                    }
                    catch (ThreadAbortException)
                    {
                        return;
                    }
                    catch (Exception ex)
                    {
                        _errorLog.WriteLine("Exception in page collection cleanup thread. " + ex.Message, ex);
                    }
                }

                _startupLog.WriteLine("Stale page clean up thread exiting");
            })
            {
                IsBackground = true,
                Name         = "Page collection cleanup",
                Priority     = ThreadPriority.AboveNormal
            };

            _cleanupThread.Start();
        }
        public TransactionHeadCollection(
            IStartupLog startupLog,
            IErrorLog errorLog,
            IPagePool pagePool)
        {
            _transactions = new Dictionary <ulong, TransactionHead>();
            _startupLog   = startupLog;
            _errorLog     = errorLog;
            _pagePool     = pagePool;

            _cleanupThread = new Thread(() =>
            {
                _startupLog.WriteLine("Transaction clean up thread starting");

                while (!_disposing)
                {
                    try
                    {
                        Thread.Sleep(50);

                        // TODO: Kill long running and deadlocked transactions
                    }
                    catch (ThreadAbortException)
                    {
                        return;
                    }
                    catch (Exception ex)
                    {
                        _errorLog.WriteLine("Exception in page cache stale page cleanup thread. " + ex.Message, ex);
                    }
                }

                _startupLog.WriteLine("Transaction clean up thread exiting");
            })
            {
                IsBackground = true,
                Name         = "Transaction collection cleanup",
                Priority     = ThreadPriority.AboveNormal
            };

            _cleanupThread.Start();
        }