Exemplo n.º 1
0
        /// <summary>
        /// Finish transaction, release lock and call done action
        /// </summary>
        private void Done()
        {
            ENSURE(_disposed == false, "transaction must be active before call Done");

            _disposed = true;

            _locker.ExitTransaction();

            _reader.Dispose();

            // call done callback
            _done(_transactionID);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Dispose
        /// </summary>
        public void Dispose()
        {
            ENSURE(_state != TransactionState.Disposed, "transaction must be active before call Done");

            // clean snapshots if there is no commit/rollback
            if (_state == TransactionState.Active && _snapshots.Count > 0)
            {
                // release writable snapshots
                foreach (var snapshot in _snapshots.Values.Where(x => x.Mode == LockMode.Write))
                {
                    // discard all dirty pages
                    _disk.DiscardDirtyPages(snapshot.GetWritablePages(true, true).Select(x => x.Buffer));

                    // discard all clean pages
                    _disk.DiscardCleanPages(snapshot.GetWritablePages(false, true).Select(x => x.Buffer));
                }

                // release buffers in read-only snaphosts
                foreach (var snapshot in _snapshots.Values.Where(x => x.Mode == LockMode.Read))
                {
                    foreach (var page in snapshot.LocalPages)
                    {
                        page.Buffer.Release();
                    }

                    snapshot.CollectionPage?.Buffer.Release();
                }
            }

            _reader.Dispose();

            _state = TransactionState.Disposed;
        }
        // Protected implementation of Dispose pattern.
        protected virtual void Dispose(bool dispose)
        {
            if (_state == TransactionState.Disposed)
            {
                return;
            }

            ENSURE(_state != TransactionState.Disposed, "transaction must be active before call Done");

            // clean snapshots if there is no commit/rollback
            if (_state == TransactionState.Active && _snapshots.Count > 0)
            {
                // release writable snapshots
                foreach (var snapshot in _snapshots.Values.Where(x => x.Mode == LockMode.Write))
                {
                    // discard all dirty pages
                    _disk.Cache.DiscardDirtyPages(snapshot.GetWritablePages(true, true).Select(x => x.Buffer));

                    // discard all clean pages
                    _disk.Cache.DiscardCleanPages(snapshot.GetWritablePages(false, true).Select(x => x.Buffer));
                }

                // release buffers in read-only snaphosts
                foreach (var snapshot in _snapshots.Values.Where(x => x.Mode == LockMode.Read))
                {
                    foreach (var page in snapshot.LocalPages)
                    {
                        page.Buffer.Release();
                    }

                    snapshot.CollectionPage?.Buffer.Release();
                }
            }

            _reader.Dispose();

            _state = TransactionState.Disposed;

            if (!dispose)
            {
                // Remove transaction monitor's dictionary
                _monitor.ReleaseTransaction(this);
            }
        }